* Source/GSNibCompatibility.m: Further improvements to nib loading

logic.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27115 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
gcasa 2008-11-23 01:41:04 +00:00
parent 00d73826fd
commit 2adf17b4ef
2 changed files with 78 additions and 83 deletions

View file

@ -1,3 +1,8 @@
2008-11-22 20:46-EST Gregory John Casamento <greg_casamento@yahoo.com>
* Source/GSNibCompatibility.m: Further improvements to nib loading
logic.
2008-11-21 23:12-EST Gregory John Casamento <greg_casamento@yahoo.com> 2008-11-21 23:12-EST Gregory John Casamento <greg_casamento@yahoo.com>
* Source/GSNibCompatibility.m: Remove calls to designated initializers * Source/GSNibCompatibility.m: Remove calls to designated initializers

View file

@ -611,6 +611,28 @@ static BOOL _isInInterfaceBuilder = NO;
{ {
ASSIGN(_className, [coder decodeObjectForKey: @"NSClassName"]); ASSIGN(_className, [coder decodeObjectForKey: @"NSClassName"]);
ASSIGN(_extension, [coder decodeObjectForKey: @"NSExtension"]); ASSIGN(_extension, [coder decodeObjectForKey: @"NSExtension"]);
if (_object == nil)
{
Class aClass;
if ([NSClassSwapper isInInterfaceBuilder])
{
aClass = [self class];
}
else
{
aClass = NSClassFromString(_className);
}
if (aClass == nil)
{
[NSException raise: NSInternalInconsistencyException
format: @"Unable to find class '%@'", _className];
}
_object = [[aClass allocWithZone: NSDefaultMallocZone()] init];
}
} }
else else
{ {
@ -618,7 +640,8 @@ static BOOL _isInInterfaceBuilder = NO;
format: @"Can't decode %@ with %@.",NSStringFromClass([self class]), format: @"Can't decode %@ with %@.",NSStringFromClass([self class]),
NSStringFromClass([coder class])]; NSStringFromClass([coder class])];
} }
return self;
return _object;
} }
- (void) encodeWithCoder: (NSCoder *)coder - (void) encodeWithCoder: (NSCoder *)coder
@ -639,27 +662,6 @@ static BOOL _isInInterfaceBuilder = NO;
- (id) nibInstantiate - (id) nibInstantiate
{ {
if (_object == nil)
{
Class aClass;
if ([NSClassSwapper isInInterfaceBuilder])
{
aClass = [self class];
}
else
{
aClass = NSClassFromString(_className);
}
if (aClass == nil)
{
[NSException raise: NSInternalInconsistencyException
format: @"Unable to find class '%@'", _className];
}
_object = [[aClass allocWithZone: NSDefaultMallocZone()] init];
}
return _object; return _object;
} }
@ -701,6 +703,27 @@ static BOOL _isInInterfaceBuilder = NO;
- (id) nibInstantiate - (id) nibInstantiate
{ {
return _view;
}
- (id) initWithCoder: (NSCoder *)coder
{
self = [super initWithCoder: coder];
if (self != nil)
{
if ([coder allowsKeyedCoding])
{
ASSIGN(_className, [coder decodeObjectForKey: @"NSClassName"]);
ASSIGN(_extension, [coder decodeObjectForKey: @"NSExtension"]);
}
else
{
[NSException raise: NSInvalidArgumentException
format: @"Can't decode %@ with %@.",NSStringFromClass([self class]),
NSStringFromClass([coder class])];
}
}
if (_view == nil) if (_view == nil)
{ {
Class aClass; Class aClass;
@ -744,26 +767,6 @@ static BOOL _isInInterfaceBuilder = NO;
return _view; return _view;
} }
- (id) initWithCoder: (NSCoder *)coder
{
self = [super initWithCoder: coder];
if (self != nil)
{
if ([coder allowsKeyedCoding])
{
ASSIGN(_className, [coder decodeObjectForKey: @"NSClassName"]);
ASSIGN(_extension, [coder decodeObjectForKey: @"NSExtension"]);
}
else
{
[NSException raise: NSInvalidArgumentException
format: @"Can't decode %@ with %@.",NSStringFromClass([self class]),
NSStringFromClass([coder class])];
}
}
return self;
}
- (void) encodeWithCoder: (NSCoder *)coder - (void) encodeWithCoder: (NSCoder *)coder
{ {
[super encodeWithCoder: coder]; [super encodeWithCoder: coder];
@ -941,9 +944,6 @@ static BOOL _isInInterfaceBuilder = NO;
{ {
Class aClass = nil; Class aClass = nil;
id object = nil; id object = nil;
Class newCellClass = nil;
NSString *origCellClassName = nil;
Class origCellClass = nil;
// if there is a replacement class, use it, otherwise, use the one specified. // if there is a replacement class, use it, otherwise, use the one specified.
if ((aClass = [(NSKeyedUnarchiver *)coder classForClassName: className]) == nil) if ((aClass = [(NSKeyedUnarchiver *)coder classForClassName: className]) == nil)
@ -957,19 +957,6 @@ static BOOL _isInInterfaceBuilder = NO;
format: @"NSClassSwapper unable to find class '%@'", className]; format: @"NSClassSwapper unable to find class '%@'", className];
} }
// if this is a class which uses cells, override with the new cellClass, if the
// subclass responds to cellClass.
if ([aClass respondsToSelector: @selector(cellClass)] &&
[className isEqualToString: _originalClassName] == NO)
{
Class origClass = NSClassFromString(_originalClassName);
origCellClass = [origClass cellClass];
newCellClass = [aClass cellClass];
origCellClassName = NSStringFromClass(origCellClass);
[(NSKeyedUnarchiver *)coder setClass: newCellClass forClassName: origCellClassName];
}
// swap the class... // swap the class...
object = [aClass allocWithZone: NSDefaultMallocZone()]; object = [aClass allocWithZone: NSDefaultMallocZone()];
[(NSKeyedUnarchiver *)coder replaceObject: self withObject: object]; [(NSKeyedUnarchiver *)coder replaceObject: self withObject: object];
@ -979,9 +966,12 @@ static BOOL _isInInterfaceBuilder = NO;
[(NSKeyedUnarchiver *)coder replaceObject: object withObject: _template]; [(NSKeyedUnarchiver *)coder replaceObject: object withObject: _template];
} }
if (newCellClass != nil && origCellClass != nil) if([aClass respondsToSelector: @selector(cellClass)] &&
[className isEqualToString: _originalClassName] == NO)
{ {
[(NSKeyedUnarchiver *)coder setClass: origCellClass forClassName: nil]; id oldCell = [_template cell];
id newCell = [[[aClass cellClass] alloc] init];
[_template setCell: newCell];
} }
} }
@ -994,13 +984,13 @@ static BOOL _isInInterfaceBuilder = NO;
// build the real object... // build the real object...
if ([NSClassSwapper isInInterfaceBuilder] == YES) if ([NSClassSwapper isInInterfaceBuilder] == YES)
{ {
[self instantiateRealObject: coder withClassName: _originalClassName]; [self instantiateRealObject: coder withClassName: _originalClassName];
} }
else else
{ {
[self instantiateRealObject: coder withClassName: _className]; [self instantiateRealObject: coder withClassName: _className];
} }
} }
else else
{ {