Folder Contents In NSOutlineView
Folder Contents In NSOutlineView
- Subject: Folder Contents In NSOutlineView
- From: Oliver Cameron <email@hidden>
- Date: Wed, 13 Oct 2004 19:11:34 +0100
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:
- (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:folderGroup
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. 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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden