Update using rearrangeObjects, clean up white space for review

This commit is contained in:
Gregory John Casamento 2023-02-28 03:42:43 -05:00
parent b9841fe493
commit dcf5fbe74b
2 changed files with 26 additions and 34 deletions

View file

@ -1,21 +1,21 @@
/* Definition of class NSDictionaryController
Copyright (C) 2021 Free Software Foundation, Inc.
By: Gregory John Casamento
Date: 16-10-2021
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
@ -61,7 +61,7 @@ APPKIT_EXPORT_CLASS
/**
* Is this key value pair included in the underlying dictionary.
*/
- (BOOL) isExplicitlyIncluded;
- (BOOL) isExplicitlyIncluded;
- (void) setExplicitlyIncluded: (BOOL)flag;
@end
@ -112,7 +112,7 @@ APPKIT_EXPORT_CLASS
*/
- (NSArray *) includedKeys;
- (void) setIncludedKeys: (NSArray *)includedKeys;
/**
* Returns a copy of the included keys. Included keys are always represented by a
* key value pair whether or not they are included in the underlying dictionary.
@ -130,9 +130,9 @@ APPKIT_EXPORT_CLASS
*/
- (void) setLocalizedKeyDictionary: (NSDictionary *)dict;
/**
/**
* Returns the keyTable which is the dictionary in strings format.
*/
*/
- (NSString *) localizedKeyTable;
/**

View file

@ -93,7 +93,6 @@
@interface NSDictionaryController (GSPrivate_BuildArray)
- (NSArray *) _buildArray: (NSDictionary *)content;
- (NSDictionary *) _rebuildDictionary;
@end
@ -115,12 +114,12 @@
[kvp setKey: k];
[kvp setValue: v];
[kvp setExplicitlyIncluded: NO];
if ([_excludedKeys containsObject: k])
{
continue; // skip if excluded...
}
if ([_includedKeys containsObject: k])
{
[kvp setExplicitlyIncluded: YES];
@ -133,22 +132,6 @@
return result;
}
- (NSDictionary *) _rebuildDictionary
{
NSMutableDictionary *result = [NSMutableDictionary dictionary];
FOR_IN(NSDictionaryControllerKeyValuePair*, kvp, _content)
{
NSString *k = [kvp key];
NSString *v = [kvp value];
[result setObject: v forKey: k];
}
END_FOR_IN(_content);
return [result copy];
}
@end
// NSDictionary class implementation...
@ -209,6 +192,7 @@
[super addObject: obj];
[_contentDictionary setObject: v
forKey: k];
[self rearrangeObjects];
}
- (void) addObjects: (NSArray *)array
@ -224,6 +208,7 @@
forKey: k];
}
END_FOR_IN(array);
[self rearrangeObjects];
}
- (void) removeObject: (id)obj
@ -232,6 +217,7 @@
[super removeObject: obj];
[_contentDictionary removeObjectForKey: k];
[self rearrangeObjects];
}
- (void) removeObjects: (NSArray *)array
@ -245,6 +231,7 @@
[_contentDictionary removeObjectForKey: k];
}
END_FOR_IN(array);
[self rearrangeObjects];
}
- (NSDictionaryControllerKeyValuePair *) newObject
@ -260,7 +247,7 @@
{
k = [_initialKey copy];
}
[kvp setKey: k];
[kvp setValue: _initialValue];
@ -270,6 +257,16 @@
return kvp;
}
- (void) rearrangeObjects
{
[self willChangeValueForKey: NSContentBinding];
DESTROY(_arranged_objects);
_arranged_objects = [[GSObservableArray alloc]
initWithArray: [self arrangeObjects:
[self _buildArray: _contentDictionary]]];
[self didChangeValueForKey: NSContentBinding];
}
- (NSString *) initialKey
{
return _initialKey;
@ -308,13 +305,8 @@
- (void) setExcludedKeys: (NSArray *)excludedKeys
{
[self willChangeValueForKey: NSContentBinding];
ASSIGNCOPY(_excludedKeys, excludedKeys);
DESTROY(_arranged_objects);
_arranged_objects = [[GSObservableArray alloc]
initWithArray: [self arrangeObjects:
[self _buildArray: _contentDictionary]]];
[self didChangeValueForKey: NSContentBinding];
[self rearrangeObjects];
}
- (NSDictionary *) localizedKeyDictionary