# HG changeset patch # User Markus Bröker # Date 1490741915 -7200 # Node ID 523bf90e16b7698527ae729e810e919679f0cbf3 # Parent fd23014eaa851498e4c945c7b5bcf3f26f94e365 Weitere Menüpunkte aktiviert 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 @@ -59,52 +59,18 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/PDFViewer/appdelegate/AppDelegate.m b/PDFViewer/appdelegate/AppDelegate.m --- a/PDFViewer/appdelegate/AppDelegate.m +++ b/PDFViewer/appdelegate/AppDelegate.m @@ -15,16 +15,15 @@ @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - // Insert code here to initialize your application + // Insert code here to initialize your application } - (void)applicationWillTerminate:(NSNotification *)aNotification { - // Insert code here to tear down your application + // Insert code here to tear down your application } -- (BOOL)applicationShouldTerminateAfterLastWindowClosed: - (NSApplication *)sender { - return TRUE; +- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { + return TRUE; } @end diff --git a/PDFViewer/pdfviewer/PDFViewer.h b/PDFViewer/pdfviewer/PDFViewer.h --- a/PDFViewer/pdfviewer/PDFViewer.h +++ b/PDFViewer/pdfviewer/PDFViewer.h @@ -8,9 +8,13 @@ #import @interface PDFViewer : PDFView { - NSSpeechSynthesizer *synthesizer; + NSSpeechSynthesizer *synthesizer; } +/* Datei-Aktionen für First-Respnder */ +- (IBAction)openDocument:(id)sender; +- (IBAction)performClose: (id)sender; + /* Action-Override für First-Responder */ - (IBAction)startSpeaking:(id)sender; - (IBAction)stopSpeaking:(id)sender; diff --git a/PDFViewer/pdfviewer/PDFViewer.m b/PDFViewer/pdfviewer/PDFViewer.m --- a/PDFViewer/pdfviewer/PDFViewer.m +++ b/PDFViewer/pdfviewer/PDFViewer.m @@ -10,23 +10,53 @@ @implementation PDFViewer +/* Eintrittspunkt eines (N)ext (I)nterface! */ - (void)awakeFromNib { - synthesizer = [[NSSpeechSynthesizer alloc] - initWithVoice:[NSSpeechSynthesizer defaultVoice]]; + synthesizer = [[NSSpeechSynthesizer alloc] initWithVoice:[NSSpeechSynthesizer defaultVoice]]; +} + +/* Lese den Text aus dem aktuell geöffneten Dokument aus */ +- (NSMutableString *)getTexts { + NSMutableString *strings = [[NSMutableString alloc] init]; + NSUInteger nOps = [[self document] pageCount]; + + [strings appendString:[NSString stringWithFormat:@"Genosse Parteisekretär, das Dokument hat %lu Seiten", nOps]]; + + for (int pages = 0; pages < nOps; pages++) { + PDFPage *page = [[self document] pageAtIndex:pages]; + [strings appendString:[self replaceString:[page string]]]; + } + + return strings; } -- (NSMutableString *)getTexts { - NSMutableString *strings = [[NSMutableString alloc] init]; - NSUInteger nOps = [[self document] pageCount]; - - [strings appendString:[NSString stringWithFormat:@"Genosse Parteisekretär, das Dokument hat %lu Seiten", nOps]]; +/* Datei-Menü: Öffnen-Dialog */ +- (IBAction)openDocument:(id)sender { + NSArray *fileTypes = [NSPDFImageRep imageTypes]; + + NSOpenPanel* panel =[NSOpenPanel openPanel]; + [panel setAllowedFileTypes:fileTypes]; + + [panel beginWithCompletionHandler:^(NSInteger result){ + if (result == NSFileHandlingPanelOKButton) { + + // Audioausgabe beenden + [self silence]; + + // neues PDF laden + NSURL* url = [[panel URLs] objectAtIndex:0]; + PDFDocument *doc = [[PDFDocument alloc] initWithURL:url]; + + [self setDocument:doc]; + [self startSpeaking:nil]; + } + }]; +} - for (int pages = 0; pages < nOps; pages++) { - PDFPage *page = [[self document] pageAtIndex:pages]; - [strings appendString:[self replaceString:[page string]]]; - } - - return strings; +/* Datei-Menü: Schließen-Dialog */ +- (IBAction)performClose: (id)sender { + [self silence]; + [self setDocument:nil]; } /* Button Action startSpeaking */ @@ -46,31 +76,32 @@ /* Sprachausgabe an */ - (void)speak:(NSMutableString *)texts { - // Die Audioausgabe muss immer gestoppt werden, bevor Sie erneut gestartet werden darf! - [self stopSpeaking:self]; - - [synthesizer startSpeakingString:texts]; + // Die Audioausgabe muss immer gestoppt werden, bevor Sie erneut gestartet werden darf! + [self silence]; + + [synthesizer startSpeakingString:texts]; } /* Sprachausgabe aus */ - (void)silence { - if ([synthesizer isSpeaking]) { - [synthesizer stopSpeaking]; - } + if ([synthesizer isSpeaking]) { + [synthesizer stopSpeaking]; + } } +/* Standard-Ersetzungen für die Sprachausgabe */ - (NSString *)replaceString:(NSString *)inputStr { - NSDictionary *replacements = @{ - @"SED" : @"S.E.D.", - @"DDR" : @"D.D.R.", - @" IM " : @" I.M. ", - }; - - for (id key in replacements) { - inputStr = [inputStr stringByReplacingOccurrencesOfString:key withString:replacements[key]]; - } - - return inputStr; + NSDictionary *replacements = @{ + @"SED" : @"S.E.D.", + @"DDR" : @"D.D.R.", + @" IM ": @" I.M. ", + }; + + for (id key in replacements) { + inputStr = [inputStr stringByReplacingOccurrencesOfString:key withString:replacements[key]]; + } + + return inputStr; } @end diff --git a/PDFViewer/viewcontroller/ViewController.m b/PDFViewer/viewcontroller/ViewController.m --- a/PDFViewer/viewcontroller/ViewController.m +++ b/PDFViewer/viewcontroller/ViewController.m @@ -13,26 +13,26 @@ @synthesize pdfViewer = _pdfViewer; - (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]; + [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 { - [_pdfViewer speak:[_pdfViewer getTexts]]; + [_pdfViewer speak:[_pdfViewer getTexts]]; } - (void)viewDidDisappear { - [_pdfViewer stopSpeaking:self]; + [_pdfViewer silence]; } - (void)setRepresentedObject:(id)representedObject { - [super setRepresentedObject:representedObject]; + [super setRepresentedObject:representedObject]; } @end