I have an NSTreeController, working with an NSOutlineView, to traverse a privately mounted disk image.
The content of the NSTreeController points to a method that returns an array of strings, each being a full path to the file in the root of the mounted disk image..
I then added two categories to NSString:
subdirectories - takes the string path of the directory, and returns an array of paths to the files within that directory. isFile - takes the current path, and return boolean whether it is a file or a directory.
the "subdirectories" key is set to the "Children key path" of the NSTreeController. the "isFile" key is set to the "Leaf key path" of the NSTreeController. The "value" of the NSOutlineView is bound to the NSArrangedObjects. lastPathComponent.
This all works fine, and the NSOutlineView essentially displays the file names of the file structure of the mounted disk image. You can expand / contract the directories as you want.
Now I started adding support for dragging files onto the disk image thru the NSOutlineView. I registered it for accepting NSFilenamesPboardType, and added the following delegate methods:
// This added so we won't overwrite any existing files (index == -1) - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index { if(index >= 0) { return NSDragOperationCopy; } return NSDragOperationNone; }
// Determine where to drop the files - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index { NSPasteboard *pboard = [info draggingPasteboard]; NSArray *filePaths = [pboard propertyListForType:NSFilenamesPboardType]; NSEnumerator *fpEnum = [filePaths objectEnumerator]; NSString *path;
// Determine what directory path to copy the files to...
return YES; }
The problem is that the "item" object in this second method is a private object of type _NSArrayControllerTreeNode, so we can't (shouldn't) query it for the path string it represents.
Any suggestions on how we can determine what directory node we are dropping the file paths into?
Pat
|