2001-12-17 16:51:51 +00:00
|
|
|
/** <title>NSBundleAdditions</title>
|
1997-01-29 16:07:56 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
<abstract>Implementation of NSBundle Additions</abstract>
|
1997-01-29 16:07:56 +00:00
|
|
|
|
1999-01-15 10:14:28 +00:00
|
|
|
Copyright (C) 1997, 1999 Free Software Foundation, Inc.
|
1997-01-29 16:07:56 +00:00
|
|
|
|
|
|
|
Author: Simon Frankau <sgf@frankau.demon.co.uk>
|
|
|
|
Date: 1997
|
1999-01-15 10:14:28 +00:00
|
|
|
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
Date: 1999
|
2006-05-20 22:12:46 +00:00
|
|
|
Author: Gregory John Casamento <greg_casamento@yahoo.com>
|
|
|
|
Date: 2000
|
1997-01-29 16:07:56 +00:00
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-10-29 21:16:17 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1997-01-29 16:07:56 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-10 04:01:49 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2007-10-29 21:16:17 +00:00
|
|
|
|
1997-01-29 16:07:56 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-10-29 21:16:17 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
1997-01-29 16:07:56 +00:00
|
|
|
|
2007-10-29 21:16:17 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
|
|
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
1997-01-29 16:07:56 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-20 14:09:02 +00:00
|
|
|
#import "config.h"
|
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSBundle.h>
|
|
|
|
#import <Foundation/NSCoder.h>
|
2013-12-01 12:26:12 +00:00
|
|
|
#import <Foundation/NSDebug.h>
|
2010-03-20 14:09:02 +00:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
|
|
|
#import <Foundation/NSException.h>
|
|
|
|
#import <Foundation/NSString.h>
|
2010-03-22 09:08:50 +00:00
|
|
|
#import <Foundation/NSURL.h>
|
2010-03-20 14:09:02 +00:00
|
|
|
#import <Foundation/NSUserDefaults.h>
|
|
|
|
#import <Foundation/NSKeyValueCoding.h>
|
2010-03-22 09:08:50 +00:00
|
|
|
#import "AppKit/NSControl.h"
|
|
|
|
#import "AppKit/NSNib.h"
|
2010-03-20 14:09:02 +00:00
|
|
|
#import "AppKit/NSNibConnector.h"
|
|
|
|
#import "AppKit/NSNibLoading.h"
|
|
|
|
#import "GNUstepGUI/GSModelLoaderFactory.h"
|
1999-11-29 11:45:50 +00:00
|
|
|
|
|
|
|
@implementation NSNibConnector
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
RELEASE(_src);
|
|
|
|
RELEASE(_dst);
|
|
|
|
RELEASE(_tag);
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) destination
|
|
|
|
{
|
|
|
|
return _dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if ([aCoder allowsKeyedCoding])
|
|
|
|
{
|
2006-10-15 08:34:47 +00:00
|
|
|
if (_src != nil)
|
2006-10-07 14:03:50 +00:00
|
|
|
{
|
|
|
|
[aCoder encodeObject: _src forKey: @"NSSource"];
|
|
|
|
}
|
2006-10-15 08:34:47 +00:00
|
|
|
if (_dst != nil)
|
2006-10-07 14:03:50 +00:00
|
|
|
{
|
|
|
|
[aCoder encodeObject: _dst forKey: @"NSDestination"];
|
|
|
|
}
|
2006-10-15 08:34:47 +00:00
|
|
|
if (_tag != nil)
|
2006-10-07 14:03:50 +00:00
|
|
|
{
|
|
|
|
[aCoder encodeObject: _tag forKey: @"NSLabel"];
|
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[aCoder encodeObject: _src];
|
|
|
|
[aCoder encodeObject: _dst];
|
|
|
|
[aCoder encodeObject: _tag];
|
|
|
|
}
|
1999-11-29 11:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) establishConnection
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-02-08 20:33:07 +00:00
|
|
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
1999-11-29 11:45:50 +00:00
|
|
|
{
|
2004-02-08 20:33:07 +00:00
|
|
|
if ([aDecoder allowsKeyedCoding])
|
|
|
|
{
|
2006-10-15 08:34:47 +00:00
|
|
|
if ([aDecoder containsValueForKey: @"NSDestination"])
|
2006-10-07 14:03:50 +00:00
|
|
|
{
|
|
|
|
ASSIGN(_dst, [aDecoder decodeObjectForKey: @"NSDestination"]);
|
|
|
|
}
|
2006-10-15 08:34:47 +00:00
|
|
|
if ([aDecoder containsValueForKey: @"NSSource"])
|
2006-10-07 14:03:50 +00:00
|
|
|
{
|
|
|
|
ASSIGN(_src, [aDecoder decodeObjectForKey: @"NSSource"]);
|
|
|
|
}
|
2006-10-15 08:34:47 +00:00
|
|
|
if ([aDecoder containsValueForKey: @"NSLabel"])
|
2006-10-07 14:03:50 +00:00
|
|
|
{
|
|
|
|
ASSIGN(_tag, [aDecoder decodeObjectForKey: @"NSLabel"]);
|
|
|
|
}
|
2004-02-08 20:33:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_src];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_dst];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_tag];
|
|
|
|
}
|
1999-11-29 11:45:50 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) label
|
|
|
|
{
|
|
|
|
return _tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) replaceObject: (id)anObject withObject: (id)anotherObject
|
|
|
|
{
|
1999-12-03 14:51:56 +00:00
|
|
|
if (_src == anObject)
|
|
|
|
{
|
|
|
|
ASSIGN(_src, anotherObject);
|
|
|
|
}
|
|
|
|
if (_dst == anObject)
|
|
|
|
{
|
|
|
|
ASSIGN(_dst, anotherObject);
|
|
|
|
}
|
|
|
|
if (_tag == anObject)
|
|
|
|
{
|
|
|
|
ASSIGN(_tag, anotherObject);
|
|
|
|
}
|
1999-11-29 11:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) source
|
|
|
|
{
|
|
|
|
return _src;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setDestination: (id)anObject
|
|
|
|
{
|
|
|
|
ASSIGN(_dst, anObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setLabel: (NSString*)label
|
|
|
|
{
|
|
|
|
ASSIGN(_tag, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSource: (id)anObject
|
|
|
|
{
|
|
|
|
ASSIGN(_src, anObject);
|
|
|
|
}
|
|
|
|
|
2005-02-05 20:39:49 +00:00
|
|
|
- (NSString *)description
|
|
|
|
{
|
|
|
|
NSString *desc = [NSString stringWithFormat: @"<%@ src=%@ dst=%@ label=%@>",
|
|
|
|
[super description],
|
|
|
|
[self source],
|
|
|
|
[self destination],
|
|
|
|
[self label]];
|
|
|
|
return desc;
|
|
|
|
}
|
1999-11-29 11:45:50 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSNibControlConnector
|
|
|
|
- (void) establishConnection
|
|
|
|
{
|
2008-01-09 03:37:59 +00:00
|
|
|
SEL sel = NSSelectorFromString(_tag);
|
1999-11-29 11:45:50 +00:00
|
|
|
|
|
|
|
[_src setTarget: _dst];
|
|
|
|
[_src setAction: sel];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSNibOutletConnector
|
|
|
|
- (void) establishConnection
|
|
|
|
{
|
2009-02-11 05:43:06 +00:00
|
|
|
NS_DURING
|
2000-01-03 18:42:16 +00:00
|
|
|
{
|
2009-02-11 05:43:06 +00:00
|
|
|
if (_src != nil)
|
|
|
|
{
|
2010-03-13 13:15:47 +00:00
|
|
|
NSString *selName;
|
|
|
|
SEL sel;
|
|
|
|
|
|
|
|
selName = [NSString stringWithFormat: @"set%@%@:",
|
|
|
|
[[_tag substringToIndex: 1] uppercaseString],
|
|
|
|
[_tag substringFromIndex: 1]];
|
|
|
|
sel = NSSelectorFromString(selName);
|
|
|
|
|
|
|
|
if (sel && [_src respondsToSelector: sel])
|
|
|
|
{
|
|
|
|
[_src performSelector: sel withObject: _dst];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *nam = [_tag cString];
|
|
|
|
const char *type;
|
|
|
|
unsigned int size;
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use the GNUstep additional function to set the instance
|
|
|
|
* variable directly.
|
|
|
|
* FIXME - need some way to do this for libFoundation and
|
|
|
|
* Foundation based systems.
|
|
|
|
*/
|
|
|
|
if (GSObjCFindVariable(_src, nam, &type, &size, &offset))
|
|
|
|
{
|
|
|
|
GSObjCSetVariable(_src, offset, size, (void*)&_dst);
|
|
|
|
}
|
|
|
|
}
|
2009-02-11 05:43:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
|
|
|
NSLog(@"Error while establishing connection %@: %@",self,[localException reason]);
|
1999-11-29 11:45:50 +00:00
|
|
|
}
|
2009-02-11 05:43:06 +00:00
|
|
|
NS_ENDHANDLER;
|
1999-11-29 11:45:50 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
1997-01-29 16:07:56 +00:00
|
|
|
@implementation NSBundle (NSBundleAdditions)
|
2002-02-11 16:29:15 +00:00
|
|
|
+ (BOOL) loadNibFile: (NSString*)fileName
|
|
|
|
externalNameTable: (NSDictionary*)context
|
|
|
|
withZone: (NSZone*)zone
|
1997-01-29 16:07:56 +00:00
|
|
|
{
|
2010-03-22 09:08:50 +00:00
|
|
|
NSNib *nib = [[NSNib alloc] initWithContentsOfURL: [NSURL fileURLWithPath: fileName]];
|
|
|
|
BOOL loaded = [nib instantiateNibWithExternalNameTable: context
|
|
|
|
withZone: zone];
|
|
|
|
|
|
|
|
RELEASE(nib);
|
2004-02-09 01:50:45 +00:00
|
|
|
return loaded;
|
1997-01-29 16:07:56 +00:00
|
|
|
}
|
|
|
|
|
1999-01-15 10:14:28 +00:00
|
|
|
+ (BOOL) loadNibNamed: (NSString *)aNibName
|
|
|
|
owner: (id)owner
|
1997-01-29 16:07:56 +00:00
|
|
|
{
|
1999-01-15 10:14:28 +00:00
|
|
|
NSDictionary *table;
|
|
|
|
NSBundle *bundle;
|
|
|
|
|
|
|
|
if (owner == nil || aNibName == nil)
|
2002-02-11 16:29:15 +00:00
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
2010-03-28 21:33:08 +00:00
|
|
|
table = [NSDictionary dictionaryWithObject: owner forKey: NSNibOwner];
|
2006-05-11 11:27:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First look for the NIB in the bundle corresponding to the owning class,
|
|
|
|
* since the class may have been loaded dynamically and the bundle may
|
|
|
|
* contain class-specific NIB resources as well as code.
|
|
|
|
* If that fails, try to load the NIB from the main application bundle,
|
|
|
|
* which is where most NIB resources are to be found.
|
|
|
|
* Possibly this is the wrong order ... since it's conceivable that an
|
|
|
|
* application may supply an alternative NIB which it would like to have
|
|
|
|
* used in preference to the one in the classes bundle. However I could
|
|
|
|
* not find the behavior documented anywhere and the current order is
|
|
|
|
* most consistent with the the way the code behaved before I changed it.
|
|
|
|
*/
|
1999-11-29 11:45:50 +00:00
|
|
|
bundle = [self bundleForClass: [owner class]];
|
2006-05-10 13:06:57 +00:00
|
|
|
if (bundle != nil && [bundle loadNibFile: aNibName
|
|
|
|
externalNameTable: table
|
|
|
|
withZone: [owner zone]] == YES)
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
else
|
1999-01-15 10:14:28 +00:00
|
|
|
{
|
1999-11-29 11:45:50 +00:00
|
|
|
bundle = [self mainBundle];
|
1999-01-15 10:14:28 +00:00
|
|
|
}
|
1999-11-29 11:45:50 +00:00
|
|
|
return [bundle loadNibFile: aNibName
|
|
|
|
externalNameTable: table
|
|
|
|
withZone: [owner zone]];
|
1997-01-29 16:07:56 +00:00
|
|
|
}
|
|
|
|
|
2001-11-26 20:28:34 +00:00
|
|
|
- (NSString *) pathForNibResource: (NSString *)fileName
|
1999-11-29 11:45:50 +00:00
|
|
|
{
|
2013-12-01 12:26:12 +00:00
|
|
|
NSEnumerator *enumerator;
|
|
|
|
NSArray *types = [GSModelLoaderFactory supportedTypes];
|
|
|
|
NSString *ext = [fileName pathExtension];
|
1999-11-29 11:45:50 +00:00
|
|
|
|
2013-12-01 12:26:12 +00:00
|
|
|
NSDebugLLog(@"NIB", @"Path for NIB file %@", fileName);
|
|
|
|
if ((ext == nil) || [ext isEqualToString:@""])
|
1999-11-29 11:45:50 +00:00
|
|
|
{
|
2013-12-01 12:26:12 +00:00
|
|
|
NSString *type;
|
|
|
|
|
|
|
|
enumerator = [types objectEnumerator];
|
|
|
|
while ((type = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
NSDebugLLog(@"NIB", @"Checking type %@", fileName);
|
|
|
|
NSString *path = [self pathForResource: fileName
|
|
|
|
ofType: type];
|
|
|
|
if (path != nil)
|
|
|
|
{
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
}
|
1999-11-29 11:45:50 +00:00
|
|
|
}
|
2013-12-01 12:26:12 +00:00
|
|
|
else
|
1999-11-29 11:45:50 +00:00
|
|
|
{
|
2013-12-01 12:26:12 +00:00
|
|
|
if ([types containsObject: ext])
|
|
|
|
{
|
|
|
|
NSString *path = [self pathForResource:
|
|
|
|
[fileName stringByDeletingPathExtension]
|
|
|
|
ofType: ext];
|
|
|
|
if (path != nil)
|
|
|
|
{
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
}
|
1999-11-29 11:45:50 +00:00
|
|
|
}
|
2000-07-30 08:20:51 +00:00
|
|
|
|
2013-12-01 12:26:12 +00:00
|
|
|
NSDebugLLog(@"NIB", @"Did not find NIB resource %@", fileName);
|
2001-11-26 20:28:34 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) loadNibFile: (NSString*)fileName
|
|
|
|
externalNameTable: (NSDictionary*)context
|
|
|
|
withZone: (NSZone*)zone
|
|
|
|
{
|
|
|
|
NSString *path = [self pathForNibResource: fileName];
|
2004-02-09 01:50:45 +00:00
|
|
|
|
|
|
|
if (path != nil)
|
2002-02-11 16:29:15 +00:00
|
|
|
{
|
|
|
|
return [NSBundle loadNibFile: path
|
|
|
|
externalNameTable: context
|
|
|
|
withZone: (NSZone*)zone];
|
|
|
|
}
|
2004-02-09 01:50:45 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
1999-11-29 11:45:50 +00:00
|
|
|
}
|
1997-01-29 16:07:56 +00:00
|
|
|
@end
|
2003-08-23 01:03:40 +00:00
|
|
|
// end of NSBundleAdditions
|