mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 14:30:38 +00:00
Get the class NSNib to work and use it in NSBundleAdditions.
Restructure top level object handling for NIB loading. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@30018 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ec2ea1114d
commit
444b0fc6db
9 changed files with 122 additions and 126 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
2010-03-22 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Headers/Additions/GNUstepGUI/GSModelLoaderFactory.h,
|
||||
* Source/GSModelLoaderFactory.m,
|
||||
* Source/GSGormLoader.m,
|
||||
* Source/GSXibLoader.m,
|
||||
* Source/GSNibLoader.m: New method dataForFile: on GSModelLoader
|
||||
and its subclasses.
|
||||
* Source/NSNib.m: Use this new method to load NIB files.
|
||||
* Source/NSBundleAdditions.m: Use NSNib for NIB loading.
|
||||
* Source/GSNibLoading.m: Correctly handle top level objects and
|
||||
clean up dealloc for most classes here.
|
||||
|
||||
2010-03-22 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSDocument.m (-close): Retain and autorelease self before
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
- (BOOL) loadModelFile: (NSString *)fileName
|
||||
externalNameTable: (NSDictionary *)context
|
||||
withZone: (NSZone *)zone;
|
||||
- (NSData *)dataForFile: (NSString *)fileName;
|
||||
@end
|
||||
|
||||
@interface GSModelLoaderFactory : NSObject
|
||||
|
|
|
@ -26,11 +26,18 @@
|
|||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <AppKit/AppKit.h>
|
||||
#import "config.h"
|
||||
#import <Foundation/NSArchiver.h>
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSData.h>
|
||||
#import <Foundation/NSDebug.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSException.h>
|
||||
#import <Foundation/NSFileManager.h>
|
||||
#import <Foundation/NSString.h>
|
||||
|
||||
#include "GNUstepGUI/GSModelLoaderFactory.h"
|
||||
#include "GNUstepGUI/GSGormLoading.h"
|
||||
#import "GNUstepGUI/GSModelLoaderFactory.h"
|
||||
#import "GNUstepGUI/GSGormLoading.h"
|
||||
|
||||
@interface GSGormLoader : GSModelLoader
|
||||
@end
|
||||
|
@ -104,19 +111,15 @@
|
|||
return loaded;
|
||||
}
|
||||
|
||||
- (BOOL) loadModelFile: (NSString *)fileName
|
||||
externalNameTable: (NSDictionary *)context
|
||||
withZone: (NSZone *)zone;
|
||||
- (NSData *) dataForFile: (NSString *)fileName
|
||||
{
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
BOOL isDir = NO;
|
||||
BOOL loaded = NO;
|
||||
BOOL isDir = NO;
|
||||
|
||||
NSDebugLog(@"Loading Gorm `%@'...\n", fileName);
|
||||
|
||||
if ([mgr fileExistsAtPath: fileName isDirectory: &isDir])
|
||||
{
|
||||
NSData *data = nil;
|
||||
NSData *data = nil;
|
||||
|
||||
// if the data is in a directory, then load from objects.gorm in the directory
|
||||
if (isDir == NO)
|
||||
|
@ -130,18 +133,13 @@
|
|||
data = [NSData dataWithContentsOfFile: newFileName];
|
||||
NSDebugLog(@"Loaded data from %@...",newFileName);
|
||||
}
|
||||
|
||||
loaded = [self loadModelData: data
|
||||
externalNameTable: context
|
||||
withZone: zone];
|
||||
|
||||
// report a problem if there is one.
|
||||
if (loaded == NO)
|
||||
{
|
||||
NSLog(@"Could not load Gorm file: %@",fileName);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
return loaded;
|
||||
else
|
||||
{
|
||||
NSLog(@"Gorm file specified %@, could not be found.", fileName);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#import "config.h"
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSData.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSEnumerator.h>
|
||||
#import <Foundation/NSException.h>
|
||||
|
@ -60,9 +61,26 @@
|
|||
externalNameTable: (NSDictionary *)context
|
||||
withZone: (NSZone *)zone
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Abstract model loader."];
|
||||
return NO;
|
||||
NSData *data = [self dataForFile: fileName];
|
||||
|
||||
if (data != nil)
|
||||
{
|
||||
BOOL loaded = [self loadModelData: data
|
||||
externalNameTable: context
|
||||
withZone: zone];
|
||||
if (!loaded)
|
||||
NSLog(@"Could not load Nib file: %@", fileName);
|
||||
return loaded;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSData *) dataForFile: (NSString *)fileName
|
||||
{
|
||||
return [NSData dataWithContentsOfFile: fileName];
|
||||
}
|
||||
|
||||
+ (NSComparisonResult) _comparePriority: (Class)loader
|
||||
|
|
|
@ -124,19 +124,15 @@
|
|||
return loaded;
|
||||
}
|
||||
|
||||
- (BOOL) loadModelFile: (NSString *)fileName
|
||||
externalNameTable: (NSDictionary *)context
|
||||
withZone: (NSZone *)zone;
|
||||
- (NSData *) dataForFile: (NSString *)fileName
|
||||
{
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
BOOL isDir = NO;
|
||||
BOOL loaded = NO;
|
||||
BOOL isDir = NO;
|
||||
|
||||
NSDebugLog(@"Loading Nib `%@'...\n", fileName);
|
||||
|
||||
if ([mgr fileExistsAtPath: fileName isDirectory: &isDir])
|
||||
{
|
||||
NSData *data = nil;
|
||||
NSData *data = nil;
|
||||
|
||||
// if the data is in a directory, then load from keyedobjects.nib in the directory
|
||||
if (isDir == NO)
|
||||
|
@ -148,24 +144,14 @@
|
|||
{
|
||||
NSString *newFileName = [fileName stringByAppendingPathComponent: @"keyedobjects.nib"];
|
||||
data = [NSData dataWithContentsOfFile: newFileName];
|
||||
NSDebugLog(@"Loaded data from %@...",newFileName);
|
||||
}
|
||||
|
||||
loaded = [self loadModelData: data
|
||||
externalNameTable: context
|
||||
withZone: zone];
|
||||
|
||||
// report a problem if there is one.
|
||||
if (loaded == NO)
|
||||
{
|
||||
NSLog(@"Could not load Nib file: %@",fileName);
|
||||
NSDebugLog(@"Loaded data from %@...", newFileName);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Nib file specified %@, could not be found.",fileName);
|
||||
NSLog(@"NIB file specified %@, could not be found.", fileName);
|
||||
}
|
||||
|
||||
return loaded;
|
||||
return nil;
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
Author: Gregory John Casamento
|
||||
Date: 2003, 2005
|
||||
Author: Fred Kiefer
|
||||
Date: 2003, 2010
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -286,6 +288,7 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
RELEASE(_windowClass);
|
||||
RELEASE(_view);
|
||||
RELEASE(_autosaveName);
|
||||
RELEASE(_realObject);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -701,6 +704,13 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_className);
|
||||
RELEASE(_realObject);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
/**
|
||||
* Designated initializer for NSViewTemplate.
|
||||
*/
|
||||
|
@ -837,6 +847,13 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_menuClass);
|
||||
RELEASE(_realObject);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
RELEASE(self);
|
||||
|
@ -988,6 +1005,7 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
{
|
||||
RELEASE(_className);
|
||||
RELEASE(_extension);
|
||||
RELEASE(_object);
|
||||
[super dealloc];
|
||||
}
|
||||
@end
|
||||
|
@ -1858,15 +1876,16 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
*/
|
||||
- (void) nibInstantiateWithOwner: (id)owner topLevelObjects: (NSMutableArray *)topLevelObjects
|
||||
{
|
||||
NSEnumerator *en = [_connections objectEnumerator];
|
||||
NSArray *objs = NSAllMapTableKeys([self names]);
|
||||
NSEnumerator *en;
|
||||
NSArray *objs;
|
||||
id obj = nil;
|
||||
id menu = nil;
|
||||
|
||||
|
||||
// set the new root object.
|
||||
[_root setRealObject: owner];
|
||||
|
||||
// iterate over connections, instantiate, and then establish them.
|
||||
// iterate over connections, instantiate and then establish them.
|
||||
en = [_connections objectEnumerator];
|
||||
while ((obj = [en nextObject]) != nil)
|
||||
{
|
||||
if ([obj respondsToSelector: @selector(instantiateWithInstantiator:)])
|
||||
|
@ -1876,24 +1895,23 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
}
|
||||
}
|
||||
|
||||
// iterate over all objects instantiate windows, awaken objects and fill
|
||||
// iterate over all objects, instantiate, awaken objects and fill
|
||||
// in top level array.
|
||||
objs = NSAllMapTableKeys(_objects);
|
||||
en = [objs objectEnumerator];
|
||||
while ((obj = [en nextObject]) != nil)
|
||||
{
|
||||
// instantiate all windows and fill in the top level array.
|
||||
if ([obj isKindOfClass: [NSWindowTemplate class]])
|
||||
id v = NSMapGet(_objects, obj);
|
||||
obj = [self instantiateObject: obj];
|
||||
// Object is top level if it isn't the owner but points to it.
|
||||
if ((v == owner || v == _root) && (obj != owner) && (obj != _root))
|
||||
{
|
||||
if ([obj realObject] == nil)
|
||||
if (topLevelObjects == nil)
|
||||
{
|
||||
obj = [self instantiateObject: obj];
|
||||
[topLevelObjects addObject: obj];
|
||||
// When there is no top level object array, just retain these objects
|
||||
RETAIN(obj);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
id v = NSMapGet(_objects, obj);
|
||||
if (v == nil || v == owner)
|
||||
else
|
||||
{
|
||||
[topLevelObjects addObject: obj];
|
||||
}
|
||||
|
|
|
@ -693,41 +693,28 @@
|
|||
return loaded;
|
||||
}
|
||||
|
||||
- (BOOL) loadModelFile: (NSString *)fileName
|
||||
externalNameTable: (NSDictionary *)context
|
||||
withZone: (NSZone *)zone;
|
||||
- (NSData *) dataForFile: (NSString *)fileName
|
||||
{
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
BOOL isDir = NO;
|
||||
BOOL loaded = NO;
|
||||
|
||||
NSDebugLog(@"Loading Xib `%@'...\n", fileName);
|
||||
|
||||
if ([mgr fileExistsAtPath: fileName isDirectory: &isDir])
|
||||
{
|
||||
NSData *data = nil;
|
||||
|
||||
if (isDir == NO)
|
||||
{
|
||||
data = [NSData dataWithContentsOfFile: fileName];
|
||||
NSDebugLog(@"Loaded data from file...");
|
||||
loaded = [self loadModelData: data
|
||||
externalNameTable: context
|
||||
withZone: zone];
|
||||
}
|
||||
|
||||
// report a problem if there is one.
|
||||
if (loaded == NO)
|
||||
{
|
||||
NSLog(@"Could not load Xib file: %@",fileName);
|
||||
}
|
||||
return [NSData dataWithContentsOfFile: fileName];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Xib file specified %@, is directory.", fileName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Xib file specified %@, could not be found.",fileName);
|
||||
NSLog(@"Xib file specified %@, could not be found.", fileName);
|
||||
}
|
||||
|
||||
return loaded;
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -38,9 +38,11 @@
|
|||
#import <Foundation/NSEnumerator.h>
|
||||
#import <Foundation/NSException.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSURL.h>
|
||||
#import <Foundation/NSUserDefaults.h>
|
||||
#import <Foundation/NSKeyValueCoding.h>
|
||||
#import <AppKit/NSControl.h>
|
||||
#import "AppKit/NSControl.h"
|
||||
#import "AppKit/NSNib.h"
|
||||
#import "AppKit/NSNibConnector.h"
|
||||
#import "AppKit/NSNibLoading.h"
|
||||
#import "GNUstepGUI/GSModelLoaderFactory.h"
|
||||
|
@ -229,10 +231,11 @@
|
|||
externalNameTable: (NSDictionary*)context
|
||||
withZone: (NSZone*)zone
|
||||
{
|
||||
GSModelLoader *loader = [GSModelLoaderFactory modelLoaderForFileName: fileName];
|
||||
BOOL loaded = [loader loadModelFile: fileName
|
||||
externalNameTable: context
|
||||
withZone: zone];
|
||||
NSNib *nib = [[NSNib alloc] initWithContentsOfURL: [NSURL fileURLWithPath: fileName]];
|
||||
BOOL loaded = [nib instantiateNibWithExternalNameTable: context
|
||||
withZone: zone];
|
||||
|
||||
RELEASE(nib);
|
||||
return loaded;
|
||||
}
|
||||
|
||||
|
@ -246,7 +249,7 @@
|
|||
{
|
||||
return NO;
|
||||
}
|
||||
table = [NSDictionary dictionaryWithObject: owner forKey: @"NSOwner"];
|
||||
table = [NSDictionary dictionaryWithObject: owner forKey: @"NSNibOwner"];
|
||||
|
||||
/*
|
||||
* First look for the NIB in the bundle corresponding to the owning class,
|
||||
|
|
|
@ -52,8 +52,6 @@
|
|||
#import "AppKit/NSNib.h"
|
||||
#import "AppKit/NSNibLoading.h"
|
||||
#import "GNUstepGUI/GSModelLoaderFactory.h"
|
||||
#import "GNUstepGUI/GSGormLoading.h"
|
||||
#import "GNUstepGUI/IMLoading.h"
|
||||
|
||||
@implementation NSNib
|
||||
|
||||
|
@ -64,8 +62,8 @@
|
|||
NS_DURING
|
||||
{
|
||||
NSString *newFileName = [GSModelLoaderFactory supportedModelFileAtPath: fileName];
|
||||
ASSIGN(_nibData, [NSData dataWithContentsOfFile: newFileName]);
|
||||
ASSIGN(_loader, [GSModelLoaderFactory modelLoaderForFileType: [newFileName pathExtension]]);
|
||||
ASSIGN(_nibData, [_loader dataForFile: newFileName]);
|
||||
NSDebugLog(@"Loaded data from %@...", newFileName);
|
||||
}
|
||||
NS_HANDLER
|
||||
|
@ -75,37 +73,6 @@
|
|||
NS_ENDHANDLER
|
||||
}
|
||||
|
||||
- (NSDictionary *) _copyTable: (NSDictionary *)dict
|
||||
{
|
||||
NSMutableDictionary *ctx = nil;
|
||||
|
||||
if (dict != nil)
|
||||
{
|
||||
id obj = nil;
|
||||
|
||||
// copy the dictionary...
|
||||
ctx = [NSMutableDictionary dictionaryWithDictionary: dict];
|
||||
|
||||
// remove and set the owner...
|
||||
obj = [ctx objectForKey: @"NSNibOwner"];
|
||||
if (obj != nil)
|
||||
{
|
||||
[ctx removeObjectForKey: @"NSNibOwner"];
|
||||
[ctx setObject: obj forKey: @"NSOwner"];
|
||||
}
|
||||
|
||||
// Remove and set the top level objects...
|
||||
obj = [ctx objectForKey: @"NSNibTopLevelObjects"];
|
||||
if (obj != nil)
|
||||
{
|
||||
[ctx removeObjectForKey: @"NSNibTopLevelObjects"];
|
||||
[ctx setObject: obj forKey: @"NSTopLevelObjects"];
|
||||
}
|
||||
}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
// Public methods...
|
||||
|
||||
/**
|
||||
|
@ -127,10 +94,10 @@
|
|||
{
|
||||
NS_DURING
|
||||
{
|
||||
// load the nib data into memory...
|
||||
_nibData = [NSData dataWithContentsOfURL: nibFileURL];
|
||||
ASSIGN(_loader, [GSModelLoaderFactory modelLoaderForFileType:
|
||||
[[nibFileURL path] pathExtension]]);
|
||||
// load the nib data into memory...
|
||||
_nibData = [NSData dataWithContentsOfURL: nibFileURL];
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
|
@ -163,6 +130,11 @@
|
|||
|
||||
// initialize the bundle...
|
||||
fileName = [bundle pathForNibResource: nibNamed];
|
||||
if (fileName == nil)
|
||||
{
|
||||
DESTROY(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
// load the nib data into memory...
|
||||
[self _readNibData: fileName];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue