From d207aa16742c8bb3903aff326c083e7586f501ee Mon Sep 17 00:00:00 2001 From: gcasa Date: Sat, 28 Aug 2004 14:41:16 +0000 Subject: [PATCH] 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 --- ChangeLog | 10 +++++ Headers/Additions/GNUstepGUI/GSNibTemplates.h | 1 + Source/GSNibTemplates.m | 38 +++++++++++++------ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9056ffe87..4a036b7d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-08-28 10:34 Gregory John Casamento + + * 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 * Source/NSWindow.m (-setFrameFromString:): Don't change the size diff --git a/Headers/Additions/GNUstepGUI/GSNibTemplates.h b/Headers/Additions/GNUstepGUI/GSNibTemplates.h index f563b948a..8a88079b8 100644 --- a/Headers/Additions/GNUstepGUI/GSNibTemplates.h +++ b/Headers/Additions/GNUstepGUI/GSNibTemplates.h @@ -81,6 +81,7 @@ NSString *_className; Class _superClass; } +- (BOOL) shouldSwapClass; @end @interface GSNibItem : NSObject diff --git a/Source/GSNibTemplates.m b/Source/GSNibTemplates.m index f48227def..0601fe6b2 100644 --- a/Source/GSNibTemplates.m +++ b/Source/GSNibTemplates.m @@ -55,6 +55,10 @@ static const int currentVersion = 1; // GSNibItem version number... +@interface NSObject (GSNibPrivateMethods) +- (BOOL) isInInterfaceBuilder; +@end + @interface NSApplication (GSNibContainer) - (void)_deactivateVisibleWindow: (NSWindow *)win; @end @@ -643,11 +647,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN // if we are living within the interface builder app, then don't try to // morph into the subclass. - if([self respondsToSelector: @selector(isInInterfaceBuilder)]) - { - obj = [_superClass alloc]; - } - else + if([self shouldSwapClass]) { Class aClass = NSClassFromString(_className); if(aClass == 0) @@ -660,6 +660,10 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN // allow us to instantiate the class we want. obj = [aClass alloc]; } + else + { + obj = [_superClass alloc]; + } // inform the coder that this object is to replace the template in all cases. [unarchiver replaceObject: self withObject: obj]; @@ -683,6 +687,16 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN [_object encodeWithCoder: aCoder]; } } + +- (BOOL) shouldSwapClass +{ + BOOL result = YES; + if([self respondsToSelector: @selector(isInInterfaceBuilder)]) + { + result = !([self isInInterfaceBuilder]); + } + return result; +} @end @implementation GSWindowTemplate @@ -715,7 +729,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN // decode the defer flag... [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) { @@ -757,7 +771,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN id obj = [super initWithCoder: coder]; if(obj != nil) { - if(![self respondsToSelector: @selector(isInInterfaceBuilder)]) + if([self shouldSwapClass]) { if(GSGetMethod([obj class],@selector(initWithFrame:), YES, NO) != NULL) { @@ -786,7 +800,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN id obj = [super initWithCoder: coder]; if(obj != nil) { - if(![self respondsToSelector: @selector(isInInterfaceBuilder)]) + if([self shouldSwapClass]) { if(GSGetMethod([obj class],@selector(initWithFrame:), YES, NO) != NULL) { @@ -815,7 +829,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN id obj = [super initWithCoder: coder]; if(obj != nil) { - if(![self respondsToSelector: @selector(isInInterfaceBuilder)]) + if([self shouldSwapClass]) { if(GSGetMethod([obj class],@selector(initWithFrame:textContainer:), YES, NO) != NULL) { @@ -846,7 +860,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN id obj = [super initWithCoder: coder]; if(obj != nil) { - if(![self respondsToSelector: @selector(isInInterfaceBuilder)]) + if([self shouldSwapClass]) { if(GSGetMethod([obj class],@selector(initWithTitle:), YES, NO) != NULL) { @@ -877,7 +891,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN if(obj != nil) { /* - if(![self respondsToSelector: @selector(isInInterfaceBuilder)]) + if([self shouldSwapClass]) { if(GSGetMethod([obj class],@selector(initWithFrame:), YES, NO) != NULL) { @@ -906,7 +920,7 @@ static NSString *GSInternalNibItemAddedNotification = @"_GSInternalNibItemAddedN id obj = [super initWithCoder: coder]; if(obj != nil) { - if(![self respondsToSelector: @selector(isInInterfaceBuilder)]) + if([self shouldSwapClass]) { if(GSGetMethod([obj class],@selector(init), YES, NO) != NULL) {