# HG changeset patch # User Markus Bröker # Date 1491098546 -7200 # Node ID 499c41b85afd6e3eb3be2ffa38c8d2957d0a3f89 # Parent 523bf90e16b7698527ae729e810e919679f0cbf3 Öffnen von PDF-Dokumenten optimiert * Öffnen per Drag-And-Drop * Öffnen per Rechts-Klick diff --git a/PDFViewer/Base.lproj/Main.storyboard b/PDFViewer/Base.lproj/Main.storyboard --- a/PDFViewer/Base.lproj/Main.storyboard +++ b/PDFViewer/Base.lproj/Main.storyboard @@ -603,7 +603,7 @@ - + @@ -622,7 +622,7 @@ - + @@ -649,7 +649,7 @@ - + diff --git a/PDFViewer/Info.plist b/PDFViewer/Info.plist --- a/PDFViewer/Info.plist +++ b/PDFViewer/Info.plist @@ -4,6 +4,23 @@ CFBundleDevelopmentRegion de_DE + CFBundleDocumentTypes + + + CFBundleTypeName + PDF + CFBundleTypeRole + Viewer + LSHandlerRank + Alternate + LSItemContentTypes + + com.adobe.pdf + + LSTypeIsPackage + 0 + + CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIconFile @@ -17,13 +34,13 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + 0.1 CFBundleSignature ???? CFBundleVersion - 1 + 2 LSApplicationCategoryType - public.app-category.education + public.app-category.utilities LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright diff --git a/PDFViewer/appdelegate/AppDelegate.h b/PDFViewer/appdelegate/AppDelegate.h --- a/PDFViewer/appdelegate/AppDelegate.h +++ b/PDFViewer/appdelegate/AppDelegate.h @@ -7,7 +7,11 @@ // #import +#import "ViewController.h" -@interface AppDelegate : NSObject +@interface AppDelegate : NSObject { + NSWindow *window; + ViewController *controller; +} @end diff --git a/PDFViewer/appdelegate/AppDelegate.m b/PDFViewer/appdelegate/AppDelegate.m --- 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 *)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 diff --git a/PDFViewer/pdfviewer/PDFViewer.h b/PDFViewer/pdfviewer/PDFViewer.h --- 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 diff --git a/PDFViewer/pdfviewer/PDFViewer.m b/PDFViewer/pdfviewer/PDFViewer.m --- 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 *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 diff --git a/PDFViewer/viewcontroller/ViewController.m b/PDFViewer/viewcontroller/ViewController.m --- 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 {