Tidy nib stuff

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5652 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-01-03 18:42:16 +00:00
parent 5b6b7b366b
commit ecad93d9c8
3 changed files with 114 additions and 98 deletions

View file

@ -1,3 +1,8 @@
Mon Jan 3 18:35:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSBundleAdditions.m: Added ([-awakeWithContext:]) method for
nib containers to wake up a newly unarchived nib.
2000-01-03 Adam Fedor <fedor@gnu.org> 2000-01-03 Adam Fedor <fedor@gnu.org>
* Source/NSBitmapImageRep.m ([NSBitmapImageRep -draw]): Use * Source/NSBitmapImageRep.m ([NSBitmapImageRep -draw]): Use

View file

@ -69,7 +69,9 @@
{ {
NSMutableDictionary *nameTable; NSMutableDictionary *nameTable;
NSMutableArray *connections; NSMutableArray *connections;
BOOL _isAwake;
} }
- (void) awakeWithContext: (NSDictionary*)context;
- (NSMutableDictionary*) nameTable; - (NSMutableDictionary*) nameTable;
- (NSMutableArray*) connections; - (NSMutableArray*) connections;
@end @end

View file

@ -139,25 +139,29 @@
@implementation NSNibOutletConnector @implementation NSNibOutletConnector
- (void) establishConnection - (void) establishConnection
{ {
NSString *selName; if (_src != nil)
SEL sel; {
NSString *selName;
SEL sel;
selName = [NSString stringWithFormat: @"set%@:", [_tag capitalizedString]]; selName = [NSString stringWithFormat: @"set%@:",
sel = NSSelectorFromString(selName); [_tag capitalizedString]];
sel = NSSelectorFromString(selName);
if ([_src respondsToSelector: sel]) if ([_src respondsToSelector: sel])
{ {
[_src performSelector: sel withObject: _dst]; [_src performSelector: sel withObject: _dst];
} }
else else
{ {
/* /*
* Use the GNUstep additional function to set the instance variable * Use the GNUstep additional function to set the instance variable
* directly. * directly.
* FIXME - need some way to do this for libFoundation and Foundation * FIXME - need some way to do this for libFoundation and Foundation
* based systems. * based systems.
*/ */
GSSetInstanceVariable(_src, _tag, (void*)&_dst); GSSetInstanceVariable(_src, _tag, (void*)&_dst);
}
} }
} }
@end @end
@ -214,88 +218,13 @@
{ {
if ([obj isKindOfClass: [GSNibContainer class]]) if ([obj isKindOfClass: [GSNibContainer class]])
{ {
GSNibContainer *container = obj; [obj awakeWithContext: context];
NSMutableDictionary *nameTable = [container nameTable];
NSMutableArray *connections = [container connections];
NSEnumerator *enumerator;
NSNibConnector *connection;
NSString *key;
NSArray *visible;
/* /*
* Go through the table of objects in the nib and * Ok - it's all done now - just retain the nib container
* retain each one (except ones that are overridden * so tthat it will not be released when the unarchiver
* by values from the 'context table' and retain them * is released, and the nib contents will persist.
* so they will persist after the container is gone.
* Add local entries into name table.
*/
enumerator = [nameTable keyEnumerator];
while ((key = [enumerator nextObject]) != nil)
{
if ([context objectForKey: key] == nil)
{
RETAIN([nameTable objectForKey: key]);
}
}
[nameTable addEntriesFromDictionary: context];
/*
* Now establish all connections by taking the names
* stored in the connection objects, and replaciong them
* with the corresponding values from the name table
* before telling the connections to establish themselves.
*/
enumerator = [connections objectEnumerator];
while ((connection = [enumerator nextObject]) != nil)
{
id val;
val = [nameTable objectForKey: [connection source]];
[connection setSource: val];
val = [nameTable objectForKey: [connection destination]];
[connection setDestination: val];
[connection establishConnection];
}
/*
* Now tell all the objects that they have been loaded from
* a nib.
*/
enumerator = [nameTable keyEnumerator];
while ((key = [enumerator nextObject]) != nil)
{
if ([context objectForKey: key] == nil)
{
id o;
o = [nameTable objectForKey: key];
if ([o respondsToSelector: @selector(awakeFromNib)])
{
[o awakeFromNib];
}
}
}
/*
* See if there are objects that should be made visible.
*/
visible = [nameTable objectForKey: @"NSVisible"];
if (visible != nil
&& [visible isKindOfClass: [NSArray class]] == YES)
{
unsigned pos = [visible count];
while (pos-- > 0)
{
[[visible objectAtIndex: pos] orderFront: self];
}
}
/*
* Ok - it's all done now - the nib container will
* be released when the unarchiver is released, so
* we will just be left with the real nib contents.
*/ */
RETAIN(obj);
loaded = YES; loaded = YES;
} }
else else
@ -405,10 +334,90 @@
/* /*
* The GSNibContainer class manages the internals os a nib file. * The GSNibContainer class manages the internals of a nib file.
*/ */
@implementation GSNibContainer @implementation GSNibContainer
- (void) awakeWithContext: (NSDictionary*)context
{
if (_isAwake == NO)
{
NSEnumerator *enumerator;
NSNibConnector *connection;
NSString *key;
NSArray *visible;
_isAwake = YES;
/*
* Add local entries into name table.
*/
if ([context count] > 0)
{
[nameTable addEntriesFromDictionary: context];
}
/*
* Now establish all connections by taking the names
* stored in the connection objects, and replaciong them
* with the corresponding values from the name table
* before telling the connections to establish themselves.
*/
enumerator = [connections objectEnumerator];
while ((connection = [enumerator nextObject]) != nil)
{
id val;
val = [nameTable objectForKey: [connection source]];
[connection setSource: val];
val = [nameTable objectForKey: [connection destination]];
[connection setDestination: val];
[connection establishConnection];
}
/*
* Now tell all the objects that they have been loaded from
* a nib.
*/
enumerator = [nameTable keyEnumerator];
while ((key = [enumerator nextObject]) != nil)
{
if ([context objectForKey: key] == nil)
{
id o;
o = [nameTable objectForKey: key];
if ([o respondsToSelector: @selector(awakeFromNib)])
{
[o awakeFromNib];
}
}
}
/*
* See if there are objects that should be made visible.
*/
visible = [nameTable objectForKey: @"NSVisible"];
if (visible != nil
&& [visible isKindOfClass: [NSArray class]] == YES)
{
unsigned pos = [visible count];
while (pos-- > 0)
{
[[visible objectAtIndex: pos] orderFront: self];
}
}
/*
* Now remove any objects added from the context dictionary.
*/
if ([context count] > 0)
{
[nameTable removeObjectsForKeys: [context allKeys]];
}
}
}
- (NSMutableArray*) connections - (NSMutableArray*) connections
{ {
return connections; return connections;