Skip to content

Commit

Permalink
Fix a number of issues pointed out by @fredkiefer
Browse files Browse the repository at this point in the history
  • Loading branch information
gcasa committed Aug 18, 2024
1 parent fbc0cd1 commit 5befed5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
1 change: 0 additions & 1 deletion Headers/AppKit/NSOutlineView.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ APPKIT_EXPORT_CLASS
NSMapTable *_itemDict;
NSMutableArray *_items;
NSMutableArray *_expandedItems;
NSMutableArray *_selectedIndexPaths;
NSMapTable *_levelOfItems;
BOOL _autoResizesOutlineColumn;
BOOL _indentationMarkerFollowsCell;
Expand Down
1 change: 0 additions & 1 deletion Source/GSThemeDrawing.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 10 additions & 11 deletions Source/NSOutlineView.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ - (void) dealloc
{
RELEASE(_items);
RELEASE(_expandedItems);
RELEASE(_selectedIndexPaths);

NSFreeMapTable(_itemDict);
NSFreeMapTable(_levelOfItems);
Expand Down Expand Up @@ -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];
Expand All @@ -1813,10 +1811,12 @@ - (void) _indexPathsFromSelectedRows
path = [self _indexPathForItem: item];
}

[_selectedIndexPaths addObject: path];
[result addObject: path];

index = [_selectedRows indexGreaterThanIndex: index];
}

return result;
}

/*
Expand Down Expand Up @@ -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];
}
}

Expand Down Expand Up @@ -2101,7 +2101,6 @@ - (void) _initOutlineDefaults
64);
_items = [[NSMutableArray alloc] init];
_expandedItems = [[NSMutableArray alloc] init];
_selectedIndexPaths = [[NSMutableArray alloc] init];
_levelOfItems = NSCreateMapTable(keyCallBacks,
NSObjectMapValueCallBacks,
64);
Expand Down
18 changes: 12 additions & 6 deletions Source/NSTreeController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -261,7 +266,7 @@ - (NSString *) childrenKeyPath

- (NSString *) countKeyPath
{
return _countKeyPath;;
return _countKeyPath;
}

- (NSString *) leafKeyPath
Expand All @@ -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
Expand All @@ -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];
}
}
Expand Down

0 comments on commit 5befed5

Please sign in to comment.