From 1abba2891213f815c528afc67b645bd61fecc226 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sun, 15 Feb 2004 03:58:10 +0000 Subject: [PATCH] Cleaned up NSNib git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@18599 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++ Headers/AppKit/NSNib.h | 2 + Source/NSNib.m | 91 +++++++++++------------------------------- 3 files changed, 31 insertions(+), 67 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5f7d2d333..d64668c0d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-02-14 23:05 Gregory John Casamento + + * Source/NSNib.[hm]: Corrected previous issue with NSNib. + Uncommented the code and cleaned up the implementation. + 2004-02-14 22:56 Matt Rice Alexander Malmberg diff --git a/Headers/AppKit/NSNib.h b/Headers/AppKit/NSNib.h index dff32faed..33d6731d0 100644 --- a/Headers/AppKit/NSNib.h +++ b/Headers/AppKit/NSNib.h @@ -38,10 +38,12 @@ @class NSBundle; @class NSURL; @class NSArray; +@class NSMutableArray; @interface NSNib : NSObject { NSData *_nibData; + NSMutableArray *_topLevelItems; } // reading the data... diff --git a/Source/NSNib.m b/Source/NSNib.m index 0258ef778..add356c87 100644 --- a/Source/NSNib.m +++ b/Source/NSNib.m @@ -54,61 +54,6 @@ #include "GNUstepGUI/GSNibTemplates.h" #include "GNUstepGUI/IMLoading.h" -/* - * This private class is used to collect the nib items while the - * .gorm file is being unarchived. This is done to allow only - * the top level items to be retained in a clean way. The reason it's - * being done this way is because old .gorm files don't have any - * array within the nameTable which indicates the objects which are - * considered top level, so there is no clean and generic way to determine - * this. Basically the top level items are any instances of or instances - * of subclasses of NSMenu, NSWindow, or any controller class. - * It's the last one that's hairy. Controller classes are - * represented in .gorm files by the GSNibItem class, but once they transform - * into the actual class instance it's not easy to tell if it should be - * retained or not since there are a lot of other things stored in the nameTable - * as well. GJC - */ - -/* -@interface _GSNibItemCollector : NSObject -{ - NSMutableArray *items; -} -- (void) handleNotification: (NSNotification *)notification; -- (NSMutableArray *)items; -@end - -@implementation _GSNibItemCollector -- (void) handleNotification: (NSNotification *)notification; -{ - id obj = [notification object]; - [items addObject: obj]; -} - -- init -{ - if((self = [super init]) != nil) - { - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - - // add myself as an observer and initialize the items array. - [nc addObserver: self - selector: @selector(handleNotification:) - name: @"__GSInternalNibItemAddedNotification" - object: nil]; - items = [[NSMutableArray alloc] init]; - } - return self; -} - -- (NSMutableArray *)items -{ - return items; -} -@end -*/ - @implementation NSNib + (NSString *) _nibFilename: (NSString *)fileName @@ -165,7 +110,24 @@ NS_ENDHANDLER } -// reading the data... +// handle the notification... +- (void) _handleNotification: (NSNotification *)notification +{ + id obj = [notification object]; + [_topLevelItems addObject: obj]; +} + +// subscribe to the notification... +- (void) _addObserver +{ + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + + // add myself as an observer and initialize the items array. + [nc addObserver: self + selector: @selector(_handleNotification:) + name: @"__GSInternalNibItemAddedNotification" + object: nil]; +} /** * Load the NSNib object from the specified URL. This location can be @@ -178,6 +140,7 @@ { // load the nib data into memory... _nibData = [NSData dataWithContentsOfURL: nibFileURL]; + [self _addObserver]; } return self; } @@ -205,6 +168,7 @@ // load the nib data into memory... [self _readNibData: fileName]; + [self _addObserver]; } return self; } @@ -216,9 +180,7 @@ - (BOOL)instantiateNibWithExternalNameTable: (NSDictionary *)externalNameTable withZone: (NSZone *)zone { - /* BOOL loaded = NO; - id nibitems = nil; NSUnarchiver *unarchiver = nil; NS_DURING @@ -228,28 +190,25 @@ unarchiver = [[NSUnarchiver alloc] initForReadingWithData: _nibData]; if (unarchiver != nil) { - id obj; + id obj; - nibitems = [[_GSNibItemCollector alloc] init]; NSDebugLog(@"Invoking unarchiver"); [unarchiver setObjectZone: zone]; obj = [unarchiver decodeObject]; if (obj != nil) { - NSArray *items = [nibitems items]; if ([obj isKindOfClass: [GSNibContainer class]]) { NSDebugLog(@"Calling awakeWithContext"); [obj awakeWithContext: externalNameTable - topLevelItems: items]; + topLevelItems: _topLevelItems]; loaded = YES; - } + } else { NSLog(@"Nib '%@' without container object!"); } } - RELEASE(nibitems); RELEASE(unarchiver); } } @@ -257,7 +216,6 @@ NS_HANDLER { NSLog(@"Exception occured while loading model: %@",[localException reason]); - TEST_RELEASE(nibitems); TEST_RELEASE(unarchiver); } NS_ENDHANDLER @@ -268,8 +226,6 @@ } return loaded; - */ - return NO; } /** @@ -325,6 +281,7 @@ - (void) dealloc { RELEASE(_nibData); + RELEASE(_topLevelItems); [super dealloc]; }