From ec403f12960f74f04bd3ae87552a9830d69963f3 Mon Sep 17 00:00:00 2001 From: qmathe Date: Sat, 16 Jan 2010 20:29:59 +0000 Subject: [PATCH] Rewrote _selectColumn:modifiers: to be simpler, support selection by range as Cocoa does, and remove the toggle selection behavior when a column is clicked twice (in conflict with the ability to change the sort direction). git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29296 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 8 ++++ Source/NSTableView.m | 108 +++++++++++++++++-------------------------- 2 files changed, 51 insertions(+), 65 deletions(-) diff --git a/ChangeLog b/ChangeLog index 38c39101e..8a7be9dc1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-01-16 Quentin Mathe + + * Source/NSTableView.m (-_selectColumn:modifiers:): Rewrote to be + simpler, support selection by range as Cocoa does and to remove the + toggle selection behavior when a column is clicked twice. This toggle + behavior was in conflict with the ability to change the sort direction + by clicking in an already selected column header. + 2010-01-16 14:55-EST Gregory John Casamento * Source/NSWindow.m: Don't use the flags for key/main window tracking. diff --git a/Source/NSTableView.m b/Source/NSTableView.m index e76504e78..c97693c8e 100644 --- a/Source/NSTableView.m +++ b/Source/NSTableView.m @@ -2359,84 +2359,62 @@ static void computeNewSelection /* * And this when it gets a simple click which turns out to be for * selecting/deselecting a column. + * We don't support subtracting a column from the selection (Cocoa doesn't + * either). + * However we support adding a distinct column with the control key (unlike + * Cocoa where the user can only make column range selection). */ - - (void) _selectColumn: (int)columnIndex modifiers: (unsigned int)modifiers { - if (_allowsColumnSelection == NO) + NSIndexSet *oldIndexes = [self selectedColumnIndexes]; + BOOL addRange = ((modifiers & NSShiftKeyMask) + && _allowsMultipleSelection && [oldIndexes count] > 0); + BOOL addSingle = ((modifiers & NSControlKeyMask) + && _allowsMultipleSelection); + BOOL shouldSelect = ([self _shouldSelectionChange] + && [self _shouldSelectTableColumn: [_tableColumns objectAtIndex: columnIndex]]); + NSIndexSet *newIndexes = [NSIndexSet indexSetWithIndex: columnIndex]; + + if (_allowsColumnSelection == NO || shouldSelect == NO) { return; } - if ([self isColumnSelected: columnIndex] == YES) + if (_selectingColumns == NO) { - if (([_selectedColumns count] == 1) && (_allowsEmptySelection == NO)) - { - return; - } - - if ([self _shouldSelectionChange] == NO) - { - return; - } - - if (_selectingColumns == NO) - { - [self _setSelectingColumns: YES]; - } - - [self deselectColumn: columnIndex]; - return; + [self _setSelectingColumns: YES]; } - else // column is not selected + + /* Single select has priority over range select when both modifiers are pressed */ + if (addSingle) + { + [self selectColumnIndexes: newIndexes byExtendingSelection: YES]; + } + else if (addRange) { - BOOL newSelection; - - if ((modifiers & (NSShiftKeyMask | NSAlternateKeyMask)) - && _allowsMultipleSelection) - { - newSelection = NO; - } + NSUInteger firstIndex = [oldIndexes firstIndex]; + NSUInteger lastIndex = [oldIndexes lastIndex]; + NSRange range; + + /* We extend the selection to the left or the right of the last selected + column. */ + if (columnIndex > [self selectedColumn]) + { + lastIndex = columnIndex; + } else - { - newSelection = YES; - } + { + firstIndex = columnIndex; + } - if (([_selectedColumns count] > 0) && (_allowsMultipleSelection == NO) - && (newSelection == NO)) - { - return; - } - - if ([self _shouldSelectionChange] == NO) - { - return; - } - - { - NSTableColumn *tc = [_tableColumns objectAtIndex: columnIndex]; - if ([self _shouldSelectTableColumn: tc] == NO) - { - return; - } - } - - if (_selectingColumns == NO) - { - [self _setSelectingColumns: YES]; - } - - if (newSelection == YES) - { - /* No shift or alternate key pressed: clear the old selection */ - [self selectColumn: columnIndex byExtendingSelection: NO]; - } - else - { - /* Simply add to the old selection */ - [self selectColumn: columnIndex byExtendingSelection: YES]; - } + range = NSMakeRange(firstIndex, lastIndex - firstIndex + 1); + newIndexes = [NSIndexSet indexSetWithIndexesInRange: range]; + [self selectColumnIndexes: newIndexes byExtendingSelection: YES]; + } + else + { + [self selectColumnIndexes: newIndexes byExtendingSelection: NO]; } }