Why NSApplicationDelegate method openFiles: is being called multiple times on a multiple drag to the dock icon?
I've seen this behavior in one of my apps (usually when dragging a whole bunch of files at one time). As I workaround, instead of opening the files directly from application:openFiles:
, I queue them up and open the queued files after a small delay. Something like the following:
- (void) application:(NSApplication*)sender openFiles:(NSArray*)filenames{ // I saw cases in which dragging a bunch of files onto the app // actually called application:openFiles several times, resulting // in more than one window, with the dragged files split amongst them. // This is lame. So we queue them up and open them all at once later. [self queueFilesForOpening:filenames]; [NSApp replyToOpenOrPrint:NSApplicationDelegateReplySuccess];}- (void) queueFilesForOpening:(NSArray*)filenames{ [self.filesToOpen addObjectsFromArray:filenames]; [self performSelector:@selector(openQueuedFiles) withObject:nil afterDelay:0.25];}- (void) openQueuedFiles{ if( self.filesToOpen.count == 0 ) return; [self makeNewWindowWithFiles:self.filesToOpen]; [self.filesToOpen removeAllObjects];}