Cleanup of memory management in loadNib code. Minor formatting changes in gopen and GSspell.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@18264 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
uid65715 2003-12-23 18:45:18 +00:00
parent 67bf59a067
commit 3f01db306e
5 changed files with 80 additions and 14 deletions

View file

@ -25,7 +25,6 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// #include "gnustep/gui/config.h"
#include <Foundation/NSClassDescription.h>
#include <Foundation/NSArchiver.h>
#include <Foundation/NSArray.h>
@ -96,6 +95,8 @@ static const int currentVersion = 1; // GSNibItem version number...
NSString *key;
NSArray *visible;
NSMenu *menu;
NSMutableArray *topLevelObjects;
id obj;
_isAwake = YES;
/*
@ -162,7 +163,12 @@ static const int currentVersion = 1; // GSNibItem version number...
while ((key = [enumerator nextObject]) != nil)
{
if ([context objectForKey: key] == nil ||
[key isEqualToString: @"NSOwner"]) // we want to send the message to the owner
([key isEqualToString: @"NSOwner"] && // we want to send the message to the owner
[key isEqualToString: @"NSWindowsMenu"] == NO && // we don't want to send a message to these menus twice,
[key isEqualToString: @"NSServicesMenu"] == NO && // if they're custom classes.
[key isEqualToString: @"NSVisible"] == NO && // also exclude any other special parts of the nameTable.
[key isEqualToString: @"NSDeferred"] == NO &&
[key isEqualToString: @"NSTopLevelObjects"] == NO))
{
id o;
@ -173,6 +179,63 @@ static const int currentVersion = 1; // GSNibItem version number...
}
}
}
/*
* See if the user has passed in the NSTopLevelObjects key.
* This is an implementation of an undocumented, but commonly used feature
* of nib files to allow the release of the top level objects in the nib
* file.
*/
obj = [context objectForKey: @"NSTopLevelObjects"];
if([obj isKindOfClass: [NSMutableArray class]])
{
topLevelObjects = obj;
}
else
{
topLevelObjects = nil;
}
/*
* Retain all "top level" items so that, when the container is released, they will remain.
*/
enumerator = [nameTable keyEnumerator];
while ((key = [enumerator nextObject]) != nil)
{
if ([context objectForKey: key] == nil ||
([key isEqualToString: @"NSOwner"] == NO && // dont retain the owner.
[key isEqualToString: @"NSWindowsMenu"] == NO && // exclude special sections.
[key isEqualToString: @"NSServicesMenu"] == NO &&
[key isEqualToString: @"NSVisible"] == NO &&
[key isEqualToString: @"NSDeferred"] == NO &&
[key isEqualToString: @"NSTopLevelObjects"] == NO))
{
id o = [nameTable objectForKey: key];
// RETAIN all top-level items...
if (([o isKindOfClass: [NSMenu class]] == YES &&
[key isEqualToString: @"NSMenu"] == YES) || // the main menu...
([o isKindOfClass: [NSWindow class]] == YES) || // any windows...
([o isKindOfClass: [NSObject class]] == YES &&
[o isKindOfClass: [NSView class]] == NO)) // any objects which are not views..
{
if(topLevelObjects == nil)
{
// It is expected, if the NSTopLevelObjects key is not passed in,
// that the user has opted to either allow these objects to leak or
// to release them explicitly.
RETAIN(o);
}
else
{
// We don't want to do the extra retain if the items are added to the
// array, since the array will do the retain for us. When the array
// is released, the top level objects should be released as well.
[topLevelObjects addObject: o];
}
}
}
}
/*
* See if there are objects that should be made visible.

View file

@ -286,9 +286,6 @@ Class gmodel_class(void)
{
id obj;
// font fallback and automatic translation...
// [unarchiver decodeClassName: @"NSString" asClassName: @"GSStringProxy"];
NSDebugLog(@"Invoking unarchiver");
[unarchiver setObjectZone: zone];
obj = [unarchiver decodeObject];
@ -298,12 +295,6 @@ Class gmodel_class(void)
{
NSDebugLog(@"Calling awakeWithContext");
[obj awakeWithContext: context];
/*
*Ok - it's all done now - just retain the nib container
*so that it will not be released when the unarchiver
*is released, and the nib contents will persist.
*/
RETAIN(obj);
loaded = YES;
}
else