mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 05:40:37 +00:00
Cleaned up NSNib
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@18599 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d3140f2622
commit
1abba28912
3 changed files with 31 additions and 67 deletions
|
@ -1,3 +1,8 @@
|
|||
2004-02-14 23:05 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* Source/NSNib.[hm]: Corrected previous issue with NSNib.
|
||||
Uncommented the code and cleaned up the implementation.
|
||||
|
||||
2004-02-14 22:56 Matt Rice <ratmice@yahoo.com>
|
||||
Alexander Malmberg <alexander@malmberg.org>
|
||||
|
||||
|
|
|
@ -38,10 +38,12 @@
|
|||
@class NSBundle;
|
||||
@class NSURL;
|
||||
@class NSArray;
|
||||
@class NSMutableArray;
|
||||
|
||||
@interface NSNib : NSObject <NSCoding>
|
||||
{
|
||||
NSData *_nibData;
|
||||
NSMutableArray *_topLevelItems;
|
||||
}
|
||||
|
||||
// reading the data...
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue