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:
Quentin Mathe 2010-01-16 20:29:59 +00:00
parent 6a9dfe8d61
commit 668fbe236a
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>
* Source/NSWindow.m: Don't use the flags for key/main window tracking.

View file

@ -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];
}
}