Re: NSTreeController and insertObject:atArrangedObjectIndexPath:
Re: NSTreeController and insertObject:atArrangedObjectIndexPath:
- Subject: Re: NSTreeController and insertObject:atArrangedObjectIndexPath:
- From: Tony Romano <email@hidden>
- Date: Sat, 19 Jun 2010 12:19:59 -0700
Maybe I am missing the big picture here....
Something has to change in order to trigger the sequence of events. The UI is the outlineview, the controller is NSTreeController, and the store is the file system. The treecontroller stores objects that I have created to represent items in the store. Through bindings, the treecontroller asks for 2 things, my arranged list of items and getter/setter to respond from requests from the controller to update a child list.
The scenario this thread is about is the user decides via a context menu to add a node. I tried both case where I add the folder to the file system first then called insertObject or called insertObject then add the folder to the file system. In both cases, both the setter and the getter are called. There is no direct binding to the filesystem.
insertObject:atArrangedObjectIndexPath: requires I give it an object and an index path. So at a minimum, I have to create a blank node with some pertinent data . The object I created is a single node, not bound to anything at this point, just a pointer to a blob. When I make the call to insertObject, I expect two things to happen.
1. It adds this object to my arrangedObjects and then calls my setter telling me, "Hey there has been a change, here is the new child list".
2. Add it to the NSOutlineView. since they are bound to each other.
The controller does both of these. The problem is it ALSO calls the getter on the parent node of the indexPath provided and tells me to enumerate this node. If I updated the file system prior to calling insertObject, I would enumerate it and give the list back to the controller. Then, the insertObject code would proceed to add the newly created node, hence added twice in the child list. It seems like the controller lost track of the child list for this node and requested it again and perhaps this is where the problem is. I know for a fact it tracks child list otherwise the controller would enumerate the nodes every time the user opens a folder that had been previously opened.
I guess the scenario the controller is trying to protect itself from the user adding a new node to a child that has not been enumerated(makes perfect sense). In this case the node doesn't not have a child list and it would have to ask for it first. But it shouldn't call the setter in this case. Under all conditions it calls both, this is a bug.
Sorry for all the details.
-Tony
On Jun 19, 2010, at 6:22 AM, Clark S. Cox III wrote:
> You should only need add your object to your model (which needs to me KVO compliant). The tree controller will then notice, in response to the KVO notification that a new item was added.
>
> You should rarely, if ever, be direcly adding objects to the controller layer like this.
>
> Sent from my iPhone
>
> On Jun 18, 2010, at 18:53, Tony Romano <email@hidden> wrote:
>
>> Scenario: Adding a new node to a NSOutlineView backed by a NSTreeController.
>>
>> 1. Create a new internal object add add it to the data store(file system). This will be my representedObject in the treecontroller
>> 2. Compute the path and call insertObject:atArrangedObjectIndexPath:
>>
>> the treecontroller does 2 things during the call to insertObject:
>>
>> 1. It calls my getter, children, and asks me for all the children under the parent node I have added the new node to. I give it the list INCLUDING the newly created node since it is now in the store.
>> 2. Then it calls the setter, setChildren, and gives me the newChildren list. Which now has an additional copy of the new node, one from the getter call and one from the insertAt call. I know this for a fact because I purposely added some data to the newly created node for the insert to distinguish them.
>>
>> From the UI, the outlineview is correct, but my internal child list has the extra node. It's not displayed because the treecontroller optimizes when to ask me for a childlist. I have a work around which I don't like to basically lock out the getter method and just return the current child list(i.e the previous child list which doesn't have the new node added from the file system). Anyone experience this before and have a recommendation?
>>
>> TIA,
>> -Tony
>>
>> _______________________________________________
>>
>> 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
>
-Tony
_______________________________________________
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