Implement NSIBUserDefinedRuntimeAttributesConnector

This commit is contained in:
Sergey Bugaev 2018-05-12 22:13:37 +03:00
parent 7942379f04
commit ca0a2d2ab7
3 changed files with 114 additions and 0 deletions

View File

@ -128,6 +128,7 @@ set(AppKit_sources
nib.subproj/NSNibLoading.m
nib.subproj/NSClassSwapper.m
nib.subproj/NSNibAXRelationshipConnector.m
nib.subproj/NSIBUserDefinedRuntimeAttributesConnector.m
NSTextFieldCell.m
NSFormCell.m

View File

@ -0,0 +1,26 @@
#import <Foundation/Foundation.h>
@interface NSIBUserDefinedRuntimeAttributesConnector : NSObject<NSCoding> {
id _object;
NSMutableArray *_keyPaths;
NSMutableArray *_values;
}
- (void) establishConnection;
- (void) replaceObject:(id) original withObject:(id) replacement;
- (void) setLabel:(NSString *) label;
- (NSString *) label;
- (void) setDestination:(id) destination;
- (id) destination;
- (void) setSource:(id) source;
- (id) source;
- (void) setObject:(id) object;
- (id) object;
- (void) setValues: (NSArray *) values;
- (NSArray *) values;
- (void) setKeyPaths:(NSArray *) paths;
- (NSArray *) keyPaths;
@end

View File

@ -0,0 +1,87 @@
#import "NSIBUserDefinedRuntimeAttributesConnector.h"
#import <AppKit/NSRaise.h>
@implementation NSIBUserDefinedRuntimeAttributesConnector
- (id) initWithCoder:(NSCoder *) decoder {
_object = [[decoder decodeObjectForKey: @"NSObject"] retain];
_keyPaths = [[[decoder decodeObjectForKey: @"NSKeyPaths"] mutableCopy] retain];
_values = [[[decoder decodeObjectForKey: @"NSValues"] mutableCopy] retain];
return self;
}
- (void) encodeWithCoder:(NSCoder *) coder {
NSUnimplementedMethod();
}
- (void) dealloc {
[_object release];
[_keyPaths release];
[_values release];
[super dealloc];
}
- (void) establishConnection {
for (int i = 0; i < [_values count]; i++) {
[_object setValue: _values[i] forKey: _keyPaths[i]];
}
}
- (void) replaceObject:(id) original withObject:(id) replacement {
if (_object == original) [self setObject: replacement];
for (int i = 0; i < [_values count]; i++) {
if (_values[i] == original) _values[i] = replacement;
}
}
- (void) setLabel:(NSString *) label {
_keyPaths[0] = label;
}
- (NSString *) label {
return _keyPaths[0];
}
- (void) setDestination:(id) destination {
_values[0] = destination;
}
- (id) destination {
return _values[0];
}
- (void) setSource:(id) source {
source = [source retain];
[_object release];
_object = source;
}
- (id) source {
return _object;
}
- (void) setObject:(id) object {
object = [object retain];
[_object release];
_object = object;
}
- (id) object {
return _object;
}
- (void) setValues: (NSArray *) values {
values = [values retain];
[_values release];
_values = values;
}
- (NSArray *) values {
return _values;
}
- (void) setKeyPaths:(NSArray *) paths {
paths = [paths retain];
[_keyPaths release];
_keyPaths = paths;
}
- (NSArray *) keyPaths {
return _keyPaths;
}
@end