Re: NSOutlineView: removing the selected items, what's the easy way?
Re: NSOutlineView: removing the selected items, what's the easy way?
- Subject: Re: NSOutlineView: removing the selected items, what's the easy way?
- From: Brian Webster <email@hidden>
- Date: Mon, 8 Jul 2002 17:25:04 -0500
Whenever I've implemented a delete functionality in an
NSOutlineView, I've always made sure that each item had a
pointer to its parent. This might not work in some situations,
like if your outline is actually representing a graph and not a
tree, and thus some items could have more than one parent. It's
definitely the simplest way, if applicable.
If tagging items with their parents isn't possible, you could
cut down your search time a little bit by using NSOutlineView's
levelForRow: or levelForItem: methods. For each selected row,
you can iterate upwards in the table until you find an item
whose level is one less than the selected item, and you've found
the parent. This may be faster or slower depending on the
expansion state and number of items in the outline, but I think
it would be faster in the worst case scenario.
One other thing I've done to make life simpler when selecting
items in an outline view is to only allow selections of items
that all have the same parent. I had to subclass NSOutlineView
and override selectRow:byExtendingSelection: in order to do it
correctly, but it meant that I only ever had to deal with
deleting items from a single parent, not to mention cases where
both an item and its parent are selected at the same time.
Hope this helps...
On Monday, July 8, 2002, at 04:20 PM, cocoa-dev-
email@hidden wrote:
Hi there,
I have an NSOutlineView and want to allow the user to remove the
selected items.
Using the enumerator method I get the indices of the selected rows, but
these indices refer to the visible index, and thus vary
depending on the
which items are collapsed/expanded.
Either I go through the NSOutlineView's items while also traversing my
own datastructure, and remove items when I find a match (O(n) granted
the enumerator outputs the indices in ascending order), or I
convert the
indices to item pointers and search for each (O(m*n) where m is the
number of selected items) -- I need to search because it's a
hierarchical datastructure -- alternatively I could tag each item with
it's parent, so that it coudl be removed without the search, but I
dislike this overhead.
So I'd be interested to hear how others handle this rather simple
problem, which unfortunately have turned out to involve quite a lot of
code... maybe I should just tag my items, as it's only a constant
overhead...
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.