Re: NSTreeController and insertObject:atArrangedObjectIndexPath:

2010-06-19 Thread Tony Romano
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  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 (Cocoa-dev@lists.apple.com)
>> 
>> 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:
>> http://lists.apple.com/mailman/options/cocoa-dev/clarkcox3%40gmail.com
>> 
>> This email sent to clarkc...@gmail.com
> 

-Tony

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 Sub

Re: NSTreeController and insertObject:atArrangedObjectIndexPath:

2010-06-19 Thread Clark S. Cox III
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  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 (Cocoa-dev@lists.apple.com)
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/clarkcox3%40gmail.com
> 
> This email sent to clarkc...@gmail.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSTreeController and insertObject:atArrangedObjectIndexPath:

2010-06-19 Thread Michael Babin
On Jun 18, 2010, at 5:53 PM, Tony Romano 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?

I will qualify this by saying that I don't have much direct experience with 
using NSTreeController.

In this case, it appears that the problem is that you are effectively adding 
the new object twice. Your step 1 adds it directly to your model. If this was 
done in a KVO compliant way, then the NSTreeController should take note of the 
change and update the NSOutlineView for you (making step 2 unnecessary). 
Alternatively, you could add the new object to your model through the 
NSTreeController (your step 2) and omit step 1.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSTreeController and insertObject:atArrangedObjectIndexPath:

2010-06-18 Thread Tony Romano
I solved this my not adding the file to the store until after the insert is 
completed in the controller.  The side effect is if the file system operation 
fails, I have to back out the node inserted into the tree which seems 
counterintuitive(i.e. I should only add the node if the model successfully has 
the data). It still calls both the getter and the setter within this one call.  
This has to be is a bug and I will file it.  It should only call the setter.

-Tony

On Jun 18, 2010, at 3:53 PM, Tony Romano 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 (Cocoa-dev@lists.apple.com)
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/tonyrom%40hotmail.com
> 
> This email sent to tony...@hotmail.com
> 

-Tony

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSTreeController and insertObject:atArrangedObjectIndexPath:

2010-06-18 Thread Tony Romano
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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com