Move more behaviour from the IBActionConnection5 and IBOutletConnection5

classes to the original ones.
This commit is contained in:
fredkiefer 2020-02-23 18:22:21 +01:00
parent 078d10774c
commit 3db981a95d
4 changed files with 112 additions and 116 deletions

View file

@ -421,18 +421,117 @@
@implementation IBActionConnection
- (void) dealloc
{
DESTROY(trigger);
[super dealloc];
}
- (instancetype) initWithCoder: (NSCoder *)coder
{
self = [super initWithCoder: coder];
if (self)
{
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"]);
}
// Looks like the 'trigger' attribute should be used to override the
// 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);
[destination setTarget: source];
[destination setAction: sel];
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 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);
}
}
else
{
// Otherwise invoke the normal method...
[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"]);
}
}
else
{
[NSException raise: NSInvalidArgumentException
format: @"Can't decode %@ with %@.", NSStringFromClass([self class]),
NSStringFromClass([coder class])];
}
}
return self;
}
- (void) establishConnection
{
NS_DURING