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
This commit is contained in:
qmathe 2010-01-16 20:29:59 +00:00
parent 83dac5cfec
commit ec403f1296
2 changed files with 51 additions and 65 deletions

View file

@ -1,3 +1,11 @@
2010-01-16 Quentin Mathe <quentin.mathe@gmail.com>
* 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 <greg.casamento@gmail.com> 2010-01-16 14:55-EST Gregory John Casamento <greg.casamento@gmail.com>
* Source/NSWindow.m: Don't use the flags for key/main window tracking. * Source/NSWindow.m: Don't use the flags for key/main window tracking.

View file

@ -2359,24 +2359,24 @@ static void computeNewSelection
/* /*
* And this when it gets a simple click which turns out to be for * And this when it gets a simple click which turns out to be for
* selecting/deselecting a column. * 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 - (void) _selectColumn: (int)columnIndex
modifiers: (unsigned int)modifiers modifiers: (unsigned int)modifiers
{ {
if (_allowsColumnSelection == NO) NSIndexSet *oldIndexes = [self selectedColumnIndexes];
{ BOOL addRange = ((modifiers & NSShiftKeyMask)
return; && _allowsMultipleSelection && [oldIndexes count] > 0);
} BOOL addSingle = ((modifiers & NSControlKeyMask)
&& _allowsMultipleSelection);
BOOL shouldSelect = ([self _shouldSelectionChange]
&& [self _shouldSelectTableColumn: [_tableColumns objectAtIndex: columnIndex]]);
NSIndexSet *newIndexes = [NSIndexSet indexSetWithIndex: columnIndex];
if ([self isColumnSelected: columnIndex] == YES) if (_allowsColumnSelection == NO || shouldSelect == NO)
{
if (([_selectedColumns count] == 1) && (_allowsEmptySelection == NO))
{
return;
}
if ([self _shouldSelectionChange] == NO)
{ {
return; return;
} }
@ -2386,57 +2386,35 @@ static void computeNewSelection
[self _setSelectingColumns: YES]; [self _setSelectingColumns: YES];
} }
[self deselectColumn: columnIndex]; /* Single select has priority over range select when both modifiers are pressed */
return; if (addSingle)
{
[self selectColumnIndexes: newIndexes byExtendingSelection: YES];
} }
else // column is not selected else if (addRange)
{ {
BOOL newSelection; NSUInteger firstIndex = [oldIndexes firstIndex];
NSUInteger lastIndex = [oldIndexes lastIndex];
NSRange range;
if ((modifiers & (NSShiftKeyMask | NSAlternateKeyMask)) /* We extend the selection to the left or the right of the last selected
&& _allowsMultipleSelection) column. */
if (columnIndex > [self selectedColumn])
{ {
newSelection = NO; lastIndex = columnIndex;
} }
else else
{ {
newSelection = YES; firstIndex = columnIndex;
} }
if (([_selectedColumns count] > 0) && (_allowsMultipleSelection == NO) range = NSMakeRange(firstIndex, lastIndex - firstIndex + 1);
&& (newSelection == NO)) newIndexes = [NSIndexSet indexSetWithIndexesInRange: range];
{ [self selectColumnIndexes: newIndexes byExtendingSelection: YES];
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 else
{ {
/* Simply add to the old selection */ [self selectColumnIndexes: newIndexes byExtendingSelection: NO];
[self selectColumn: columnIndex byExtendingSelection: YES];
}
} }
} }