aneuryzm
aneuryzm

Reputation: 64834

Cocoa: drag and drop create problems to a modal window

I'm running a modal window (I've tried both beginModalSessionForWindow and runModalForWindow), after a drag drop in a NSTableView:

(BOOL)tableView:(NSTableView*)tableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation
{
   //launch modal window
}

However, a NSTextField of the modal window seems not being available (it is "locked", I can't type in it) until when I see a (mac OSX) animation of the file icon moving back to the file. Then it works.

I hope it is clear, it seems that the modal window is interrupting the drag-drop release.

Thanks

Upvotes: 0

Views: 284

Answers (1)

gaige
gaige

Reputation: 17471

The problem here is that the -tableView:acceptDrop:row:dropOperation: needs to return before the Run Loop intercedes for the modal window. Unfortunately, regardless of which method you use to put up the modal, it's going to change the Run Loop until the modal is gone, which means the system is going to think you still haven't resolved the drop. Eventually, it'll time out and the drop will spring back (which is what you're seeing).

One way to resolve this would be to send yourself a message to put up the window very soon after, but not in this Run Loop (using -performSelector:withObject:afterDelay:). Since you're already in the main thread, this will schedule a call back after your requested delay using a timer on the main thread, allowing you to respond.

Upvotes: 1

Related Questions