On 18 May 2008, at 23:57, Charles Srstka wrote:

On May 18, 2008, at 5:47 PM, Jonathan Dann wrote:

Not any more, the documentation may not have been updated yet. The header for NSTreeController says differently as of 10.5. It's always good to check the docs and the comments in the header file. (control double click on the word NSTreeController in your code to get to the header). You often find the odd method that's not in the docs too. File a radar if you do for any of the classes you use.

Glad to be of service, feel free to ask more.

Jon

Oh sweet, you are indeed correct. The header also mentions a - descendantNodeAtIndexPath: method I can send this object that will allow me to get the node at a given index path, which was another thing I was having trouble doing.

Thanks! :-)

Charles

Yeah that one's really useful. NSTreeController is so much easier to use in 10.5 but those extensions to NSTreeController NSTreeNode and NSIndexPath make it really simple to use.

You're welcome. These ones I didn't post but I use ALL the time too (note they call other methods in the sample project)

//NSTreeNode_Extensions (insipred by Apple's SourceView sample code)
- (NSArray *)descendants;
{
        NSMutableArray *array = [NSMutableArray array];
        for (NSTreeNode *item in [self childNodes]) {
                [array addObject:item];
                if (![item isLeaf])
                        [array addObjectsFromArray:[item descendants]];
        }
        return [[array copy] autorelease];
}

// NSTreeController_Extensions
- (void)setSelectedNode:(NSTreeNode *)node;
{
        [self setSelectionIndexPath:[node indexPath]];
}

- (void)setSelectedObject:(id)object;
{
        [self setSelectedNode:[self treeNodeForObject:object]];
}

- (NSArray *)flattenedSelectedNodes;
{
        NSMutableArray *mutableArray = [NSMutableArray array];
        for (NSTreeNode *treeNode in [self selectedNodes]) {
                if (![mutableArray containsObject:treeNode])
                        [mutableArray addObject:treeNode];
                if (![[treeNode valueForKeyPath:[self leafKeyPath]] boolValue]) 
{
[mutableArray addObjectsFromArray:[treeNode valueForKeyPath:@"descendants"]];
                }
        }
        return [[mutableArray copy] autorelease];
}

- (NSArray *)flattenedSelectedObjects;
{
return [[self flattenedSelectedNodes] valueForKey:@"representedObject"];
}

- (NSArray *)flattenedSelectedLeafNodes;
{
        NSMutableArray *mutableArray = [NSMutableArray array];
        for (NSTreeNode *treeNode in [self flattenedSelectedNodes]) {
                if ([[treeNode valueForKeyPath:[self leafKeyPath]] boolValue])
                        [mutableArray addObject:treeNode];
        }
        return [[mutableArray copy] autorelease];
}

- (NSArray *)flattenedSelectedLeafObjects;
{
return [[self flattenedSelectedLeafNodes] valueForKey:@"representedObject"];
}

- (NSArray *)flattenedSelectedGroupNodes;
{
        NSMutableArray *mutableArray = [NSMutableArray array];
        for (NSTreeNode *treeNode in [self flattenedSelectedNodes]) {
                if (![[treeNode valueForKeyPath:[self leafKeyPath]] boolValue])
                        [mutableArray addObject:treeNode];
        }
        return [[mutableArray copy] autorelease];
}


- (NSArray *)flattenedSelectedGroupObjects;
{
return [[self flattenedSelectedGroupNodes] valueForKey:@"representedObject"];
}

Jon

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to