• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to implement drag-drop onto application icon
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to implement drag-drop onto application icon


  • Subject: Re: How to implement drag-drop onto application icon
  • From: email@hidden
  • Date: Sun, 12 May 2002 01:18:56 +0200

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];
}
}

Although I haven't tested, I think this code will not work as expected when several files are dropped on the "not yet launched" application. application:openFile: is called once for each file opened, so I think only the last one will be handled here.

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?

What you are trying to do is in fact already handled. Here is the non-exhaustive application initialization process:

...
- call applicationWillFinishLaunching:
- call application:openFile:
- call applicationDidFinishLaunching:
- application receive first event
...

This is well explained in the documentation of applicationDidFinishLaunching: of NSApplication (at least in April DevTools).

Simply rename your original applicationDidFinishLaunching: to applicationWillFinishLaunching:, and it should work fine.
--
Julien Dufour
_______________________________________________
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.
References: 
 >Re: How to implement drag-drop onto application icon (From: Kirk Kerekes <email@hidden>)

  • Prev by Date: Re: CICN resource into NSImage?...familyhandle
  • Next by Date: Re: SymLink duplicating troubles
  • Previous by thread: Re: How to implement drag-drop onto application icon
  • Next by thread: Re: Bundle identifiers - solution!
  • Index(es):
    • Date
    • Thread