Revision: 4572
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4572&view=rev
Author:   hofman
Date:     2008-09-07 11:35:54 +0000 (Sun, 07 Sep 2008)

Log Message:
-----------
Make the app controller a singleton

Modified Paths:
--------------
    trunk/NSDocument_SKExtensions.m
    trunk/SKApplicationController.h
    trunk/SKApplicationController.m
    trunk/SKDocumentController.m
    trunk/SKPDFDocument.m

Modified: trunk/NSDocument_SKExtensions.m
===================================================================
--- trunk/NSDocument_SKExtensions.m     2008-09-07 10:58:54 UTC (rev 4571)
+++ trunk/NSDocument_SKExtensions.m     2008-09-07 11:35:54 UTC (rev 4572)
@@ -45,7 +45,7 @@
 @implementation NSDocument (SKExtensions)
 
 - (NSString *)notesStringUsingTemplateFile:(NSString *)templateFile {
-    NSString *templatePath = [[NSApp delegate] 
pathForApplicationSupportFile:[templateFile stringByDeletingPathExtension] 
ofType:[templateFile pathExtension] inDirectory:@"Templates"];
+    NSString *templatePath = [[SKApplicationController 
sharedApplicationController] pathForApplicationSupportFile:[templateFile 
stringByDeletingPathExtension] ofType:[templateFile pathExtension] 
inDirectory:@"Templates"];
     NSError *error = nil;
     NSString *templateString = [[NSString alloc] 
initWithContentsOfFile:templatePath encoding:NSUTF8StringEncoding error:&error];
     NSString *string = [SKTemplateParser 
stringByParsingTemplate:templateString usingObject:self];
@@ -64,7 +64,7 @@
     NSString *fileType = [[templateFile pathExtension] lowercaseString];
     NSData *data = nil;
     if ([richTextTypes containsObject:fileType]) {
-        NSString *templatePath = [[NSApp delegate] 
pathForApplicationSupportFile:[templateFile stringByDeletingPathExtension] 
ofType:[templateFile pathExtension] inDirectory:@"Templates"];
+        NSString *templatePath = [[SKApplicationController 
sharedApplicationController] pathForApplicationSupportFile:[templateFile 
stringByDeletingPathExtension] ofType:[templateFile pathExtension] 
inDirectory:@"Templates"];
         NSDictionary *docAttributes = nil;
         NSError *error = nil;
         NSAttributedString *templateAttrString = [[NSAttributedString alloc] 
initWithPath:templatePath documentAttributes:&docAttributes];
@@ -80,7 +80,7 @@
 - (NSFileWrapper *)notesFileWrapperUsingTemplateFile:(NSString *)templateFile {
     NSFileWrapper *fileWrapper = nil;
     if ([[templateFile pathExtension] caseInsensitiveCompare:@"rtfd"] == 
NSOrderedSame) {
-        NSString *templatePath = [[NSApp delegate] 
pathForApplicationSupportFile:[templateFile stringByDeletingPathExtension] 
ofType:[templateFile pathExtension] inDirectory:@"Templates"];
+        NSString *templatePath = [[SKApplicationController 
sharedApplicationController] pathForApplicationSupportFile:[templateFile 
stringByDeletingPathExtension] ofType:[templateFile pathExtension] 
inDirectory:@"Templates"];
         NSDictionary *docAttributes = nil;
         NSAttributedString *templateAttrString = [[NSAttributedString alloc] 
initWithPath:templatePath documentAttributes:&docAttributes];
         NSAttributedString *attrString = [SKTemplateParser 
attributedStringByParsingTemplate:templateAttrString usingObject:self];

Modified: trunk/SKApplicationController.h
===================================================================
--- trunk/SKApplicationController.h     2008-09-07 10:58:54 UTC (rev 4571)
+++ trunk/SKApplicationController.h     2008-09-07 11:35:54 UTC (rev 4572)
@@ -47,7 +47,7 @@
     BOOL remoteScrolling;
 }
 
-+ (void)setupDefaults;
++ (id)sharedApplicationController;
 
 - (IBAction)orderFrontLineInspector:(id)sender;
 - (IBAction)orderFrontNotesPanel:(id)sender;

Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m     2008-09-07 10:58:54 UTC (rev 4571)
+++ trunk/SKApplicationController.m     2008-09-07 11:35:54 UTC (rev 4572)
@@ -96,10 +96,6 @@
 + (void)initialize{
     OBINITIALIZE;
     
-    [self setupDefaults];
-}
-   
-+ (void)setupDefaults{
     // load the default values for the user defaults
     NSString *initialUserDefaultsPath = [[NSBundle mainBundle] 
pathForResource:INITIAL_USER_DEFAULTS_FILENAME ofType:@"plist"];
     NSDictionary *initialUserDefaultsDict = [NSDictionary 
dictionaryWithContentsOfFile:initialUserDefaultsPath];
@@ -120,6 +116,32 @@
     [[NSUserDefaultsController sharedUserDefaultsController] 
setInitialValues:initialValuesDict];
 }
 
+static id sharedApplicationController = nil;
+
++ (id)sharedApplicationController {
+    if (sharedApplicationController == nil)
+        [[self alloc] init];
+    return sharedApplicationController;
+}
+
++ (id)allocWithZone:(NSZone *)zone {
+    return sharedApplicationController ?: [super allocWithZone:zone];
+}
+
+- (id)init {
+    if (sharedApplicationController == nil)
+        sharedApplicationController = [super init];
+    return sharedApplicationController;
+}
+
+- (id)retain { return self; }
+
+- (id)autorelease { return self; }
+
+- (void)release {}
+
+- (unsigned)retainCount { return UINT_MAX; }
+
 - (void)awakeFromNib {
     NSMenu *viewMenu = [[[NSApp mainMenu] itemAtIndex:VIEW_MENU_INDEX] 
submenu];
     int i, count = [viewMenu numberOfItems];

Modified: trunk/SKDocumentController.m
===================================================================
--- trunk/SKDocumentController.m        2008-09-07 10:58:54 UTC (rev 4571)
+++ trunk/SKDocumentController.m        2008-09-07 11:35:54 UTC (rev 4572)
@@ -418,7 +418,7 @@
     if (customExportTemplateFiles == nil) {
         NSFileManager *fm = [NSFileManager defaultManager];
         NSMutableArray *templateFiles = [NSMutableArray array];
-        NSEnumerator *pathEnum = [[[NSApp delegate] 
applicationSupportDirectories] objectEnumerator];
+        NSEnumerator *pathEnum = [[[SKApplicationController 
sharedApplicationController] applicationSupportDirectories] objectEnumerator];
         NSString *appSupportPath;
         
         while (appSupportPath = [pathEnum nextObject]) {

Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m       2008-09-07 10:58:54 UTC (rev 4571)
+++ trunk/SKPDFDocument.m       2008-09-07 11:35:54 UTC (rev 4572)
@@ -1413,7 +1413,7 @@
         NSString *editorPreset = [[NSUserDefaults standardUserDefaults] 
objectForKey:SKTeXEditorPresetKey];
         NSString *editorCmd = [[NSUserDefaults standardUserDefaults] 
objectForKey:SKTeXEditorCommandKey];
         NSMutableString *cmdString = [[[[NSUserDefaults standardUserDefaults] 
objectForKey:SKTeXEditorArgumentsKey] mutableCopy] autorelease];
-        NSEnumerator *pathEnum = [[[NSApp delegate] 
applicationSupportDirectories] objectEnumerator];
+        NSEnumerator *pathEnum = [[[SKApplicationController 
sharedApplicationController] applicationSupportDirectories] objectEnumerator];
         NSString *appSupportPath;
         NSMutableDictionary *environment = [[[[NSProcessInfo processInfo] 
environment] mutableCopy] autorelease];
         NSMutableArray *paths = [NSMutableArray arrayWithArray:[[environment 
objectForKey:@"PATH"] componentsSeparatedByString:@":"]];


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to