mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 16:10:48 +00:00
Temporary removal of NSNib pending bugfix. :)
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@18568 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
154110be23
commit
64ef0ab5fa
4 changed files with 150 additions and 49 deletions
|
@ -1,3 +1,9 @@
|
|||
2004-02-08 20:56 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* Source/GSNibTemplates.m: Backout of NSNib modification.
|
||||
* Source/NSBundleAdditions.m: ditto.
|
||||
* Source/NSNib.m: Commented out some code and private class.
|
||||
|
||||
2004-02-09 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSLayoutManager.m (-drawGlyphsForGlyphRange:atPoint:)
|
||||
|
|
|
@ -161,13 +161,13 @@ static const int currentVersion = 1; // GSNibItem version number...
|
|||
while ((key = [enumerator nextObject]) != nil)
|
||||
{
|
||||
if ([context objectForKey: key] == nil ||
|
||||
[key isEqualToString: @"NSNibOwner"]) // we want to send the message to the owner
|
||||
[key isEqualToString: @"NSOwner"]) // we want to send the message to the owner
|
||||
{
|
||||
if([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: @"NSNibTopLevelObjects"] == NO &&
|
||||
[key isEqualToString: @"NSTopLevelObjects"] == NO &&
|
||||
[key isEqualToString: @"GSCustomClassMap"] == NO)
|
||||
{
|
||||
id o = [nameTable objectForKey: key];
|
||||
|
@ -180,12 +180,12 @@ static const int currentVersion = 1; // GSNibItem version number...
|
|||
}
|
||||
|
||||
/*
|
||||
* See if the user has passed in the NSNibTopLevelObjects key.
|
||||
* 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: @"NSNibTopLevelObjects"];
|
||||
obj = [context objectForKey: @"NSTopLevelObjects"];
|
||||
if([obj isKindOfClass: [NSMutableArray class]])
|
||||
{
|
||||
topLevelObjects = obj;
|
||||
|
@ -208,7 +208,7 @@ static const int currentVersion = 1; // GSNibItem version number...
|
|||
[key isEqualToString: @"NSServicesMenu"] == NO &&
|
||||
[key isEqualToString: @"NSVisible"] == NO &&
|
||||
[key isEqualToString: @"NSDeferred"] == NO &&
|
||||
[key isEqualToString: @"NSNibTopLevelObjects"] == NO &&
|
||||
[key isEqualToString: @"NSTopLevelObjects"] == NO &&
|
||||
[key isEqualToString: @"GSCustomClassMap"] == NO)
|
||||
{
|
||||
id o = [nameTable objectForKey: key];
|
||||
|
@ -220,7 +220,7 @@ static const int currentVersion = 1; // GSNibItem version number...
|
|||
{
|
||||
if(topLevelObjects == nil)
|
||||
{
|
||||
// It is expected, if the NSNibTopLevelObjects key is not passed in,
|
||||
// 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);
|
||||
|
|
|
@ -45,10 +45,8 @@
|
|||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSKeyValueCoding.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSURL.h>
|
||||
#include "AppKit/NSNibConnector.h"
|
||||
#include "AppKit/NSNibLoading.h"
|
||||
#include "AppKit/NSNib.h"
|
||||
#include "GNUstepGUI/GSNibTemplates.h"
|
||||
#include "GNUstepGUI/IMLoading.h"
|
||||
|
||||
|
@ -187,11 +185,66 @@
|
|||
}
|
||||
@end
|
||||
|
||||
// declare this here to avoid a compiler warning...
|
||||
@interface NSNib (GNUstepPrivate)
|
||||
+ (NSString *) _nibFilename: (NSString *)fileName;
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
RELEASE(items);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSMutableArray *)items
|
||||
{
|
||||
return items;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSBundle (NSBundleAdditions)
|
||||
|
||||
static
|
||||
|
@ -230,15 +283,11 @@ Class gmodel_class(void)
|
|||
externalNameTable: (NSDictionary*)context
|
||||
withZone: (NSZone*)zone
|
||||
{
|
||||
NSString *ext = [fileName pathExtension];
|
||||
NSNib *nib = nil;
|
||||
BOOL result = NO;
|
||||
NSMutableDictionary *ctx = nil;
|
||||
BOOL loaded = NO;
|
||||
NSUnarchiver *unarchiver = nil;
|
||||
NSString *ext = [fileName pathExtension];
|
||||
id nibitems = nil;
|
||||
|
||||
/*
|
||||
* Determine if we're loading a .gorm or a .gmodel
|
||||
* if the extension is .nib.
|
||||
*/
|
||||
if ([ext isEqual: @"nib"])
|
||||
{
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
|
@ -264,42 +313,78 @@ Class gmodel_class(void)
|
|||
if ([ext isEqualToString: @"gmodel"])
|
||||
{
|
||||
return [gmodel_class() loadIMFile: fileName
|
||||
owner: [context objectForKey: @"NSOwner"]];
|
||||
owner: [context objectForKey: @"NSOwner"]];
|
||||
}
|
||||
|
||||
// Create a temporary context dictionary, containing all of the entries of the
|
||||
// one passed in, but replacing the NSOwner and NSTopLevelObjects entries with
|
||||
// the ones used by the NSNib class. We want *all* nib handling to happen in
|
||||
// one unified place within NSNib. GJC
|
||||
if(context != nil)
|
||||
|
||||
NSDebugLog(@"Loading Nib `%@'...\n", fileName);
|
||||
NS_DURING
|
||||
{
|
||||
id obj = nil;
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
BOOL isDir = NO;
|
||||
|
||||
ctx = [NSMutableDictionary dictionaryWithDictionary: context];
|
||||
|
||||
// remove and set the owner...
|
||||
obj = [ctx objectForKey: @"NSOwner"];
|
||||
if(obj != nil)
|
||||
if([mgr fileExistsAtPath: fileName isDirectory: &isDir])
|
||||
{
|
||||
[ctx removeObjectForKey: @"NSOwner"];
|
||||
[ctx setObject: obj forKey: @"NSNibOwner"];
|
||||
}
|
||||
NSData *data = nil;
|
||||
|
||||
// if the data is in a directory, then load from objects.gorm in the directory
|
||||
if(isDir == NO)
|
||||
{
|
||||
data = [NSData dataWithContentsOfFile: fileName];
|
||||
NSDebugLog(@"Loaded data from file...");
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *newFileName = [fileName stringByAppendingPathComponent: @"objects.gorm"];
|
||||
data = [NSData dataWithContentsOfFile: newFileName];
|
||||
NSDebugLog(@"Loaded data from %@...",newFileName);
|
||||
}
|
||||
|
||||
// Remove and set the top level objects...
|
||||
obj = [ctx objectForKey: @"NSTopLevelObjects"];
|
||||
if(obj != nil)
|
||||
{
|
||||
[ctx removeObjectForKey: @"NSTopLevelObjects"];
|
||||
[ctx setObject: obj forKey: @"NSNibTopLevelObjects"];
|
||||
if (data != nil)
|
||||
{
|
||||
unarchiver = [[NSUnarchiver alloc] initForReadingWithData: data];
|
||||
if (unarchiver != nil)
|
||||
{
|
||||
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: context
|
||||
topLevelItems: items];
|
||||
loaded = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Nib '%@' without container object!", fileName);
|
||||
}
|
||||
}
|
||||
RELEASE(nibitems);
|
||||
RELEASE(unarchiver);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"Exception occured while loading model: %@",[localException reason]);
|
||||
TEST_RELEASE(nibitems);
|
||||
TEST_RELEASE(unarchiver);
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
|
||||
// Load and instantiate the nib... release the NSNib object.
|
||||
nib = [[NSNib alloc] initWithContentsOfURL: [NSURL fileURLWithPath: [NSNib _nibFilename: fileName]]];
|
||||
result = [nib instantiateNibWithExternalNameTable: ctx withZone: zone];
|
||||
RELEASE(nib);
|
||||
|
||||
return result;
|
||||
if (loaded == NO)
|
||||
{
|
||||
NSLog(@"Failed to load Nib\n");
|
||||
}
|
||||
return loaded;
|
||||
}
|
||||
|
||||
+ (BOOL) loadNibNamed: (NSString *)aNibName
|
||||
|
@ -405,13 +490,17 @@ Class gmodel_class(void)
|
|||
withZone: (NSZone*)zone
|
||||
{
|
||||
NSString *path = [self pathForNibResource: fileName];
|
||||
if (fileName != nil)
|
||||
|
||||
if (path != nil)
|
||||
{
|
||||
return [NSBundle loadNibFile: path
|
||||
externalNameTable: context
|
||||
withZone: (NSZone*)zone];
|
||||
}
|
||||
return NO;
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
@end
|
||||
// end of NSBundleAdditions
|
||||
|
|
|
@ -69,6 +69,8 @@
|
|||
* retained or not since there are a lot of other things stored in the nameTable
|
||||
* as well. GJC
|
||||
*/
|
||||
|
||||
/*
|
||||
@interface _GSNibItemCollector : NSObject
|
||||
{
|
||||
NSMutableArray *items;
|
||||
|
@ -105,6 +107,7 @@
|
|||
return items;
|
||||
}
|
||||
@end
|
||||
*/
|
||||
|
||||
@implementation NSNib
|
||||
|
||||
|
@ -213,6 +216,7 @@
|
|||
- (BOOL)instantiateNibWithExternalNameTable: (NSDictionary *)externalNameTable
|
||||
withZone: (NSZone *)zone
|
||||
{
|
||||
/*
|
||||
BOOL loaded = NO;
|
||||
id nibitems = nil;
|
||||
NSUnarchiver *unarchiver = nil;
|
||||
|
@ -264,6 +268,8 @@
|
|||
}
|
||||
|
||||
return loaded;
|
||||
*/
|
||||
return NO;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue