From 5befed5855d91e02ba11d31ffb65fed9a60c73f5 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sun, 18 Aug 2024 17:25:47 -0400 Subject: [PATCH] Fix a number of issues pointed out by @fredkiefer --- Headers/AppKit/NSOutlineView.h | 1 - Source/GSThemeDrawing.m | 1 - Source/NSOutlineView.m | 21 ++++++++++----------- Source/NSTreeController.m | 18 ++++++++++++------ 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Headers/AppKit/NSOutlineView.h b/Headers/AppKit/NSOutlineView.h index 81fbcd770..fe0b1b966 100644 --- a/Headers/AppKit/NSOutlineView.h +++ b/Headers/AppKit/NSOutlineView.h @@ -44,7 +44,6 @@ APPKIT_EXPORT_CLASS NSMapTable *_itemDict; NSMutableArray *_items; NSMutableArray *_expandedItems; - NSMutableArray *_selectedIndexPaths; NSMapTable *_levelOfItems; BOOL _autoResizesOutlineColumn; BOOL _indentationMarkerFollowsCell; diff --git a/Source/GSThemeDrawing.m b/Source/GSThemeDrawing.m index e8d08a518..6c7006742 100644 --- a/Source/GSThemeDrawing.m +++ b/Source/GSThemeDrawing.m @@ -3532,7 +3532,6 @@ - (void) drawOutlineViewRow: (NSInteger)rowIndex NSInteger endingColumn; NSRect drawingRect; NSInteger i; - id dataSource = [outlineView dataSource]; NSTableColumn *outlineTableColumn = [outlineView outlineTableColumn]; /* Using columnAtPoint: here would make it called twice per row per drawn diff --git a/Source/NSOutlineView.m b/Source/NSOutlineView.m index 5d9379d4b..feb12cfb7 100644 --- a/Source/NSOutlineView.m +++ b/Source/NSOutlineView.m @@ -225,7 +225,6 @@ - (void) dealloc { RELEASE(_items); RELEASE(_expandedItems); - RELEASE(_selectedIndexPaths); NSFreeMapTable(_itemDict); NSFreeMapTable(_levelOfItems); @@ -1788,17 +1787,16 @@ - (NSIndexPath *) _findIndexPathForItem: (id)item - (NSIndexPath *) _indexPathForItem: (id)item { - id rootItem = nil; return [self _findIndexPathForItem: item - parentItem: rootItem]; + parentItem: nil]; } -- (void) _indexPathsFromSelectedRows +- (NSArray *) _indexPathsFromSelectedRows { NSUInteger index = [_selectedRows firstIndex]; - + NSMutableArray *result = [[NSMutableArray alloc] init]; + // Regenerate the array... - [_selectedIndexPaths removeAllObjects]; while (index != NSNotFound) { id item = [_items objectAtIndex: index]; @@ -1813,10 +1811,12 @@ - (void) _indexPathsFromSelectedRows path = [self _indexPathForItem: item]; } - [_selectedIndexPaths addObject: path]; + [result addObject: path]; index = [_selectedRows indexGreaterThanIndex: index]; } + + return result; } /* @@ -1847,12 +1847,12 @@ - (void) _postSelectionDidChangeNotification forObject: observedObject]; if (theBinding != nil) { - [self _indexPathsFromSelectedRows]; + NSArray *paths = [self _indexPathsFromSelectedRows]; if ([observedObject respondsToSelector: @selector(setSelectionIndexPaths:)]) { - [observedObject setSelectionIndexPaths: _selectedIndexPaths]; + [observedObject setSelectionIndexPaths: paths]; } - [theBinding reverseSetValue: _selectedIndexPaths]; + [theBinding reverseSetValue: paths]; } } @@ -2101,7 +2101,6 @@ - (void) _initOutlineDefaults 64); _items = [[NSMutableArray alloc] init]; _expandedItems = [[NSMutableArray alloc] init]; - _selectedIndexPaths = [[NSMutableArray alloc] init]; _levelOfItems = NSCreateMapTable(keyCallBacks, NSObjectMapValueCallBacks, 64); diff --git a/Source/NSTreeController.m b/Source/NSTreeController.m index f1b18bac0..13247ff46 100644 --- a/Source/NSTreeController.m +++ b/Source/NSTreeController.m @@ -161,7 +161,8 @@ - (BOOL) setSelectionIndexPath: (NSIndexPath *)indexPath if (YES == f) { - [_selection_index_paths addObject: indexPath]; + NSMutableArray *mutable_index_paths = [NSMutableArray arrayWithObject: indexPath]; + ASSIGN(_selection_index_paths, mutable_index_paths); } return f; @@ -241,17 +242,21 @@ - (NSArray *) selectedObjects - (NSIndexPath *) selectionIndexPath { - return [_selection_index_paths objectAtIndex: 0]; + if ([_selection_index_paths count] > 0) + { + return [_selection_index_paths objectAtIndex: 0]; + } + return nil; } - (NSArray *) selectionIndexPaths { - return _selection_index_paths; + return [_selection_index_paths copy]; } - (NSArray *) sortDescriptors { - return _sortDescriptors; + return [_sortDescriptors copy]; } - (NSString *) childrenKeyPath @@ -261,7 +266,7 @@ - (NSString *) childrenKeyPath - (NSString *) countKeyPath { - return _countKeyPath;; + return _countKeyPath; } - (NSString *) leafKeyPath @@ -274,6 +279,7 @@ - (IBAction) add: (id)sender NSIndexPath *p = [NSIndexPath indexPathWithIndex: 0]; id newObject = [self newObject]; [self insertObject: newObject atArrangedObjectIndexPath: p]; + RELEASE(newObject); } - (IBAction) addChild: (id)sender @@ -295,7 +301,7 @@ - (IBAction) remove: (id)sender { if ([_selection_index_paths count] > 0) { - NSIndexPath *p = [_selection_index_paths objectAtIndex: 0]; + NSIndexPath *p = [self selectionIndexPath]; [self removeObjectAtArrangedObjectIndexPath: p]; } }