Add implementation for methods that add nodes at a given indexPath or set of indexPaths

This commit is contained in:
Gregory John Casamento 2024-07-12 06:22:56 -04:00
parent bbbe9d00b4
commit 90b3913a1f
3 changed files with 59 additions and 29 deletions

View file

@ -165,14 +165,14 @@ APPKIT_EXPORT_CLASS
* If the tree controller is in "object" mode, then newObject is called
* to add a new node.
*/
- (void) addChild: (id)sender;
- (IBAction) addChild: (id)sender;
/**
* Adds a new objeect to the tree usin the newObject method.
* If the tree controller is in "object" mode, then newObject is called
* to add a new node.
*/
- (void) add: (id)sender;
- (IBAction) add: (id)sender;
/**
* Inserts a child using the newObject method. This method
@ -180,7 +180,7 @@ APPKIT_EXPORT_CLASS
* If the tree controller is in "object" mode, then newObject is called
* to add a new node.
*/
- (void) insertChild: (id)sender;
- (IBAction) insertChild: (id)sender;
/**
* Inserts and object using the newObject method at the specified indexPath.
@ -217,7 +217,7 @@ APPKIT_EXPORT_CLASS
* This method will only function if the tree controller is in
* "object" mode.
*/
- (void) insert: (id)sender;
- (IBAction) insert: (id)sender;
/**
* Causes the controller to re-sort and rearrange the objects. This method
@ -262,7 +262,7 @@ APPKIT_EXPORT_CLASS
* Remove the currently selected object. This method will only
* function if the tree controller is in "object" mode.
*/
- (void) remove: (id)sender;
- (IBAction) remove: (id)sender;
/**
* Sets the flag to always use multiple values marker.

View file

@ -57,6 +57,7 @@
return [children count];
}
// This is here so that when the path is specified as "children" it responds
- (NSMutableArray *) children
{
NSDictionary *ro = [self representedObject];
@ -75,5 +76,16 @@
forKey: @"value"];
}
// These return the value in the cases where the parent class method is called...
- (NSArray *) childNodes
{
return [self children];
}
- (NSArray *) mutableChildNodes
{
return [self children];
}
@end

View file

@ -32,6 +32,7 @@
#import <Foundation/NSDictionary.h>
#import <Foundation/NSIndexPath.h>
#import <Foundation/NSKeyedArchiver.h>
#import <Foundation/NSKeyValueCoding.h>
#import <Foundation/NSKeyValueObserving.h>
#import <Foundation/NSString.h>
#import <Foundation/NSSortDescriptor.h>
@ -237,7 +238,7 @@
return _leafKeyPath;
}
- (void) add: (id)sender
- (IBAction) add: (id)sender
{
if ([self canAddChild]
&& [self countKeyPath] == nil)
@ -258,28 +259,13 @@
}
}
- (void) addChild: (id)obj
- (IBAction) addChild: (id)sender
{
if ([self canAddChild]
&& [self countKeyPath] == nil)
{
id newObject = [self newObject];
if (newObject != nil)
{
NSMutableArray *newContent = [NSMutableArray arrayWithArray: [self content]];
GSControllerTreeProxy *node = [[GSControllerTreeProxy alloc]
initWithRepresentedObject: newObject
withController: self];
[newContent addObject: node];
[self setContent: newContent];
RELEASE(newObject);
}
}
// FIXME
[self add: sender];
}
- (void) remove: (id)sender
- (IBAction) remove: (id)sender
{
if ([self canRemove]
&& [self countKeyPath] == nil)
@ -288,24 +274,56 @@
}
}
- (void) insertChild: (id)sender
- (IBAction) insertChild: (id)sender
{
// FIXME
[self add: sender];
}
- (void) insertObject: (id)object atArrangedObjectIndexPath: (NSIndexPath*)indexPath
{
// FIXME
NSUInteger length = [indexPath length];
NSUInteger pos = 0;
NSMutableArray *children = [_arranged_objects mutableChildNodes];
NSUInteger lastIndex = 0;
for (pos = 0; pos < length - 1; pos++)
{
NSUInteger i = [indexPath indexAtPosition: pos];
id node = [children objectAtIndex: i];
children = [node valueForKeyPath: _childrenKeyPath];
}
lastIndex = [indexPath indexAtPosition: length - 1];
[children insertObject: object atIndex: lastIndex];
}
- (void) insertObjects: (NSArray*)objects atArrangedObjectIndexPaths: (NSArray*)indexPaths
{
// FIXME
if ([objects count] != [indexPaths count])
{
return;
}
else
{
NSUInteger i = 0;
FOR_IN(id, object, objects)
{
NSIndexPath *indexPath = [indexPaths objectAtIndex: i];
[self insertObject: object atArrangedObjectIndexPath: indexPath];
i++;
}
END_FOR_IN(objects);
}
}
- (void) insert: (id)sender
- (IBAction) insert: (id)sender
{
// FIXME
[self add: sender];
}
- (void) removeObjectAtArrangedObjectIndexPath: (NSIndexPath*)indexPath