Overview:
I am implementing DnD using the NSOutlineview as my UI and the NSTreeController
as my "store front" to the file system. If none of the files exist at the drop
target both move and copy operations work fine. The case where there is a file
in the target that conflicts with one of the files in the source, I need to
remove both the file and the node in the controller. All the file operations
are happening on a another thread. Once I have determine which node needs to
be removed, I am doing a performSelectorOnMainThread to instruct the
treecontroller to remove the node. Note: The copy and move work this way as
well. The scenario I have outlined is really a special case in a move
operation that will remove the node at the target and continues as if it were a
simple move.
The issue is this, most of the time, removeObjectAtArrangedObjectIndexPath,
will NOT remove the code and I wind up with a duplicate in the tree at the
target drop point. The files in the filesystem are correct.
Here are some snippets of code:
// File Operations are complete at this time
if (rr == kReplaced_MacFileMoveOrCopy)
{
// We are doing a move and the target was both in the file system AND
the outlineview.
// At this point, the file got moved but we now need to remove it from
the tree so we can
// continue with a normal MOVE operation
// The node to remove will be under the targetItem in the treecontroller
NSMutableArray *targetItemChildren = [targetItem mutableChildNodes];
// I have also done this as well instead of the line directly above.
// NSArray * targetItemChildren = [targetItem childNodes];
// NSMutableArray * tc = [targetItemChildren copy];
// Create a temporary URL to retarget the URL we want to move, to have
the path of the destination node
NSURL * u = [[[targetItem representedObject] nodeURL]
URLByStandardizingPath];
NSURL * lookingForURL = [u URLByAppendingPathComponent:[[node nodeURL]
lastPathComponent]];
NSURL * lookingAtURL = nil;
for(NSTreeNode * childTn in targetItemChildren) {
lookingAtURL = [[childTn representedObject] nodeURL]
if ([lookingAtURL isEqual:lookingForURL] == YES) {
[self performSelectorOnMainThread:
@selector(removeNode:)
withObject:childTn waitUntilDone:YES];
break; // found it, we're done.
}
}
[targetItemChildren release];
}
// This function is call on the main thread
-(void)removeNode:(NSTreeNode *)tn
{
NSLog(@"Main Thread RemoveNode(%d)", [NSThread isMainThread]);
NSIndexPath *objPath = [tn indexPath];
[treeController removeObjectAtArrangedObjectIndexPath:objPath];
}
Does anyone have experience using an NSTreeController with an NSOutlineview in
this fashion and can shed some light on this? I've spent the better part of
the day looking at this. In all cases my internal nodes are correct by looking
at them from the debugger.
TIA,
-Tony
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]