[for the archives - old thread]

This is a brute force mechanism to save the expanded NSOutlineView items prior to changing a Managed Object context and then restoring them after the modification.

- (id)expandedState
{
    NSMutableArray *state = [NSMutableArray array];
    NSInteger count = [outlineView numberOfRows];
    for (NSInteger row = 0; row < count; row++) {
        id item = [outlineView itemAtRow:row];
        if ([outlineView isItemExpanded:item])
        {
            [state addObject:[item representedObject] ];
        }
    }
    return state;
}

// brute force solution: for each object, do a full tree search for the NSTreeNode item...at least it works!
-(id)recursiveSearch:(id)object set:(NSSet *)set
{
    for (id item in set)
    {
        if ([item representedObject] == object) return item;

        NSSet *children = [item valueForKey:@"childNodes"];

        if ([children count]) {
            id ret = [self recursiveSearch:object set:children];
            if(ret) return ret;
        }
    }
    return nil;
}

- (void)setExpandedState:(id)state
{
    // Collapse everything first
    [outline collapseItem:nil collapseChildren:YES];

    for (id pobj in state) {
[outlineView expandItem:[self recursiveSearch:pobj set:[[treeController arrangedObjects] valueForKey:@"childNodes"]] ];
    }
}

David
_______________________________________________

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

Reply via email to