Revision: 4423
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4423&view=rev
Author:   hofman
Date:     2008-08-18 15:22:35 +0000 (Mon, 18 Aug 2008)

Log Message:
-----------
Implement bookmark class cluster using a separate placeholder subclass

Modified Paths:
--------------
    trunk/SKBookmark.m

Modified: trunk/SKBookmark.m
===================================================================
--- trunk/SKBookmark.m  2008-08-18 11:07:56 UTC (rev 4422)
+++ trunk/SKBookmark.m  2008-08-18 15:22:35 UTC (rev 4423)
@@ -54,6 +54,9 @@
 static NSString *SKBookmarkAliasDataKey = @"_BDAlias";
 static NSString *SKBookmarkTypeKey = @"type";
 
[EMAIL PROTECTED] SKPlaceholderBookmark : SKBookmark
[EMAIL PROTECTED]
+
 @interface SKFileBookmark : SKBookmark {
     BDAlias *alias;
     NSData *aliasData;
@@ -77,85 +80,61 @@
 @interface SKSeparatorBookmark : SKBookmark
 @end
 
+#pragma mark -
+
 @implementation SKBookmark
 
-static SKBookmark *defaultPlaceholderBookmark = nil;
+static SKPlaceholderBookmark *defaultPlaceholderBookmark = nil;
 static Class SKBookmarkClass = Nil;
 
 + (void)initialize {
     OBINITIALIZE;
-    if (self == [SKBookmark class]) {
-        SKBookmarkClass = self;
-        defaultPlaceholderBookmark = (SKBookmark 
*)NSAllocateObject(SKBookmarkClass, 0, NSDefaultMallocZone());
-    }
+    SKBookmarkClass = self;
+    defaultPlaceholderBookmark = (SKPlaceholderBookmark 
*)NSAllocateObject([SKPlaceholderBookmark class], 0, NSDefaultMallocZone());
 }
 
 + (id)allocWithZone:(NSZone *)aZone {
-    return SKBookmarkClass == self ? defaultPlaceholderBookmark : 
NSAllocateObject(self, 0, aZone);
+    return SKBookmarkClass == self ? defaultPlaceholderBookmark : [super 
allocWithZone:aZone];
 }
 
-- (id)init {
-    return self != defaultPlaceholderBookmark ? [super init] : nil;
-}
-
 - (id)initWithAlias:(BDAlias *)anAlias pageIndex:(unsigned)aPageIndex 
label:(NSString *)aLabel {
-    if (self != defaultPlaceholderBookmark)
-        [self release];
-    return [[SKFileBookmark alloc] initWithAlias:anAlias pageIndex:aPageIndex 
label:aLabel];
+    [self doesNotRecognizeSelector:_cmd];
+    return nil;
 }
 
 - (id)initWithPath:(NSString *)aPath pageIndex:(unsigned)aPageIndex 
label:(NSString *)aLabel {
-    return [self initWithAlias:[BDAlias aliasWithPath:aPath] 
pageIndex:aPageIndex label:aLabel];
+    [self doesNotRecognizeSelector:_cmd];
+    return nil;
 }
 
 - (id)initWithSetup:(NSDictionary *)aSetupDict label:(NSString *)aLabel {
-    if (self != defaultPlaceholderBookmark)
-        [self release];
-    return [[SKFileBookmark alloc] initWithSetup:aSetupDict label:aLabel];
+    [self doesNotRecognizeSelector:_cmd];
+    return nil;
 }
 
 - (id)initFolderWithChildren:(NSArray *)aChildren label:(NSString *)aLabel {
-    if (self != defaultPlaceholderBookmark)
-        [self release];
-    return [[SKFolderBookmark alloc] initFolderWithChildren:aChildren 
label:aLabel];
+    [self doesNotRecognizeSelector:_cmd];
+    return nil;
 }
 
 - (id)initFolderWithLabel:(NSString *)aLabel {
-    return [self initFolderWithChildren:[NSArray array] label:aLabel];
+    [self doesNotRecognizeSelector:_cmd];
+    return nil;
 }
 
 - (id)initSessionWithChildren:(NSArray *)aChildren label:(NSString *)aLabel {
-    if (self != defaultPlaceholderBookmark)
-        [self release];
-    return [[SKSessionBookmark alloc] initSessionWithChildren:aChildren 
label:aLabel];
+    [self doesNotRecognizeSelector:_cmd];
+    return nil;
 }
 
 - (id)initSeparator {
-    if (self != defaultPlaceholderBookmark)
-        [self release];
-    return [[SKSeparatorBookmark alloc] init];
+    [self doesNotRecognizeSelector:_cmd];
+    return nil;
 }
 
 - (id)initWithProperties:(NSDictionary *)dictionary {
-    if ([[dictionary objectForKey:SKBookmarkTypeKey] 
isEqualToString:SKBookmarkTypeFolderString]) {
-        NSEnumerator *dictEnum = [[dictionary 
objectForKey:SKBookmarkChildrenKey] objectEnumerator];
-        NSDictionary *dict;
-        NSMutableArray *newChildren = [NSMutableArray array];
-        while (dict = [dictEnum nextObject])
-            [newChildren addObject:[[[[self class] alloc] 
initWithProperties:dict] autorelease]];
-        return [self initFolderWithChildren:newChildren label:[dictionary 
objectForKey:SKBookmarkLabelKey]];
-    } else if ([[dictionary objectForKey:SKBookmarkTypeKey] 
isEqualToString:SKBookmarkTypeSeparatorString]) {
-        return [self initSeparator];
-    } else if ([[dictionary objectForKey:SKBookmarkTypeKey] 
isEqualToString:SKBookmarkTypeSessionString]) {
-        NSEnumerator *dictEnum = [[dictionary 
objectForKey:SKBookmarkChildrenKey] objectEnumerator];
-        NSDictionary *dict;
-        NSMutableArray *newChildren = [NSMutableArray array];
-        while (dict = [dictEnum nextObject])
-            [newChildren addObject:[[[[self class] alloc] 
initWithProperties:dict] autorelease]];
-        return [self initSessionWithChildren:newChildren label:[dictionary 
objectForKey:SKBookmarkLabelKey]];
-    } else {
-        return [self initWithAlias:[BDAlias aliasWithData:[dictionary 
objectForKey:SKBookmarkAliasDataKey]] pageIndex:[[dictionary 
objectForKey:SKBookmarkPageIndexKey] unsignedIntValue] label:[dictionary 
objectForKey:SKBookmarkLabelKey]];
-    }
+    [self doesNotRecognizeSelector:_cmd];
+    return nil;
 }
 
 - (id)copyWithZone:(NSZone *)aZone {
@@ -163,11 +142,6 @@
     return nil;
 }
 
-- (void)dealloc {
-    if (self != defaultPlaceholderBookmark)
-        [super dealloc];
-}
-
 - (NSDictionary *)properties { return nil; }
 
 - (int)bookmarkType { return SKBookmarkTypeSeparator; }
@@ -222,6 +196,75 @@
 
 #pragma mark -
 
[EMAIL PROTECTED] SKPlaceholderBookmark
+
+- (id)init {
+    return nil;
+}
+
+- (id)initWithAlias:(BDAlias *)anAlias pageIndex:(unsigned)aPageIndex 
label:(NSString *)aLabel {
+    return [[SKFileBookmark alloc] initWithAlias:anAlias pageIndex:aPageIndex 
label:aLabel];
+}
+
+- (id)initWithPath:(NSString *)aPath pageIndex:(unsigned)aPageIndex 
label:(NSString *)aLabel {
+    return [self initWithAlias:[BDAlias aliasWithPath:aPath] 
pageIndex:aPageIndex label:aLabel];
+}
+
+- (id)initWithSetup:(NSDictionary *)aSetupDict label:(NSString *)aLabel {
+    return [[SKFileBookmark alloc] initWithSetup:aSetupDict label:aLabel];
+}
+
+- (id)initFolderWithChildren:(NSArray *)aChildren label:(NSString *)aLabel {
+    return [[SKFolderBookmark alloc] initFolderWithChildren:aChildren 
label:aLabel];
+}
+
+- (id)initFolderWithLabel:(NSString *)aLabel {
+    return [self initFolderWithChildren:[NSArray array] label:aLabel];
+}
+
+- (id)initSessionWithChildren:(NSArray *)aChildren label:(NSString *)aLabel {
+    return [[SKSessionBookmark alloc] initSessionWithChildren:aChildren 
label:aLabel];
+}
+
+- (id)initSeparator {
+    return [[SKSeparatorBookmark alloc] init];
+}
+
+- (id)initWithProperties:(NSDictionary *)dictionary {
+    NSString *type = [dictionary objectForKey:SKBookmarkTypeKey];
+    if ([type isEqualToString:SKBookmarkTypeFolderString]) {
+        NSEnumerator *dictEnum = [[dictionary 
objectForKey:SKBookmarkChildrenKey] objectEnumerator];
+        NSDictionary *dict;
+        NSMutableArray *newChildren = [NSMutableArray array];
+        while (dict = [dictEnum nextObject])
+            [newChildren addObject:[[[[self class] alloc] 
initWithProperties:dict] autorelease]];
+        return [self initFolderWithChildren:newChildren label:[dictionary 
objectForKey:SKBookmarkLabelKey]];
+    } else if ([type isEqualToString:SKBookmarkTypeSeparatorString]) {
+        return [self initSeparator];
+    } else if ([type isEqualToString:SKBookmarkTypeSessionString]) {
+        NSEnumerator *dictEnum = [[dictionary 
objectForKey:SKBookmarkChildrenKey] objectEnumerator];
+        NSDictionary *dict;
+        NSMutableArray *newChildren = [NSMutableArray array];
+        while (dict = [dictEnum nextObject])
+            [newChildren addObject:[[[[self class] alloc] 
initWithProperties:dict] autorelease]];
+        return [self initSessionWithChildren:newChildren label:[dictionary 
objectForKey:SKBookmarkLabelKey]];
+    } else {
+        return [self initWithAlias:[BDAlias aliasWithData:[dictionary 
objectForKey:SKBookmarkAliasDataKey]] pageIndex:[[dictionary 
objectForKey:SKBookmarkPageIndexKey] unsignedIntValue] label:[dictionary 
objectForKey:SKBookmarkLabelKey]];
+    }
+}
+
+- (id)retain { return self; }
+
+- (id)autorelease { return self; }
+
+- (void)release {}
+
+- (unsigned)retainCount { return UINT_MAX; }
+
[EMAIL PROTECTED]
+
+#pragma mark -
+
 @implementation SKFileBookmark
 
 - (id)initWithAlias:(BDAlias *)anAlias pageIndex:(unsigned)aPageIndex 
label:(NSString *)aLabel {


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