Re: Restoring a NSTreeController selection
Re: Restoring a NSTreeController selection
- Subject: Re: Restoring a NSTreeController selection
- From: "email@hidden" <email@hidden>
- Date: Thu, 24 Jun 2010 09:35:20 +0100
On 24 Jun 2010, at 01:43, Markus Spoettl wrote:
> Hi List,
>
> I have a NSOutlineView bound to a NSTreeController that delivers my model objects. That NSTreeController sorts the model objects through sort descriptors. What I would like to do is save the current selection and restore it at a later time.
>
> Saving is easy, I get the -selectedObjects from the tree controller, extract my model objects and store a unique key that allows me to identify the objects when I look them up later.
>
> Restoring proves to be tricky - for me anyway. I can locate my model objects properly and build an index path for each one I want to select. However, the index paths the tree controller seems to expect is the one AFTER applying the sort order.
>
> My model is not sorted in the same way the tree controller's representation is. The only I can find out the correct (for selection) index paths is to sort my model like the tree controller does and find the index paths after that. That's terribly inelegant and potentially expensive. I think the tree controller should either accept -selectionIndexPaths the way I see them in my model OR let me see the ordered collection of how my model ended up being represented.
>
>
Maybe you know all this but:
1. NSTreeController items are subclasses of NSTreeNode (see the 10.5 release notes).
2. NSTreeController.h states
// proxy for the root tree node responds to -childNodes and -descendantNodeAtIndexPath:(NSIndexPath *)indexPath
- (id)arrangedObjects;
This presents the arranged objects as a tree of NSTreeNodes.
Your model is -representedObject.
You can walk this along -childNodes.
3. see NSTreeController-DMExtensions
wilshipley.com/blog/2006_04_01_archive.html
A category on NSTreeController that implements setSelectedObjects:
As it's a category on an external class I would prefix the category method names with something, like dm_, to avoid collisions in the future.
Regards
Jonathan Mitchell
Developer
Mugginsoft LLP
http://www.mugginsoft.com_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden