Here's one I created in about 10 minutes:  Create a regular Cocoa app, drop an 
outline view into the window, and hook it up to the AppDelegate for its 
datasource and its delegate.

The following four methods will allow you to walk your entire file hierarchy.  
Yes there's a memory leak, and this probably isn't the smartest way to be doing 
stuff, but the point is to show how it works.  =)

- (NSInteger)outlineView:(NSOutlineView *)outlineView 
numberOfChildrenOfItem:(id)item {
        if (item == nil) { return 1; }
        BOOL isDir = NO;
        if ([[NSFileManager defaultManager] fileExistsAtPath:item 
isDirectory:&isDir] && isDir == YES) {
                return [[[NSFileManager defaultManager] 
contentsOfDirectoryAtPath:item error:nil] count];
        }
        return 0;
}

- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index 
ofItem:(id)item {
        if (item == nil) { return @"/"; }
        NSArray * children = [[NSFileManager defaultManager] 
contentsOfDirectoryAtPath:item error:nil];
        //this has to be a retained object, otherwise the item will be 
destroyed on the next runloop cycle
        return [[item stringByAppendingPathComponent:[children 
objectAtIndex:index]] retain];
}

- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
        BOOL isDir = NO;
        if ([[NSFileManager defaultManager] fileExistsAtPath:item 
isDirectory:&isDir] && isDir == YES) { return YES; }
        return NO;
}

- (id)outlineView:(NSOutlineView *)outlineView 
objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
        return [[NSFileManager defaultManager] displayNameAtPath:item];
}

Enjoy!

Dave

On Dec 3, 2009, at 9:37 PM, Sandro Noël wrote:

> On 2009-12-03, at 11:07 PM, Graham Cox wrote:
>> 
>> http://apptree.net/gcfolderbrowser.htm
>> 
>> 
>> hth,
>> 
>> --Graham
>> 
> Graham thanks for the link, 
> the component is deprecated thow.
> but it's a good enough example.

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

_______________________________________________

Cocoa-dev mailing list ([email protected])

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