Inserting node in an OutlineView bound to a TreeController and preserve expanded items
Inserting node in an OutlineView bound to a TreeController and preserve expanded items
- Subject: Inserting node in an OutlineView bound to a TreeController and preserve expanded items
- From: Olivier Lance <email@hidden>
- Date: Mon, 9 Feb 2009 19:29:08 +0100
Hi everybody,
I know this subject has seen many entries in this mailing list (or others),
but I couldn't find any answer solving my own problem... I'm must also admit
that I'm quite new to Cocoa development, so I may have seen the solution but
not succeeded in applying it. Sorry if that's the case !
Here is the context of my problem :
I'm implementing a finder-like application, quite basic at the moment. The
folders are seen on the left in a single-column NSOutlineView, while the
files display on the right in an NSTableView.
I use bindings with an NSTreeController as a data source for my OutlineView,
as follows :
• OutlineView.content ===== bound to =====> TreeController.arrangedObjects
and
• TreeController.contentArray ===== bound to =====>
ImportModule.currentPlugin.children
Just to be clear about the latter, "ImportModule" is an object managing
importation plugins, which have a "children" method returning a NSArray of
nodes. These nodes then as well have a children and isLeaf methods which are
set as the childrenKeyPath and leafKeyPath of the TreeController.
I'm currently working on a basic FileSystem Plugin, for which children
returns all the available volumes, and then each volume returns the
directories it contains and so on.
Everything's working fine for volumes/directories listing.
The problem is, I want to refresh my content array if a volume is mounted or
unmounted, to keep my tree synchronized with the system.
I registered for the mount/unmount notification, but now I'm not really sure
what to do to have my application behaving properly. Here is the basic code
I tried in the first place for the mount notification :
- (void) mountNotification:(NSNotification*)notification
{
NSLog(@"Mounted %@", [[notification userInfo] valueForKey:@"NSDevicePath"
]);
[self willChange:NSKeyValueChangeInsertion valuesAtIndexes:[NSIndexSet
indexSetWithIndex:0] forKey:@"children"];
[self didChange:NSKeyValueChangeInsertion valuesAtIndexes:[NSIndexSet
indexSetWithIndex:0] forKey:@"children"];
}
I'm aware I'm not explicitly doing any change between the two calls, but as
I had specified NSKeyValueChangeInsertion I expected the data to be
refreshed only on the new node added when returning from
currentPlugin.children. Instead, the TreeController do call
currenPlugin.children but the entire tree is refreshed in the OutlineView,
and even though I've checked the "Preserve selection" attribute in IB, I'm
loosing the expanded items (in fact if the expansion is "deep" enough, it
seems random items are being expanded).
So I bet I'm missing something here. How can I tell my TreeController and/or
OutlineView only to insert the new item instead of refreshing the entire
view ?
If this cannot be done, how could I efficiently preserve the expanded items
?
I was thinking of making the ImportModule (which has an outlet to the
OutlineView/TreeController) observe when willChange:valuesAtIndexes:forKey: and
get didChange:valuesAtIndexes:forKey: called and save/restore those states
here. Is this a correct solution ? What should I observe exactly ?
Thanks a lot for any help or hint !
Olivier
_______________________________________________
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