Some slight improvements. Made templates use a method called shouldSwapClass which checks for the existence of isInInterfaceBuilder and, if available, returns the value.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19933 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
gcasa 2004-08-28 14:41:16 +00:00
parent b7b7df9a7c
commit d207aa1674
3 changed files with 37 additions and 12 deletions

View file

@ -1,3 +1,13 @@
2004-08-28 10:34 Gregory John Casamento <greg_casamento@yahoo.com>
* Source/GSNibTemplates.m: Added implementation of method
shouldSwapClass to GSClassSwapper. This method checks for the
implementation of isInInterfaceBuilder and returns whether or
not the template should perform the class swap or whether it
should retrieve the superclass.
* Headers/Additions/GNUstepGUI/GSNibTemplates.h: Added
declaration for -[GSClassSwapper shouldSwapClass].
2004-08-23 17:29 Alexander Malmberg <alexander@malmberg.org> 2004-08-23 17:29 Alexander Malmberg <alexander@malmberg.org>
* Source/NSWindow.m (-setFrameFromString:): Don't change the size * Source/NSWindow.m (-setFrameFromString:): Don't change the size

View file

@ -81,6 +81,7 @@
NSString *_className; NSString *_className;
Class _superClass; Class _superClass;
} }
- (BOOL) shouldSwapClass;
@end @end
@interface GSNibItem : NSObject <NSCoding> @interface GSNibItem : NSObject <NSCoding>

View file

@ -55,6 +55,10 @@
static const int currentVersion = 1; // GSNibItem version number... static const int currentVersion = 1; // GSNibItem version number...
@interface NSObject (GSNibPrivateMethods)
- (BOOL) isInInterfaceBuilder;
@end
@interface NSApplication (GSNibContainer) @interface NSApplication (GSNibContainer)
- (void)_deactivateVisibleWindow: (NSWindow *)win; - (void)_deactivateVisibleWindow: (NSWindow *)win;
@end @end
@ -643,11 +647,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN
// if we are living within the interface builder app, then don't try to // if we are living within the interface builder app, then don't try to
// morph into the subclass. // morph into the subclass.
if([self respondsToSelector: @selector(isInInterfaceBuilder)]) if([self shouldSwapClass])
{
obj = [_superClass alloc];
}
else
{ {
Class aClass = NSClassFromString(_className); Class aClass = NSClassFromString(_className);
if(aClass == 0) if(aClass == 0)
@ -660,6 +660,10 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN
// allow us to instantiate the class we want. // allow us to instantiate the class we want.
obj = [aClass alloc]; obj = [aClass alloc];
} }
else
{
obj = [_superClass alloc];
}
// inform the coder that this object is to replace the template in all cases. // inform the coder that this object is to replace the template in all cases.
[unarchiver replaceObject: self withObject: obj]; [unarchiver replaceObject: self withObject: obj];
@ -683,6 +687,16 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN
[_object encodeWithCoder: aCoder]; [_object encodeWithCoder: aCoder];
} }
} }
- (BOOL) shouldSwapClass
{
BOOL result = YES;
if([self respondsToSelector: @selector(isInInterfaceBuilder)])
{
result = !([self isInInterfaceBuilder]);
}
return result;
}
@end @end
@implementation GSWindowTemplate @implementation GSWindowTemplate
@ -715,7 +729,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN
// decode the defer flag... // decode the defer flag...
[coder decodeValueOfObjCType: @encode(BOOL) at: &_deferFlag]; [coder decodeValueOfObjCType: @encode(BOOL) at: &_deferFlag];
if(![self respondsToSelector: @selector(isInInterfaceBuilder)]) if([self shouldSwapClass])
{ {
if(GSGetMethod([obj class], @selector(initWithContentRect:styleMask:backing:defer:), YES, NO) != NULL) if(GSGetMethod([obj class], @selector(initWithContentRect:styleMask:backing:defer:), YES, NO) != NULL)
{ {
@ -757,7 +771,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN
id obj = [super initWithCoder: coder]; id obj = [super initWithCoder: coder];
if(obj != nil) if(obj != nil)
{ {
if(![self respondsToSelector: @selector(isInInterfaceBuilder)]) if([self shouldSwapClass])
{ {
if(GSGetMethod([obj class],@selector(initWithFrame:), YES, NO) != NULL) if(GSGetMethod([obj class],@selector(initWithFrame:), YES, NO) != NULL)
{ {
@ -786,7 +800,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN
id obj = [super initWithCoder: coder]; id obj = [super initWithCoder: coder];
if(obj != nil) if(obj != nil)
{ {
if(![self respondsToSelector: @selector(isInInterfaceBuilder)]) if([self shouldSwapClass])
{ {
if(GSGetMethod([obj class],@selector(initWithFrame:), YES, NO) != NULL) if(GSGetMethod([obj class],@selector(initWithFrame:), YES, NO) != NULL)
{ {
@ -815,7 +829,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN
id obj = [super initWithCoder: coder]; id obj = [super initWithCoder: coder];
if(obj != nil) if(obj != nil)
{ {
if(![self respondsToSelector: @selector(isInInterfaceBuilder)]) if([self shouldSwapClass])
{ {
if(GSGetMethod([obj class],@selector(initWithFrame:textContainer:), YES, NO) != NULL) if(GSGetMethod([obj class],@selector(initWithFrame:textContainer:), YES, NO) != NULL)
{ {
@ -846,7 +860,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN
id obj = [super initWithCoder: coder]; id obj = [super initWithCoder: coder];
if(obj != nil) if(obj != nil)
{ {
if(![self respondsToSelector: @selector(isInInterfaceBuilder)]) if([self shouldSwapClass])
{ {
if(GSGetMethod([obj class],@selector(initWithTitle:), YES, NO) != NULL) if(GSGetMethod([obj class],@selector(initWithTitle:), YES, NO) != NULL)
{ {
@ -877,7 +891,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN
if(obj != nil) if(obj != nil)
{ {
/* /*
if(![self respondsToSelector: @selector(isInInterfaceBuilder)]) if([self shouldSwapClass])
{ {
if(GSGetMethod([obj class],@selector(initWithFrame:), YES, NO) != NULL) if(GSGetMethod([obj class],@selector(initWithFrame:), YES, NO) != NULL)
{ {
@ -906,7 +920,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN
id obj = [super initWithCoder: coder]; id obj = [super initWithCoder: coder];
if(obj != nil) if(obj != nil)
{ {
if(![self respondsToSelector: @selector(isInInterfaceBuilder)]) if([self shouldSwapClass])
{ {
if(GSGetMethod([obj class],@selector(init), YES, NO) != NULL) if(GSGetMethod([obj class],@selector(init), YES, NO) != NULL)
{ {