• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Outline View.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Outline View.


  • Subject: Re: Outline View.
  • From: Dave DeLong <email@hidden>
  • Date: Fri, 04 Dec 2009 08:31:18 -0700

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@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

References: 
 >Outline View. (From: Sandro Noël <email@hidden>)
 >Re: Outline View. (From: Graham Cox <email@hidden>)
 >Re: Outline View. (From: Sandro Noël <email@hidden>)

  • Prev by Date: Re: Best way to hook into the run loop?
  • Next by Date: Re: IKImageBrowserView D&D with IKImageBrowserNSDataRepresentationType
  • Previous by thread: Re: Outline View.
  • Next by thread: Best way to hook into the run loop?
  • Index(es):
    • Date
    • Thread