simplify existing implementation of dictionary controller

This commit is contained in:
Gregory John Casamento 2023-01-30 10:47:05 -05:00
parent 7250e3fac1
commit 8de600877b
2 changed files with 48 additions and 62 deletions

View file

@ -62,6 +62,7 @@
*/
- (BOOL) isExplicitlyIncluded;
- (void) setExplicitlyIncluded: (BOOL)flag;
@end
#endif
@ -82,8 +83,6 @@ extern "C" {
NSDictionary *_localizedKeyDictionary;
NSString *_localizedKeyTable;
NSUInteger _count;
NSDictionary *_contentDictionary;
}
/**
@ -136,4 +135,3 @@ extern "C" {
#endif /* GS_API_MACOSX */
#endif /* _NSDictionaryController_h_GNUSTEP_GUI_INCLUDE */

View file

@ -41,16 +41,13 @@
{
if (self == [NSDictionaryController class])
{
[self exposeBinding: NSContentDictionaryBinding];
//[self exposeBinding: NSIncludedKeysBinding];
[self exposeBinding: NSIncludedKeysBinding];
[self exposeBinding: NSExcludedKeysBinding];
[self exposeBinding: NSInitialKeyBinding];
[self exposeBinding: NSInitialValueBinding];
/*
[self setKeys: [NSArray arrayWithObjects: NSContentDictionaryBinding, nil] // NSContentBinding, NSContentObjectBinding, nil]
[self setKeys: [NSArray arrayWithObjects: NSContentBinding, NSContentObjectBinding, nil]
triggerChangeNotificationsForDependentKey: @"arrangedObjects"];
*/
}
}
@ -129,9 +126,9 @@
ASSIGN(_localizedKeyTable, keyTable);
}
- (NSArray *) _buildArray
- (NSArray *) _buildArray: (NSDictionary *)content
{
NSArray *allKeys = [_contentDictionary allKeys];
NSArray *allKeys = [content allKeys];
NSMutableArray *result = [NSMutableArray arrayWithCapacity: [allKeys count]];
FOR_IN(id, k, allKeys)
@ -141,7 +138,7 @@
if ([_includedKeys containsObject: k])
{
id v = [_contentDictionary objectForKey: k];
id v = [[self content] objectForKey: k];
[kvp setKey: k];
[kvp setValue: v];
@ -159,18 +156,9 @@
return result;
}
- (NSDictionary *) contentDictionary
- (void) setContent: (id)content
{
return _contentDictionary;
}
- (void) setContentDictionary: (NSDictionary *)dict
{
NSArray *array = nil;
ASSIGN(_contentDictionary, dict);
array = [self _buildArray];
[self arrangeObjects: array];
[super setContent: [self _buildArray: content]];
}
- (void) observeValueForKeyPath: (NSString*)aPath
@ -185,6 +173,46 @@
return;
}
- (void) bind: (NSString *)binding
toObject: (id)anObject
withKeyPath: (NSString *)keyPath
options: (NSDictionary *)options
{
if ([binding isEqual: NSContentDictionaryBinding])
{
GSKeyValueBinding *kvb;
[self unbind: binding];
kvb = [[GSKeyValueBinding alloc] initWithBinding: @"content"
withName: binding
toObject: anObject
withKeyPath: keyPath
options: options
fromObject: self];
// The binding will be retained in the binding table
RELEASE(kvb);
}
else
{
[super bind: binding
toObject: anObject
withKeyPath: keyPath
options: options];
}
}
- (Class) valueClassForBinding: (NSString *)binding
{
if ([binding isEqual: NSContentDictionaryBinding])
{
return [NSDictionary class];
}
else
{
return [super valueClassForBinding: binding];
}
}
@end
@implementation NSDictionaryControllerKeyValuePair
@ -248,44 +276,4 @@
_explicitlyIncluded = flag;
}
- (void) bind: (NSString *)binding
toObject: (id)anObject
withKeyPath: (NSString *)keyPath
options: (NSDictionary *)options
{
if ([binding isEqual: NSContentDictionaryBinding])
{
GSKeyValueBinding *kvb;
[self unbind: binding];
kvb = [[GSKeyValueBinding alloc] initWithBinding: @"content"
withName: binding
toObject: anObject
withKeyPath: keyPath
options: options
fromObject: self];
// The binding will be retained in the binding table
RELEASE(kvb);
}
else
{
[super bind: binding
toObject: anObject
withKeyPath: keyPath
options: options];
}
}
- (Class) valueClassForBinding: (NSString *)binding
{
if ([binding isEqual: NSContentDictionaryBinding])
{
return [NSDictionary class];
}
else
{
return [super valueClassForBinding: binding];
}
}
@end