[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More NSOutlineView bugs

From: Matt Rice
Subject: Re: More NSOutlineView bugs
Date: Mon, 05 Feb 2007 07:09:26 -0800
User-agent: GNUMail (Version 1.2.0)

On 2007-02-04 09:19:24 -0800 Guenther Noack <address@hidden> wrote:


Playing around with outline drag&drop, I found some other
selection-related issues in NSOutlineView:

- Inconsistency

The NSOutlineView method -noteNumberOfRowsChanged forgets about the
case where only one item is allowed to be selected. This leads to
inconsistencies within NSTableView which result in wrongly selected
rows in outline views. It can be fixed by adding this code snippet
before the -setFrame call:

if ([_selectedRows count] == 0) {
  _selectedRow = -1;
} else {
  _selectedRow = [_selectedRows lastIndex];

I really don't think that -noteNumberOfRowsChanged makes any sense for NSOutlineView because its a public method, and can be called seperate from -reloadData
at the beginning it goes

_numberOfRows = [_items count];

If -reloadData is not called... this doesn't go to the delegate to get the new number of rows well it really cant in any good way which would be more optimal than reloadData,
and I couldn't get this to do anything on a mac

- More inconsistency

The -reloadData method in NSTableView calls -noteNumberOfRowsChanged,
too. As the -noteNumberOfRowsChanged method restores the selected row
index set _selectedRows (and hopefully the _selectedRow index, too, soon)
from the _selectedItems instance variable, NSOutlineView's -reloadData
has to assign a suitable value to that as well.

To fix the bug, insert this at the beginning of -reloadData (before
_items is set to nil):

// We save the selection
[_selectedItems removeAllObjects];
int row = [_selectedRows firstIndex];
while (row != NSNotFound)
    if ([self itemAtRow: row])
        [_selectedItems addObject: [self itemAtRow: row]];
    row = [_selectedRows indexGreaterThanIndex: row];

This stuff doesn't seem to make sense to me, if the selected objects changes row indexes the selected row shouldn't jump around to the new row index where the selected object
now is...

attached is a patch which gets rid of _selectedItems,
and implements a private method to maintain the selected row index
not the selected objects.

BTW: The whole issue also applies to the -reloadItem:reloadChildren:
method. There's even a FIXME describing the problem.


Attachment: NSOutlineView.diff
Description: Text document

reply via email to

[Prev in Thread] Current Thread [Next in Thread]