Need help for promised file drag/drop
Need help for promised file drag/drop
- Subject: Need help for promised file drag/drop
- From: "Ling Li" <email@hidden>
- Date: Tue, 30 Jan 2007 11:59:48 -0800
- Thread-topic: Need help for promised file drag/drop
Hi, all,
I am attempting to implement promised drag out of a source application that
will copy a BIG file to the drop location. My question is how can drag source
inform drop destination that copy is finished and drop can access the file? I
should also implementation drop destination.
Normally, the actual copy should be in the
namesOfPromisedFilesDroppedAtDestination: method and return the names of the
files copied. However, if I delayed the copy, the whole thing happens
asynchronously, so I have no way of ensuring that the files are created
before I return their names. In this case, the copy will take time and the
namesOfPromisedFilesDroppedAtDestination: method returns immediately. Then my
question is that how my drop destination can know that source finished the
file copy?
I ever tried this approach. Destination calls
namesOfPromisedFilesDroppedAtDestination multiple times with timer. Before
copy finished, source will return nil for file list. After copy finished, the
real file list will be return.
In drag source, the code is:
- (NSArray *)namesOfPromisedFilesDroppedAtDestination: (NSURL *)dropDest //
IN
{
if (copyStatus == 2) { // copy finished
return fileList;
}
if (copyStatus == 0) { // start copy
StartCopy();
}
return nil; // copying
}
In drop destination, the code is:
- (BOOL)performDragOperation: (id<NSDraggingInfo>)sender
{
NSURL *dropLocation = [NSURL URLWithString: [NSString
stringWithUTF8String: "/tmp"]];
NSArray *fileList = [sender
namesOfPromisedFilesDroppedAtDestination:dropLocation];
sourceDraggingInfo = sender;
if (!fileList) {
[NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:@selector(delayCopy:)
userInfo:nil
repeats:NO];
}
return YES;
}
- (void) delayCopy: (NSTimer *)timer
{
NSURL *dropLocation = [NSURL URLWithString: [NSString
stringWithUTF8String: "/tmp"]];
NSArray *fileList = [sender
namesOfPromisedFilesDroppedAtDestination:dropLocation];
sourceDraggingInfo = sender;
if (!fileList) {
[NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:@selector(delayCopy:)
userInfo:nil
repeats:NO];
} else {
ReadFiles();
}
}
Unfortunately this approach is not working. According to debug,
namesOfPromisedFilesDroppedAtDestination in source actually only got called
once, and any following calls in dest will return same result from that one
(in my case only nil, never get any true file list even after file copy
finished). Looks like the result from
namesOfPromisedFilesDroppedAtDestination will be cached, and I can not use
this function for dest to query if source finished file copy or not.
Is there any other way the destination can know when source finished file
copy?
Any suggestions are appreciated.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden