Re: How to implement drag-drop onto application icon
Re: How to implement drag-drop onto application icon
- Subject: Re: How to implement drag-drop onto application icon
- From: Kirk Kerekes <email@hidden>
- Date: Sat, 11 May 2002 15:49:05 -0500
From: Ondra Cada <email@hidden>
On Saturday, May 11, 2002, at 01:47 , Kirk Kerekes wrote:
So what does NSApplication do with a file/files dropped on the icon, and
how to I grab them?
See NSApplication delegate methods.
When app is launched by dragging an object onto its icon, beware: I kind
of recall there was somewhat weird order of delegate methods called, but
to be frank, I can't remember just now what the problem is (perhaps
applicationDidFinishLaunching called too late?).
Thanks for the pointer -- saved me hours of poking around.
Here are the specifics: NSApplication calls its delegate's openFile: method
when the file is dropped on the application icon. So in IB I set the
NSApplication's delegate to my controller object.
If the application is already running, this is nothing special, but if not,
the situation complicates.
If the application is not already running, the openFile: call happens
before the application has finished its internal setup. I don't know what
you can/cannot do at that point, and I prefer not to find out. So I also
implement the following two delegate methods:
- (BOOL) application: (NSApplication *) app openFile:(NSString *) file
{
// some kind of sanity checking on the file ought to go here.
[self setDroppedFileName:file];
[self setHasDroppedFile:YES];
if([app isRunning]) // event loop is running, actually.
{
[self openDroppedFile]; // uses instance variable set above
}
return YES; // simplistic, arbitrary choice on my part.
}
// This could be done via a notification, but I am already the delegate, so
why bother?
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
if([self hasDroppedFile])
{
[self openDroppedFile];
}
}
This seems both needlessly clumsy and needlessly obscure -- in my
reasonably ignorant opinion, NSApplication ought to wait to ship off
openFile: until it is ready to deal with the consequences. Wouldn't
implementing openFile: as a notification using NSNotificationQueue resolve
the issue?
But what do I know -- I'm still looking things up in Hillegass.
Thank goodness for Cocoa Browser, especially given the unpredictable
behavior of the option-double-click reference look-up in the April
developer tools.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.