Update selection methods

This commit is contained in:
Gregory John Casamento 2022-09-08 03:49:25 -04:00
parent 3ea04c0e36
commit a16ad6168b
2 changed files with 36 additions and 26 deletions

View file

@ -402,6 +402,7 @@ APPKIT_EXPORT_CLASS
BOOL _isSelectable; BOOL _isSelectable;
BOOL _allowsEmptySelection; BOOL _allowsEmptySelection;
NSIndexSet *_selectionIndexes; NSIndexSet *_selectionIndexes;
NSSet *_selectionIndexPaths;
NSArray *_backgroundColors; NSArray *_backgroundColors;
@ -437,7 +438,6 @@ APPKIT_EXPORT_CLASS
NSMutableDictionary *_visibleSupplementaryViews; NSMutableDictionary *_visibleSupplementaryViews;
NSMutableSet *_indexPathsForSupplementaryElementsOfKind; NSMutableSet *_indexPathsForSupplementaryElementsOfKind;
NSMutableDictionary *_itemsToAttributes; NSMutableDictionary *_itemsToAttributes;
NSSet *_selectionIndexPaths;
// Registered class/nib for item identifier // Registered class/nib for item identifier
NSMapTable *_registeredNibs; NSMapTable *_registeredNibs;

View file

@ -408,9 +408,28 @@ static NSString *placeholderItem = nil;
[item setSelected:NO]; [item setSelected:NO];
} }
} }
FOR_IN(NSIndexPath*, i, _selectionIndexPaths)
{
id item = [self itemAtIndexPath: i];
if ([item respondsToSelector: @selector(setSelected:)])
{
[item setSelected: NO];
}
}
END_FOR_IN(_selectionIndexPaths);
} }
} }
- (NSSet *) selectionIndexPaths
{
return _selectionIndexPaths;
}
- (void) setSelectionIndexPaths: (NSSet *)indexPaths
{
}
- (NSIndexSet *) selectionIndexes - (NSIndexSet *) selectionIndexes
{ {
return _selectionIndexes; return _selectionIndexes;
@ -943,10 +962,9 @@ static NSString *placeholderItem = nil;
- (void) _selectWithEvent: (NSEvent *)theEvent indexPath: (NSIndexPath *)index - (void) _selectWithEvent: (NSEvent *)theEvent indexPath: (NSIndexPath *)index
{ {
/* NSMutableSet *currentSet = [[NSMutableSet alloc] initWithSet: [self selectionIndexPaths]];
NSMutableIndexSet *currentIndexSet = [[NSMutableIndexSet alloc] initWithIndexSet: [self selectionIndexes]];
if (_isSelectable)
if (_isSelectable && ((index < [_items count]) || index < [_visibleItems count]))
{ {
if (_allowsMultipleSelection if (_allowsMultipleSelection
&& (([theEvent modifierFlags] & NSControlKeyMask) && (([theEvent modifierFlags] & NSControlKeyMask)
@ -954,22 +972,23 @@ static NSString *placeholderItem = nil;
{ {
if ([theEvent modifierFlags] & NSControlKeyMask) if ([theEvent modifierFlags] & NSControlKeyMask)
{ {
if ([currentIndexSet containsIndex: index]) if ([currentSet containsObject: index])
{ {
[currentIndexSet removeIndex: index]; [currentSet removeObject: index];
} }
else else
{ {
[currentIndexSet addIndex: index]; [currentSet addObject: index];
} }
[self setSelectionIndexes: currentIndexSet]; [self setSelectionIndexPaths: currentSet];
} }
else if ([theEvent modifierFlags] & NSShiftKeyMask) else if ([theEvent modifierFlags] & NSShiftKeyMask)
{ {
NSUInteger firstSelectedIndex = [currentIndexSet firstIndex]; /*
id firstSelected = [currentSet firstObject];
NSRange selectedRange; NSRange selectedRange;
if (firstSelectedIndex == NSNotFound) if (firstSelected == nil)
{ {
selectedRange = NSMakeRange(index, index); selectedRange = NSMakeRange(index, index);
} }
@ -982,21 +1001,22 @@ static NSString *placeholderItem = nil;
selectedRange = NSMakeRange(firstSelectedIndex, (index - firstSelectedIndex + 1)); selectedRange = NSMakeRange(firstSelectedIndex, (index - firstSelectedIndex + 1));
} }
[currentIndexSet addIndexesInRange: selectedRange]; [currentIndexSet addIndexesInRange: selectedRange];
[self setSelectionIndexes: currentIndexSet]; */
[self setSelectionIndexPaths: currentSet];
} }
} }
else else
{ {
[self setSelectionIndexes: [NSIndexSet indexSetWithIndex: index]]; [self setSelectionIndexPaths: [NSSet setWithObject: index]];
} }
[[self window] makeFirstResponder: self]; [[self window] makeFirstResponder: self];
} }
else else
{ {
[self setSelectionIndexes: [NSIndexSet indexSet]]; [self setSelectionIndexPaths: [NSSet set]];
} }
RELEASE (currentIndexSet);
*/ RELEASE (currentSet);
} }
@ -1707,16 +1727,6 @@ static NSString *placeholderItem = nil;
_allowsEmptySelection = flag; _allowsEmptySelection = flag;
} }
- (NSSet *) selectionIndexPaths
{
return _selectionIndexPaths;
}
- (void) setSelectionIndexPaths: (NSSet *)indexPaths
{
ASSIGN(_selectionIndexPaths, indexPaths);
}
- (IBAction) selectAll: (id)sender - (IBAction) selectAll: (id)sender
{ {
} }