Integrate IBConnector subclasses and IBUserDefinedRuntimeAttribute with their '5' subclasses

This commit is contained in:
Gregory John Casamento 2020-01-24 04:01:14 -05:00
parent 5591db7ce9
commit f71bdf5cff
4 changed files with 135 additions and 157 deletions

View file

@ -49,14 +49,3 @@
- (NSRange) decodeRangeForKey: (NSString*)key;
@end
@interface IBActionConnection5 : IBActionConnection
{
NSString *trigger;
}
@end
@interface IBOutletConnection5 : IBOutletConnection
@end
@interface IBUserDefinedRuntimeAttribute5 : IBUserDefinedRuntimeAttribute
@end

View file

@ -86,6 +86,7 @@
@interface IBActionConnection: IBConnection
{
NSString *trigger;
}
@end

View file

@ -60,147 +60,6 @@
#define DEBUG_XIB5 0
@implementation IBActionConnection5
- (instancetype) initWithCoder: (NSCoder *)coder
{
self = [super initWithCoder: coder];
if (self)
{
trigger = nil;
if ([coder allowsKeyedCoding])
{
// label and source string tags have changed for XIB5...
ASSIGN(label, [coder decodeObjectForKey: @"selector"]);
ASSIGN(source, [coder decodeObjectForKey: @"target"]);
// destination string tag is still the same (so far) and loaded
// by base class...
//ASSIGN(destination, [coder decodeObjectForKey: @"destination"]);
// Looks like the 'trigger' attribute should be used to override the
// target/action setup method...
if ([coder containsValueForKey: @"trigger"])
ASSIGN(trigger, [coder decodeObjectForKey: @"trigger"]);
}
else
{
[NSException raise: NSInvalidArgumentException
format: @"Can't decode %@ with %@.",NSStringFromClass([self class]),
NSStringFromClass([coder class])];
}
}
return self;
}
- (NSString*) trigger
{
return trigger;
}
- (void) establishConnection
{
if (trigger && [trigger length])
{
SEL sel = NSSelectorFromString(label);
NSString *selName = [NSString stringWithFormat: @"set%@%@:",
[[trigger substringToIndex: 1] uppercaseString],
[trigger substringFromIndex: 1]];
SEL trigsel = NSSelectorFromString(selName);
if (sel && trigsel && [destination respondsToSelector: trigsel])
{
NSWarnMLog(@"setting trigger %@ to selector %@", selName, label);
//[destination setTarget: source]; // Not needed???
[destination performSelector: trigsel withObject: (id)sel];
}
else if (!sel)
{
NSWarnMLog(@"label %@ does not correspond to any selector", label);
}
else if (!trigsel)
{
NSWarnMLog(@"trigger %@ does not correspond to any selector", trigger);
}
else
{
NSWarnMLog(@"destination class (%@) does not respond to trigger selector %@",
NSStringFromClass([destination class]), selName);
}
// PREMATURE RETURN...
return;
}
// Otherwise invoke the super class' method...
[super establishConnection];
}
@end
@implementation IBOutletConnection5
- (instancetype) initWithCoder: (NSCoder *)coder
{
self = [super initWithCoder: coder];
if (self)
{
if ([coder allowsKeyedCoding])
{
// label string tag has changed for XIB5...
ASSIGN(label, [coder decodeObjectForKey: @"property"]);
// destination and source string tags are still the same (so far) and loaded
// by base class...
}
else
{
[NSException raise: NSInvalidArgumentException
format: @"Can't decode %@ with %@.",NSStringFromClass([self class]),
NSStringFromClass([coder class])];
}
}
return self;
}
@end
@implementation IBUserDefinedRuntimeAttribute5
- (id) initWithCoder: (NSCoder *)coder
{
self = [super initWithCoder: coder];
if (self)
{
if ([coder allowsKeyedCoding])
{
[self setTypeIdentifier: [coder decodeObjectForKey: @"type"]];
// Decode value properly...
if ([@"boolean" isEqualToString: typeIdentifier])
[self setValue: [NSNumber numberWithBool: ([@"YES" isEqualToString: value] ? YES : NO)]];
else if ([@"image" isEqualToString: typeIdentifier])
[self setValue: [NSImage imageNamed: value]];
else if ([@"number" isEqualToString: typeIdentifier])
[self setValue: [coder decodeObjectForKey: @"value"]];
else if ([@"point" isEqualToString: typeIdentifier])
[self setValue: [coder decodeObjectForKey: @"value"]];
else if ([@"size" isEqualToString: typeIdentifier])
[self setValue: [coder decodeObjectForKey: @"size"]];
else if ([@"rect" isEqualToString: typeIdentifier])
[self setValue: [coder decodeObjectForKey: @"value"]];
else if ([@"nil" isEqualToString: typeIdentifier])
[self setValue: nil];
else
NSWarnMLog(@"type: %@ value: %@ (%@)", typeIdentifier, value, [value class]);
}
}
return self;
}
@end
@implementation GSXib5KeyedUnarchiver

View file

