Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Folder Contents In NSOutlineView

Folder Contents In NSOutlineView
Thread Tools
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Oct 13, 2004, 01:00 PM
 
Hey guys,

I'm having trouble of thinking out a way to put files/folders from a preset folder into a NSOutlineView, basically I can currently get a folders contents and put it all into a NSOutlineView, but the objects in the outline view are just single files and are not organized like it should be, in correct folders. Here is my current code:

Code:
- (void)processFolder:(NSString *)path { NSFileManager *fileManager = [NSFileManager defaultManager]; NSDirectoryEnumerator *fileEnumerator = [fileManager enumeratorAtPath:path]; NSString *fileString; while (fileString = [fileEnumerator nextObject]) { NSString *filePath = [path stringByAppendingString:fileString]; NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initWithPath:filePath]; if ([fileWrapper isDirectory]) { File *folderGroup = [[File alloc] initWithParent:rootProject withName:[filePath lastPathComponent] withPath:filePath withContents:nil isGroup:YES isDocument:NO]; [rootProject addFile:folderGroup]; [self processFolder:filePath]; } else { File *fileDocument = [[File alloc] initWithParent: rootProject withName:[filePath lastPathComponent] withPath:filePath withContents:[NSString stringWithContentsOfFile:filePath] isGroup:NO isDocument:YES]; [rootProject addFile:fileDocument]; } } [outlineView reloadData]; }
Basically what happens is I just get the path of the folder, use a NSDirectoryEnumerator to go through it and get all its contents, I then use NSFileWrapper to tell if a file is a folder, and if it is, add a File object as a folder, if its not, add it as a normal document. So I end up with a 1 level NSOutlineView with all the files and folders in a list. Ideally I'd like the correct files to be in the correct folders, but I just can't think of how to go about this. The parent of the file and where its added depends on where its added in the Outline View.

EDIT: I have seen the OutlineView.pbproj project, but its not what I would like. It basically does it all from inside the equivalent of my File class, but I'd like to keep the File class flexible, and I'd prefer to do all the processing in the controller class.

Any ideas appreciated,
Oliver
(Last edited by iOliverC; Oct 13, 2004 at 01:21 PM. )
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Oct 13, 2004, 09:05 PM
 
Look at OutlineView.pbproject again. That shows everything you need to know in order to do this. If you want to refactor the classes, you can do so, but all the tools you need are in that example. If you can't do it with your current class set, I don't know why you think what you have now is "flexible." What you need is some sort of tree like the sample code demonstrates. I don't know what more you expect us to tell you unless we're just supposed to write the code for you.
(Last edited by Chuckit; Oct 13, 2004 at 09:13 PM. )
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:15 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2