Re: NSOutlineView autosaving of expanded/collapsed state
Re: NSOutlineView autosaving of expanded/collapsed state
- Subject: Re: NSOutlineView autosaving of expanded/collapsed state
- From: Jonathan Dann <email@hidden>
- Date: Sun, 24 Feb 2008 22:37:31 +0000
Hi Ralph,
Here's my code from an NSOutlineView subclass
- (NSArray *)expandedItems;
{
NSMutableArray *expandedItemsArray = [NSMutableArray array];
NSUInteger row, numberOfRows = [self numberOfRows];
for (row = 0 ; row < numberOfRows ; row++)
{
id item = [self itemAtRow:row];
if ([self isItemExpanded:item])
[expandedItemsArray addObject:[item representedObject]]; // create
an array of only the expanded items in the list
}
return [[expandedItemsArray copy] autorelease];
}
The returned array can then be archived.
It uses NSTreeNode and -representedObject, so is 10.5 only. For 10.4
there is an undocumented method for the private class that
NSTreeController used in 10.4 that does the same thing, can't remember
the method name but it's on Scott Stevenson's blog somewhere, just
Google theococoa.com and NSTreeController.
Passing the (now unarchived) array to the method below will expand
them again.
- (void)expandItems:(NSArray *)array;
{
NSUInteger row, numberOfRows = [self numberOfRows];
for (MyNode *savedItem in array) {
for (row = 0 ; row < numberOfRows ; row++) {
id item = [self itemAtRow:row];
MyNode *realObject = [item representedObject];
if ([realObject.nodeName isEqualToString:savedItem.nodeName]) {
[self expandItem:item];
numberOfRows = [self numberOfRows];
break;
}
}
}
}
Enjoy,
Jon
_______________________________________________
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