mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 07:00:37 +00:00
Fixed bug occurring when some rows were removed and some of them were
selected. New code checks for it and deals with it. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@9703 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
1f2c4400ab
commit
8e481799f9
1 changed files with 64 additions and 0 deletions
|
@ -2100,6 +2100,70 @@ byExtendingSelection: (BOOL)flag
|
|||
- (void) noteNumberOfRowsChanged
|
||||
{
|
||||
_numberOfRows = [_dataSource numberOfRowsInTableView: self];
|
||||
|
||||
/* If we are selecting rows, we have to check that we have no
|
||||
selected rows below the new end of the table */
|
||||
if (!_selectingColumns)
|
||||
{
|
||||
int i, count = [_selectedRows count];
|
||||
int row = -1;
|
||||
|
||||
/* Check that all selected rows are in the new range of rows */
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
row = [[_selectedRows objectAtIndex: i] intValue];
|
||||
|
||||
if (row >= _numberOfRows)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i < count && row > -1)
|
||||
{
|
||||
/* Some of them are outside the table ! - Remove them */
|
||||
for (; i < count; i++)
|
||||
{
|
||||
[_selectedRows removeLastObject];
|
||||
}
|
||||
/* Now if the _selectedRow is outside the table, reset it to be
|
||||
the last selected row (if any) */
|
||||
if (_selectedRow >= _numberOfRows)
|
||||
{
|
||||
if ([_selectedRows count] > 0)
|
||||
{
|
||||
_selectedRow = [[_selectedRows lastObject] intValue];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Argh - all selected rows were outside the table */
|
||||
if (_allowsEmptySelection)
|
||||
{
|
||||
_selectedRow = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We shouldn't allow empty selection - try
|
||||
selecting the last row */
|
||||
int lastRow = _numberOfRows - 1;
|
||||
|
||||
if (lastRow > -1)
|
||||
{
|
||||
[_selectedRows addObject:
|
||||
[NSNumber numberWithInt: lastRow]];
|
||||
_selectedRow = lastRow;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* problem - there are no rows at all */
|
||||
_selectedRow = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[self setFrame: NSMakeRect (_frame.origin.x,
|
||||
_frame.origin.y,
|
||||
_frame.size.width,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue