If no indexPaths are found, return the root

This commit is contained in:
Gregory John Casamento 2024-08-02 11:20:58 -04:00
parent 8935a2d2da
commit fbee6dce81
3 changed files with 43 additions and 6 deletions

View file

@ -151,6 +151,18 @@ static NSImage *unexpandable = nil;
row: (NSInteger)index;
@end
@interface NSTreeNode (Private_NSOutlineView)
- (void) _setParentNode: (NSTreeNode*)parentNode;
@end
@implementation NSTreeNode (Private_NSOutlineView)
- (void) _setParentNode: (NSTreeNode*)parentNode
{
_parentNode = parentNode;
}
@end
@implementation NSOutlineView
// Initialize the class when it is loaded
@ -1755,7 +1767,7 @@ Also returns the child index relative to this parent. */
// root object
if (count == 0)
{
NSIndexPath *path = [NSIndexPath indexPathWithIndex: 0];
NSIndexPath *path = [NSIndexPath indexPathWithIndex: 1];
[_selectedIndexPaths addObject: path];
}
}
@ -1796,7 +1808,7 @@ Also returns the child index relative to this parent. */
[theBinding reverseSetValue: _selectedIndexPaths];
}
}
[nc postNotificationName: NSOutlineViewSelectionDidChangeNotification
object: self];
}
@ -2183,7 +2195,7 @@ Also returns the child index relative to this parent. */
* from whether there are children present on a given node. See
* the documentation for NSTreeController for more info.
*/
if ([self isExpandable: startitem] // leaf == NO
if ([self isExpandable: startitem]
&& [self isItemExpanded: startitem])
{
NSString *childrenKeyPath = [tc childrenKeyPathForNode: startitem];
@ -2218,6 +2230,10 @@ Also returns the child index relative to this parent. */
{
id anitem = [children objectAtIndex: i];
if ([anitem respondsToSelector: @selector(_setParentNode:)])
{
[anitem _setParentNode: startitem];
}
[anarray addObject: anitem];
[self _loadDictionaryStartingWith: anitem
atLevel: level + 1];

View file

@ -34,9 +34,11 @@
#import <Foundation/NSKeyedArchiver.h>
#import <Foundation/NSKeyValueCoding.h>
#import <Foundation/NSKeyValueObserving.h>
#import <Foundation/NSNotification.h>
#import <Foundation/NSString.h>
#import <Foundation/NSSortDescriptor.h>
#import "AppKit/NSOutlineView.h"
#import "AppKit/NSKeyValueBinding.h"
#import "AppKit/NSTreeController.h"
#import "AppKit/NSTreeNode.h"
@ -45,6 +47,21 @@
#import "GSFastEnumeration.h"
#import "GSControllerTreeProxy.h"
@interface NSOutlineView (__NSTreeController_private__)
- (NSArray *) _selectedIndexPaths;
@end
@implementation NSOutlineView (__NSTreeController_private__)
- (NSArray *) _selectedIndexPaths
{
return _selectedIndexPaths;
}
@end
@implementation NSTreeController
+ (void) initialize
@ -101,6 +118,7 @@
RELEASE(_leafKeyPath);
RELEASE(_sortDescriptors);
RELEASE(_arranged_objects);
[super dealloc];
}
@ -321,7 +339,7 @@
NSUInteger pos = 0;
NSMutableArray *children = [_arranged_objects mutableChildNodes];
NSUInteger lastIndex = 0;
for (pos = 0; pos < length - 1; pos++)
{
NSUInteger i = [indexPath indexAtPosition: pos];
@ -333,7 +351,6 @@
lastIndex = [indexPath indexAtPosition: length - 1];
[children insertObject: object atIndex: lastIndex];
NSLog(@"children = %@, class = %@", children, [children className]);
[self rearrangeObjects];
}
}

View file

@ -47,6 +47,7 @@
- (void) _setParentNode: (NSTreeNode*)parentNode
{
NSLog(@"parentNode = %@", parentNode);
_parentNode = parentNode;
}
@ -154,12 +155,13 @@
- (NSIndexPath*) indexPath
{
NSLog(@"In %@", NSStringFromSelector(_cmd));
if (_parentNode != nil)
{
NSIndexPath *path;
NSUInteger index;
index = [_parentNode->_childNodes indexOfObject: self];
index = [[_parentNode childNodes] indexOfObject: self];
path = [_parentNode indexPath];
if (path != nil)
{
@ -169,6 +171,8 @@
{
return [NSIndexPath indexPathWithIndex: index];
}
NSLog(@"index = %ld", index);
}
else
{