@ -33,9 +33,11 @@
#import <Foundation/NSException.h>
#import <Foundation/NSObject.h>
#import <Foundation/NSKeyedArchiver.h>
// #import <Foundation/NSNumber.h>
#import "AppKit/NSControl.h"
#import "AppKit/NSNibLoading.h"
#import "AppKit/NSWindow.h"
#import "AppKit/NSImage.h"
#import "GNUstepGUI/GSNibLoading.h"
#import "GNUstepGUI/GSXibLoading.h"
@ -62,12 +64,40 @@
- (id) initWithCoder: (NSCoder *)coder
{
if([coder allowsKeyedCoding])
self = [super init];
if (self)
{
[self setTypeIdentifier: [coder decodeObjectForKey: @"typeIdentifier"]];
[self setKeyPath: [coder decodeObjectForKey: @"keyPath"]];
[self setValue: [coder decodeObjectForKey: @"value"]];
if ([coder allowsKeyedCoding])
{
[self setTypeIdentifier: [coder decodeObjectForKey: @"typeIdentifier"]];
[self setKeyPath: [coder decodeObjectForKey: @"keyPath"]];
[self setValue: [coder decodeObjectForKey: @"value"]];
if ([coder containsValueForKey: @"type"])
{
[self setTypeIdentifier: [coder decodeObjectForKey: @"type"]];
// Decode value properly...
if ([@"boolean" isEqualToString: typeIdentifier])
[self setValue: [NSNumber numberWithBool: ([@"YES" isEqualToString: value] ? YES : NO)]];
else if ([@"image" isEqualToString: typeIdentifier])
[self setValue: [NSImage imageNamed: value]];
else if ([@"number" isEqualToString: typeIdentifier])
[self setValue: [coder decodeObjectForKey: @"value"]];
else if ([@"point" isEqualToString: typeIdentifier])
[self setValue: [coder decodeObjectForKey: @"value"]];
else if ([@"size" isEqualToString: typeIdentifier])
[self setValue: [coder decodeObjectForKey: @"size"]];
else if ([@"rect" isEqualToString: typeIdentifier])
[self setValue: [coder decodeObjectForKey: @"value"]];
else if ([@"nil" isEqualToString: typeIdentifier])
[self setValue: nil];
else
NSWarnMLog(@"type: %@ value: %@ (%@)", typeIdentifier, value, [value class]);
}
}
}
return self;
}
@ -420,19 +450,118 @@
@end
@implementation IBActionConnection
- (instancetype) initWithCoder: (NSCoder *)coder
{
self = [super initWithCoder: coder];
if (self)
{
trigger = nil;
if ([coder allowsKeyedCoding])
{
// label and source string tags have changed for XIB5...
if ([coder containsValueForKey: @"selector"])
{
ASSIGN(label, [coder decodeObjectForKey: @"selector"]);
}
if ([coder containsValueForKey: @"target"])
{
ASSIGN(source, [coder decodeObjectForKey: @"target"]);
}
// destination string tag is still the same (so far) and loaded
// by base class...
//ASSIGN(destination, [coder decodeObjectForKey: @"destination"]);
// Looks like the 'trigger' attribute should be used to override the
// target/action setup method...
if ([coder containsValueForKey: @"trigger"])
{
ASSIGN(trigger, [coder decodeObjectForKey: @"trigger"]);
}
}
else
{
[NSException raise: NSInvalidArgumentException
format: @"Can't decode %@ with %@.",NSStringFromClass([self class]),
NSStringFromClass([coder class])];
}
}
return self;
}
- (NSString*) trigger
{
return trigger;
}
- (void) establishConnection
{
SEL sel = NSSelectorFromString(label);
if (trigger && [trigger length])
{
NSString *selName = [NSString stringWithFormat: @"set%@%@:",
[[trigger substringToIndex: 1] uppercaseString],
[trigger substringFromIndex: 1]];
SEL trigsel = NSSelectorFromString(selName);
if (sel && trigsel && [destination respondsToSelector: trigsel])
{
NSWarnMLog(@"setting trigger %@ to selector %@", selName, label);
//[destination setTarget: source]; // Not needed???
[destination performSelector: trigsel withObject: (id)sel];
}
else if (!sel)
{
NSWarnMLog(@"label %@ does not correspond to any selector", label);
}
else if (!trigsel)
{
NSWarnMLog(@"trigger %@ does not correspond to any selector", trigger);
}
else
{
NSWarnMLog(@"destination class (%@) does not respond to trigger selector %@",
NSStringFromClass([destination class]), selName);
}
// PREMATURE RETURN...
return;
}
// Otherwise do the following....
[destination setTarget: source];
[destination setAction: sel];
}
@end
@implementation IBOutletConnection
- (instancetype) initWithCoder: (NSCoder *)coder
{
self = [super initWithCoder: coder];
if (self)
{
if ([coder allowsKeyedCoding])
{
// label string tag has changed for XIB5...
if ([coder containsValueForKey: @"property"])
{
ASSIGN(label, [coder decodeObjectForKey: @"property"]);
// destination and source string tags are still the same (so far) and loaded
// by base class...
}
}
else
{
[NSException raise: NSInvalidArgumentException
format: @"Can't decode %@ with %@.",NSStringFromClass([self class]),
NSStringFromClass([coder class])];
}
}
return self;
}
- (void) establishConnection
{
NS_DURING