Revision: 7113
          http://skim-app.svn.sourceforge.net/skim-app/?rev=7113&view=rev
Author:   hofman
Date:     2011-02-18 11:09:24 +0000 (Fri, 18 Feb 2011)

Log Message:
-----------
move warning for duplicate singletons, enforce singleton for preferences 
because that's more critical

Modified Paths:
--------------
    trunk/SKDownloadController.m
    trunk/SKFindController.m
    trunk/SKInfoWindowController.m
    trunk/SKLineInspector.m
    trunk/SKNotesPanelController.m
    trunk/SKPreferenceController.m
    trunk/SKReleaseNotesController.m

Modified: trunk/SKDownloadController.m
===================================================================
--- trunk/SKDownloadController.m        2011-02-18 10:47:30 UTC (rev 7112)
+++ trunk/SKDownloadController.m        2011-02-18 11:09:24 UTC (rev 7113)
@@ -80,12 +80,8 @@
     return sharedDownloadController;
 }
 
-+ (id)allocWithZone:(NSZone *)zone {
-    if (sharedDownloadController) NSLog(@"Attempt to allocate second instance 
of %@", self);
-    return [super allocWithZone:zone];
-}
-
 - (id)init {
+    if (sharedDownloadController) NSLog(@"Attempt to allocate second instance 
of %@", self);
     if (self = [super initWithWindowNibName:@"DownloadsWindow"]) {
         downloads = [[NSMutableArray alloc] init];
     }

Modified: trunk/SKFindController.m
===================================================================
--- trunk/SKFindController.m    2011-02-18 10:47:30 UTC (rev 7112)
+++ trunk/SKFindController.m    2011-02-18 11:09:24 UTC (rev 7113)
@@ -55,12 +55,8 @@
     return sharedFindController;
 }
 
-+ (id)allocWithZone:(NSZone *)zone {
-    if (sharedFindController) NSLog(@"Attempt to allocate second instance of 
%@", self);
-    return [super allocWithZone:zone];
-}
-
 - (id)init {
+    if (sharedFindController) NSLog(@"Attempt to allocate second instance of 
%@", self);
     if (self = [super initWithWindowNibName:@"FindPanel"]) {
         ignoreCase = YES;
     }

Modified: trunk/SKInfoWindowController.m
===================================================================
--- trunk/SKInfoWindowController.m      2011-02-18 10:47:30 UTC (rev 7112)
+++ trunk/SKInfoWindowController.m      2011-02-18 11:09:24 UTC (rev 7113)
@@ -88,12 +88,8 @@
     return sharedInstance;
 }
 
-+ (id)allocWithZone:(NSZone *)zone {
-    if (sharedInstance) NSLog(@"Attempt to allocate second instance of %@", 
self);
-    return [super allocWithZone:zone];
-}
-
 - (id)init {
+    if (sharedInstance) NSLog(@"Attempt to allocate second instance of %@", 
self);
     if (self = [super initWithWindowNibName:@"InfoWindow"]){
         info = nil;
         summaryKeys = [[NSArray alloc] initWithObjects:

Modified: trunk/SKLineInspector.m
===================================================================
--- trunk/SKLineInspector.m     2011-02-18 10:47:30 UTC (rev 7112)
+++ trunk/SKLineInspector.m     2011-02-18 11:09:24 UTC (rev 7113)
@@ -70,12 +70,8 @@
     return sharedLineInspector != nil;
 }
 
-+ (id)allocWithZone:(NSZone *)zone {
-    if (sharedLineInspector) NSLog(@"Attempt to allocate second instance of 
%@", self);
-    return [super allocWithZone:zone];
-}
-
 - (id)init {
+    if (sharedLineInspector) NSLog(@"Attempt to allocate second instance of 
%@", self);
     if (self = [super initWithWindowNibName:@"LineInspector"]) {
         style = kPDFBorderStyleSolid;
         lineWidth = 1.0;

Modified: trunk/SKNotesPanelController.m
===================================================================
--- trunk/SKNotesPanelController.m      2011-02-18 10:47:30 UTC (rev 7112)
+++ trunk/SKNotesPanelController.m      2011-02-18 11:09:24 UTC (rev 7113)
@@ -56,12 +56,8 @@
     return sharedController != nil;
 }
 
-+ (id)allocWithZone:(NSZone *)zone {
-    if (sharedController) NSLog(@"Attempt to allocate second instance of %@", 
self);
-    return [super allocWithZone:zone];
-}
-
 - (id)init {
+    if (sharedController) NSLog(@"Attempt to allocate second instance of %@", 
self);
     return (self = [super initWithWindowNibName:@"NotesPanel"]);
 }
 

Modified: trunk/SKPreferenceController.m
===================================================================
--- trunk/SKPreferenceController.m      2011-02-18 10:47:30 UTC (rev 7112)
+++ trunk/SKPreferenceController.m      2011-02-18 11:09:24 UTC (rev 7113)
@@ -64,22 +64,28 @@
 
 + (id)sharedPrefenceController {
     if (sharedPrefenceController == nil)
-        sharedPrefenceController = [[self alloc] init];
+        [[[self alloc] init] autorelease];
     return sharedPrefenceController;
 }
 
 + (id)allocWithZone:(NSZone *)zone {
-    if (sharedPrefenceController) NSLog(@"Attempt to allocate second instance 
of %@", self);
-    return [super allocWithZone:zone];
+    return [sharedPrefenceController retain] ?: [super allocWithZone:zone];
 }
 
 - (id)init {
-    if (self = [super initWithWindowNibName:@"PreferenceWindow"]) {
-        preferencePanes = [[NSArray alloc] initWithObjects:
-            [[[SKGeneralPreferences alloc] init] autorelease], 
-            [[[SKDisplayPreferences alloc] init] autorelease], 
-            [[[SKNotesPreferences alloc] init] autorelease], 
-            [[[SKSyncPreferences alloc] init] autorelease], nil];
+    if (sharedPrefenceController == nil) {
+        if (self = [super initWithWindowNibName:@"PreferenceWindow"]) {
+            preferencePanes = [[NSArray alloc] initWithObjects:
+                [[[SKGeneralPreferences alloc] init] autorelease], 
+                [[[SKDisplayPreferences alloc] init] autorelease], 
+                [[[SKNotesPreferences alloc] init] autorelease], 
+                [[[SKSyncPreferences alloc] init] autorelease], nil];
+        }
+        sharedPrefenceController = [self retain];
+    } else if (self != sharedPrefenceController) {
+        NSLog(@"Attempt to allocate second instance of %@", [self class]);
+        [self release];
+        self = [sharedPrefenceController retain];
     }
     return self;
 }

Modified: trunk/SKReleaseNotesController.m
===================================================================
--- trunk/SKReleaseNotesController.m    2011-02-18 10:47:30 UTC (rev 7112)
+++ trunk/SKReleaseNotesController.m    2011-02-18 11:09:24 UTC (rev 7113)
@@ -51,12 +51,8 @@
     return sharedReleaseNotesController;
 }
 
-+ (id)allocWithZone:(NSZone *)zone {
-    if (sharedReleaseNotesController) NSLog(@"Attempt to allocate second 
instance of %@", self);
-    return [super allocWithZone:zone];
-}
-
 - (id)init {
+    if (sharedReleaseNotesController) NSLog(@"Attempt to allocate second 
instance of %@", self);
     return (self = [super initWithWindowNibName:@"ReleaseNotes"]);
 }
 


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

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to