Re: Folder Contents In NSOutlineView
Re: Folder Contents In NSOutlineView
- Subject: Re: Folder Contents In NSOutlineView
- From: Oliver Cameron <email@hidden>
- Date: Wed, 13 Oct 2004 19:22:30 +0100
Oops. one little code change, this line:
File *fileDocument = [[File alloc] initWithParent:folderGroup
withName:[filePath lastPathComponent] withPath:filePath
withContents:[NSString stringWithContentsOfFile:filePath] isGroup:NO
isDocument:YES];
Should be:
File *fileDocument = [[File alloc] initWithParent:rootProject
withName:[filePath lastPathComponent] withPath:filePath
withContents:[NSString stringWithContentsOfFile:filePath] isGroup:NO
isDocument:YES];
With the parent name changing.
Sorry about that :-)
Oliver
On 13 Oct 2004, at 19:11, Oliver Cameron wrote:
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
_______________________________________________
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