Öffnen von PDF-Dokumenten optimiert
* Öffnen per Drag-And-Drop
* Öffnen per Rechts-Klick
--- a/PDFViewer/Base.lproj/Main.storyboard
+++ b/PDFViewer/Base.lproj/Main.storyboard
@@ -603,7 +603,7 @@
<customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
- <point key="canvasLocation" x="75" y="0.0"/>
+ <point key="canvasLocation" x="-171" y="-267"/>
</scene>
<!--Window Controller-->
<scene sceneID="R2V-B0-nI4">
@@ -622,7 +622,7 @@
</windowController>
<customObject id="Oky-zY-oP4" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
- <point key="canvasLocation" x="-87" y="59"/>
+ <point key="canvasLocation" x="-103" y="107"/>
</scene>
<!--View Controller-->
<scene sceneID="hIz-AP-VOD">
@@ -649,7 +649,7 @@
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
- <point key="canvasLocation" x="-87" y="906"/>
+ <point key="canvasLocation" x="-103" y="912"/>
</scene>
</scenes>
</document>
--- a/PDFViewer/Info.plist
+++ b/PDFViewer/Info.plist
@@ -4,6 +4,23 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>de_DE</string>
+ <key>CFBundleDocumentTypes</key>
+ <array>
+ <dict>
+ <key>CFBundleTypeName</key>
+ <string>PDF</string>
+ <key>CFBundleTypeRole</key>
+ <string>Viewer</string>
+ <key>LSHandlerRank</key>
+ <string>Alternate</string>
+ <key>LSItemContentTypes</key>
+ <array>
+ <string>com.adobe.pdf</string>
+ </array>
+ <key>LSTypeIsPackage</key>
+ <integer>0</integer>
+ </dict>
+ </array>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
@@ -17,13 +34,13 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
- <string>1.0</string>
+ <string>0.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1</string>
+ <string>2</string>
<key>LSApplicationCategoryType</key>
- <string>public.app-category.education</string>
+ <string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
--- a/PDFViewer/appdelegate/AppDelegate.h
+++ b/PDFViewer/appdelegate/AppDelegate.h
@@ -7,7 +7,11 @@
//
#import <Cocoa/Cocoa.h>
+#import "ViewController.h"
-@interface AppDelegate : NSObject <NSApplicationDelegate>
+@interface AppDelegate : NSObject <NSApplicationDelegate> {
+ NSWindow *window;
+ ViewController *controller;
+}
@end
--- a/PDFViewer/appdelegate/AppDelegate.m
+++ b/PDFViewer/appdelegate/AppDelegate.m
@@ -8,14 +8,9 @@
#import "AppDelegate.h"
-@interface AppDelegate ()
-
-@end
-
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
- // Insert code here to initialize your application
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
@@ -26,4 +21,35 @@
return TRUE;
}
+- (BOOL) application:(NSApplication *)sender openFile:(NSString *)filename {
+ window = [[[NSApplication sharedApplication] windows] objectAtIndex:0];
+ controller = (ViewController*) [window contentViewController];
+
+ NSURL *url = [[NSURL alloc] initFileURLWithPath:filename];
+ BOOL status = [[controller pdfViewer] loadUrl: url];
+
+ if (!status) {
+ [[controller pdfViewer] speak:(NSMutableString*)@"Das Dokument konnte nicht geladen werden"];
+ } else {
+ [[controller pdfViewer] startSpeaking:nil];
+ }
+
+ return status;
+}
+
+- (void) application:(NSApplication *)sender openFiles:(NSArray<NSString *> *)filenames {
+ window = [[[NSApplication sharedApplication] windows] objectAtIndex:0];
+ controller = (ViewController*) [window contentViewController];
+
+ NSString *filename = [filenames objectAtIndex:0];
+ NSURL *url = [[NSURL alloc] initFileURLWithPath:filename];
+ BOOL status = [[controller pdfViewer] loadUrl: url];
+
+ if (!status) {
+ [[controller pdfViewer] speak:(NSMutableString*)@"Das Dokument konnte nicht geladen werden"];
+ } else {
+ [[controller pdfViewer] startSpeaking:nil];
+ }
+}
+
@end
--- a/PDFViewer/pdfviewer/PDFViewer.h
+++ b/PDFViewer/pdfviewer/PDFViewer.h
@@ -24,4 +24,10 @@
- (void)speak:(NSMutableString *)texts;
- (void)silence;
+- (NSString*) getSalutation;
+- (BOOL) loadUrl: (NSURL*) url;
+
+- (void) showErrorMessage: (NSString*) message;
+- (void) showDebugMessage: (NSString*) message;
+
@end
--- a/PDFViewer/pdfviewer/PDFViewer.m
+++ b/PDFViewer/pdfviewer/PDFViewer.m
@@ -20,7 +20,13 @@
NSMutableString *strings = [[NSMutableString alloc] init];
NSUInteger nOps = [[self document] pageCount];
- [strings appendString:[NSString stringWithFormat:@"Genosse Parteisekretär, das Dokument hat %lu Seiten", nOps]];
+ NSString *salutation = [self getSalutation];
+
+ if (nOps > 0) {
+ [strings appendString:[NSString stringWithFormat:@"%@, das Dokument hat %lu Seiten", salutation, nOps]];
+ } else {
+ [strings appendString:[NSString stringWithFormat:@"%@, laden Sie ein Dokument mit MAC-O", salutation]];
+ }
for (int pages = 0; pages < nOps; pages++) {
PDFPage *page = [[self document] pageAtIndex:pages];
@@ -45,9 +51,8 @@
// neues PDF laden
NSURL* url = [[panel URLs] objectAtIndex:0];
- PDFDocument *doc = [[PDFDocument alloc] initWithURL:url];
+ [self loadUrl:url];
- [self setDocument:doc];
[self startSpeaking:nil];
}
}];
@@ -104,4 +109,44 @@
return inputStr;
}
+- (NSString*) getSalutation {
+ NSString *fullName = NSFullUserName();
+ NSArray<NSString*> *array = [fullName componentsSeparatedByString:@" "];
+
+ NSString *name = @"Parteisekretär";
+
+ if (array != NULL) {
+ if ([array count] >= 1) {
+ name = [array objectAtIndex:1];
+ }
+ }
+
+ NSString *salutation = [NSString stringWithFormat:@"Genosse %@", name];
+
+ return salutation;
+}
+
+- (BOOL) loadUrl: (NSURL*) url {
+ PDFDocument *doc = [[PDFDocument alloc] initWithURL:url];
+
+ [self silence];
+ [self setDocument:doc];
+
+ return (doc != NULL);
+}
+
+- (void) showErrorMessage: (NSString*) message {
+ NSAlert *alert = [[NSAlert alloc] init];
+ [alert setMessageText:message];
+ [alert setInformativeText:@"Fehler"];
+ [alert runModal];
+}
+
+- (void) showDebugMessage: (NSString*) message {
+ NSAlert *alert = [[NSAlert alloc] init];
+ [alert setMessageText:message];
+ [alert setInformativeText:@"Debug"];
+ [alert runModal];
+}
+
@end
--- a/PDFViewer/viewcontroller/ViewController.m
+++ b/PDFViewer/viewcontroller/ViewController.m
@@ -14,13 +14,6 @@
- (void)viewDidLoad {
[super viewDidLoad];
-
- NSString *str = @"https://derinistihbarat.files.wordpress.com/2012/08/die-doktorarbeit-von-stasi-koko-chef-alexander-schalck-golodtkowski.pdf";
-
- NSURL *url = [NSURL URLWithString:str];
-
- PDFDocument *doc = [[PDFDocument alloc] initWithURL:url];
- [_pdfViewer setDocument:doc];
}
- (void)viewDidAppear {