--- a/PDFViewer/Base.lproj/Main.storyboard
+++ b/PDFViewer/Base.lproj/Main.storyboard
@@ -59,52 +59,18 @@
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="File" id="bib-Uj-vzu">
<items>
- <menuItem title="New" keyEquivalent="n" id="Was-JA-tGl">
- <connections>
- <action selector="newDocument:" target="Ady-hI-5gd" id="4Si-XN-c54"/>
- </connections>
- </menuItem>
<menuItem title="Open…" keyEquivalent="o" id="IAo-SY-fd9">
<connections>
<action selector="openDocument:" target="Ady-hI-5gd" id="bVn-NM-KNZ"/>
</connections>
</menuItem>
- <menuItem title="Open Recent" id="tXI-mr-wws">
- <modifierMask key="keyEquivalentModifierMask"/>
- <menu key="submenu" title="Open Recent" systemMenu="recentDocuments" id="oas-Oc-fiZ">
- <items>
- <menuItem title="Clear Menu" id="vNY-rz-j42">
- <modifierMask key="keyEquivalentModifierMask"/>
- <connections>
- <action selector="clearRecentDocuments:" target="Ady-hI-5gd" id="Daa-9d-B3U"/>
- </connections>
- </menuItem>
- </items>
- </menu>
- </menuItem>
<menuItem isSeparatorItem="YES" id="m54-Is-iLE"/>
<menuItem title="Close" keyEquivalent="w" id="DVo-aG-piG">
<connections>
<action selector="performClose:" target="Ady-hI-5gd" id="HmO-Ls-i7Q"/>
</connections>
</menuItem>
- <menuItem title="Save…" keyEquivalent="s" id="pxx-59-PXV">
- <connections>
- <action selector="saveDocument:" target="Ady-hI-5gd" id="teZ-XB-qJY"/>
- </connections>
- </menuItem>
- <menuItem title="Save As…" keyEquivalent="S" id="Bw7-FT-i3A">
- <connections>
- <action selector="saveDocumentAs:" target="Ady-hI-5gd" id="mDf-zr-I0C"/>
- </connections>
- </menuItem>
- <menuItem title="Revert to Saved" id="KaW-ft-85H">
- <modifierMask key="keyEquivalentModifierMask"/>
- <connections>
- <action selector="revertDocumentToSaved:" target="Ady-hI-5gd" id="iJ3-Pv-kwq"/>
- </connections>
- </menuItem>
- <menuItem isSeparatorItem="YES" id="aJh-i4-bef"/>
+ <menuItem isSeparatorItem="YES" id="TBz-Zh-e9S"/>
<menuItem title="Page Setup…" keyEquivalent="P" id="qIS-W8-SiK">
<modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
<connections>
--- 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
--- a/PDFViewer/pdfviewer/PDFViewer.h
+++ b/PDFViewer/pdfviewer/PDFViewer.h
@@ -8,9 +8,13 @@
#import <Quartz/Quartz.h>
@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;
--- 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
--- 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