Update header and add non-keyed encoding to the class

This commit is contained in:
Gregory John Casamento 2023-03-29 07:26:32 -04:00
parent 21e8018d7d
commit bbce009d7e
2 changed files with 67 additions and 28 deletions

View file

@ -1,4 +1,4 @@
/* /*
NSTreeController.h NSTreeController.h
The tree controller class. The tree controller class.
@ -7,7 +7,7 @@
Author: Gregory Casamento <greg.casamento@gmail.com> Author: Gregory Casamento <greg.casamento@gmail.com>
Date: 2012 Date: 2012
This file is part of the GNUstep GUI Library. This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@ -22,10 +22,10 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB. License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor, Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
#ifndef _GNUstep_H_NSTreeController #ifndef _GNUstep_H_NSTreeController
#define _GNUstep_H_NSTreeController #define _GNUstep_H_NSTreeController
@ -48,22 +48,23 @@ APPKIT_EXPORT_CLASS
NSString *_leafKeyPath; NSString *_leafKeyPath;
NSArray *_sort_descriptors; NSArray *_sort_descriptors;
NSArray *_arranged_objects; NSArray *_arranged_objects;
BOOL _alwaysUsesMultipleValuesMarker; BOOL _alwaysUsesMultipleValuesMarker;
BOOL _avoidsEmptySelection; BOOL _avoidsEmptySelection;
BOOL _preservesSelection; BOOL _preservesSelection;
BOOL _selectsInsertedObjects; BOOL _selectsInsertedObjects;
} }
- (BOOL) addSelectionIndexPaths: (NSArray*)indexPaths; - (BOOL) addSelectionIndexPaths: (NSArray *)indexPaths;
- (BOOL) alwaysUsesMultipleValuesMarker; - (BOOL) alwaysUsesMultipleValuesMarker;
- (BOOL) avoidsEmptySelection; - (BOOL) avoidsEmptySelection;
- (BOOL) canAddChild; - (BOOL) canAddChild;
- (BOOL) canInsert; - (BOOL) canInsert;
- (BOOL) canInsertChild; - (BOOL) canInsertChild;
- (BOOL) preservesSelection; - (BOOL) preservesSelection;
- (BOOL) selectsInsertedObjects; - (BOOL) selectsInsertedObjects;
- (BOOL) setSelectionIndexPath: (NSIndexPath*)indexPath; - (BOOL) setSelectionIndexPath: (NSIndexPath *)indexPath;
- (BOOL) setSelectionIndexPaths: (NSArray*)indexPaths; - (BOOL) setSelectionIndexPaths: (NSArray *)indexPaths;
- (id) arrangedObjects; - (id) arrangedObjects;
- (NSArray*) selectedObjects; - (NSArray*) selectedObjects;
- (NSIndexPath*) selectionIndexPath; - (NSIndexPath*) selectionIndexPath;
@ -75,29 +76,29 @@ APPKIT_EXPORT_CLASS
- (void) addChild: (id)sender; - (void) addChild: (id)sender;
- (void) add: (id)sender; - (void) add: (id)sender;
- (void) insertChild: (id)sender; - (void) insertChild: (id)sender;
- (void) insertObject: (id)object atArrangedObjectIndexPath: (NSIndexPath*)indexPath; - (void) insertObject: (id)object atArrangedObjectIndexPath: (NSIndexPath *)indexPath;
- (void) insertObjects: (NSArray*)objects atArrangedObjectIndexPaths: (NSArray*)indexPaths; - (void) insertObjects: (NSArray *)objects atArrangedObjectIndexPaths: (NSArray *)indexPaths;
- (void) insert: (id)sender; - (void) insert: (id)sender;
- (void) rearrangeObjects; - (void) rearrangeObjects;
- (void) removeObjectAtArrangedObjectIndexPath: (NSIndexPath*)indexPath; - (void) removeObjectAtArrangedObjectIndexPath: (NSIndexPath *)indexPath;
- (void) removeObjectsAtArrangedObjectIndexPaths: (NSArray*)indexPaths; - (void) removeObjectsAtArrangedObjectIndexPaths: (NSArray *)indexPaths;
- (void) removeSelectionIndexPaths: (NSArray*)indexPaths; - (void) removeSelectionIndexPaths: (NSArray *)indexPaths;
- (void) remove: (id)sender; - (void) remove: (id)sender;
- (void) setAlwaysUsesMultipleValuesMarker: (BOOL)flag; - (void) setAlwaysUsesMultipleValuesMarker: (BOOL)flag;
- (void) setAvoidsEmptySelection: (BOOL)flag; - (void) setAvoidsEmptySelection: (BOOL)flag;
- (void) setChildrenKeyPath: (NSString*)path; - (void) setChildrenKeyPath: (NSString *)path;
- (void) setCountKeyPath: (NSString*)path; - (void) setCountKeyPath: (NSString *)path;
- (void) setLeafKeyPath: (NSString*)key; - (void) setLeafKeyPath: (NSString *)key;
- (void) setPreservesSelection: (BOOL)flag; - (void) setPreservesSelection: (BOOL)flag;
- (void) setSelectsInsertedObjects: (BOOL)flag; - (void) setSelectsInsertedObjects: (BOOL)flag;
- (void) setSortDescriptors: (NSArray*)descriptors; - (void) setSortDescriptors: (NSArray *)descriptors;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST) #if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
- (NSString*) childrenKeyPathForNode: (NSTreeNode*)node; - (NSString*) childrenKeyPathForNode: (NSTreeNode *)node;
- (NSString*) countKeyPathForNode: (NSTreeNode*)node; - (NSString*) countKeyPathForNode: (NSTreeNode *)node;
- (NSString*) leafKeyPathForNode: (NSTreeNode*)node; - (NSString*) leafKeyPathForNode: (NSTreeNode *)node;
- (void) moveNode: (NSTreeNode*)node toIndexPath: (NSIndexPath*)indexPath; - (void) moveNode: (NSTreeNode *)node toIndexPath: (NSIndexPath *)indexPath;
- (void) moveNodes: (NSArray*)nodes toIndexPath: (NSIndexPath*)startingIndexPath; - (void) moveNodes: (NSArray *)nodes toIndexPath: (NSIndexPath *)startingIndexPath;
- (NSArray*) selectedNodes; - (NSArray*) selectedNodes;
#endif #endif
@end @end

View file

@ -143,7 +143,7 @@
- (NSArray*) arrangeObjects: (NSArray*)obj - (NSArray*) arrangeObjects: (NSArray*)obj
{ {
NSArray *temp = obj; NSArray *temp = obj;
return [temp sortedArrayUsingDescriptors: _sort_descriptors]; return [temp sortedArrayUsingDescriptors: _sort_descriptors];
} }
@ -219,8 +219,8 @@
GSKeyValueBinding *theBinding; GSKeyValueBinding *theBinding;
[self setContent: obj]; [self setContent: obj];
theBinding = [GSKeyValueBinding getBinding: NSContentObjectBinding theBinding = [GSKeyValueBinding getBinding: NSContentObjectBinding
forObject: self]; forObject: self];
if (theBinding != nil) if (theBinding != nil)
[theBinding reverseSetValueFor: @"content"]; [theBinding reverseSetValueFor: @"content"];
} }
@ -405,7 +405,7 @@
[self setChildrenKeyPath: [self setChildrenKeyPath:
[coder decodeObjectForKey: @"NSTreeContentLeafKey"]]; [coder decodeObjectForKey: @"NSTreeContentLeafKey"]];
} }
// Since we don't inherit from NSArrayController these are decoded here // Since we don't inherit from NSArrayController these are decoded here
// as well. // as well.
if ([coder containsValueForKey: @"NSAvoidsEmptySelection"]) if ([coder containsValueForKey: @"NSAvoidsEmptySelection"])
@ -427,6 +427,25 @@
} }
else else
{ {
id obj = nil;
BOOL f = NO;
obj = [coder decodeObject];
[self setChildrenKeyPath: obj];
obj = [coder decodeObject];
[self setCountKeyPath: obj];
obj = [coder decodeObject];
[self setLeafKeyPath: obj];
[coder decodeValueOfObjCType: @encode(BOOL)
at: &f];
[self setAvoidsEmptySelection: f];
[coder decodeValueOfObjCType: @encode(BOOL)
at: &f];
[self setPreservesSelection: f];
[coder decodeValueOfObjCType: @encode(BOOL)
at: &f];
[self setSelectsInsertedObjects: f];
} }
return self; return self;
@ -435,7 +454,7 @@
- (void) encodeWithCoder: (NSCoder*)coder - (void) encodeWithCoder: (NSCoder*)coder
{ {
[super encodeWithCoder: coder]; [super encodeWithCoder: coder];
if ([coder allowsKeyedCoding]) if ([coder allowsKeyedCoding])
{ {
[coder encodeObject: _childrenKeyPath [coder encodeObject: _childrenKeyPath
@ -455,6 +474,25 @@
} }
else else
{ {
id obj = nil;
BOOL f = NO;
obj = [self childrenKeyPath];
[coder encodeObject: obj];
obj = [self countKeyPath];
[coder encodeObject: obj];
obj = [self leafKeyPath];
[coder encodeObject: obj];
f = [self avoidsEmptySelection];
[coder encodeValueOfObjCType: @encode(BOOL)
at: &f];
f = [self preservesSelection];
[coder encodeValueOfObjCType: @encode(BOOL)
at: &f];
f = [self selectsInsertedObjects];
[coder encodeValueOfObjCType: @encode(BOOL)
at: &f];
} }
} }