mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 13:11:55 +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>
|
2004-02-14 22:56 Matt Rice <ratmice@yahoo.com>
|
||||||
Alexander Malmberg <alexander@malmberg.org>
|
Alexander Malmberg <alexander@malmberg.org>
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,12 @@
|
||||||
@class NSBundle;
|
@class NSBundle;
|
||||||
@class NSURL;
|
@class NSURL;
|
||||||
@class NSArray;
|
@class NSArray;
|
||||||
|
@class NSMutableArray;
|
||||||
|
|
||||||
@interface NSNib : NSObject <NSCoding>
|
@interface NSNib : NSObject <NSCoding>
|
||||||
{
|
{
|
||||||
NSData *_nibData;
|
NSData *_nibData;
|
||||||
|
NSMutableArray *_topLevelItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reading the data...
|
// reading the data...
|
||||||
|
|
|
@ -54,61 +54,6 @@
|
||||||
#include "GNUstepGUI/GSNibTemplates.h"
|
#include "GNUstepGUI/GSNibTemplates.h"
|
||||||
#include "GNUstepGUI/IMLoading.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
|
@implementation NSNib
|
||||||
|
|
||||||
+ (NSString *) _nibFilename: (NSString *)fileName
|
+ (NSString *) _nibFilename: (NSString *)fileName
|
||||||
|
@ -165,7 +110,24 @@
|
||||||
NS_ENDHANDLER
|
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
|
* Load the NSNib object from the specified URL. This location can be
|
||||||
|
@ -178,6 +140,7 @@
|
||||||
{
|
{
|
||||||
// load the nib data into memory...
|
// load the nib data into memory...
|
||||||
_nibData = [NSData dataWithContentsOfURL: nibFileURL];
|
_nibData = [NSData dataWithContentsOfURL: nibFileURL];
|
||||||
|
[self _addObserver];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -205,6 +168,7 @@
|
||||||
|
|
||||||
// load the nib data into memory...
|
// load the nib data into memory...
|
||||||
[self _readNibData: fileName];
|
[self _readNibData: fileName];
|
||||||
|
[self _addObserver];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -216,9 +180,7 @@
|
||||||
- (BOOL)instantiateNibWithExternalNameTable: (NSDictionary *)externalNameTable
|
- (BOOL)instantiateNibWithExternalNameTable: (NSDictionary *)externalNameTable
|
||||||
withZone: (NSZone *)zone
|
withZone: (NSZone *)zone
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
BOOL loaded = NO;
|
BOOL loaded = NO;
|
||||||
id nibitems = nil;
|
|
||||||
NSUnarchiver *unarchiver = nil;
|
NSUnarchiver *unarchiver = nil;
|
||||||
|
|
||||||
NS_DURING
|
NS_DURING
|
||||||
|
@ -230,18 +192,16 @@
|
||||||
{
|
{
|
||||||
id obj;
|
id obj;
|
||||||
|
|
||||||
nibitems = [[_GSNibItemCollector alloc] init];
|
|
||||||
NSDebugLog(@"Invoking unarchiver");
|
NSDebugLog(@"Invoking unarchiver");
|
||||||
[unarchiver setObjectZone: zone];
|
[unarchiver setObjectZone: zone];
|
||||||
obj = [unarchiver decodeObject];
|
obj = [unarchiver decodeObject];
|
||||||
if (obj != nil)
|
if (obj != nil)
|
||||||
{
|
{
|
||||||
NSArray *items = [nibitems items];
|
|
||||||
if ([obj isKindOfClass: [GSNibContainer class]])
|
if ([obj isKindOfClass: [GSNibContainer class]])
|
||||||
{
|
{
|
||||||
NSDebugLog(@"Calling awakeWithContext");
|
NSDebugLog(@"Calling awakeWithContext");
|
||||||
[obj awakeWithContext: externalNameTable
|
[obj awakeWithContext: externalNameTable
|
||||||
topLevelItems: items];
|
topLevelItems: _topLevelItems];
|
||||||
loaded = YES;
|
loaded = YES;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -249,7 +209,6 @@
|
||||||
NSLog(@"Nib '%@' without container object!");
|
NSLog(@"Nib '%@' without container object!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RELEASE(nibitems);
|
|
||||||
RELEASE(unarchiver);
|
RELEASE(unarchiver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,7 +216,6 @@
|
||||||
NS_HANDLER
|
NS_HANDLER
|
||||||
{
|
{
|
||||||
NSLog(@"Exception occured while loading model: %@",[localException reason]);
|
NSLog(@"Exception occured while loading model: %@",[localException reason]);
|
||||||
TEST_RELEASE(nibitems);
|
|
||||||
TEST_RELEASE(unarchiver);
|
TEST_RELEASE(unarchiver);
|
||||||
}
|
}
|
||||||
NS_ENDHANDLER
|
NS_ENDHANDLER
|
||||||
|
@ -268,8 +226,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
return loaded;
|
return loaded;
|
||||||
*/
|
|
||||||
return NO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -325,6 +281,7 @@
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
RELEASE(_nibData);
|
RELEASE(_nibData);
|
||||||
|
RELEASE(_topLevelItems);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue