Re: nsdocument/nsapp delegate question
Re: nsdocument/nsapp delegate question
- Subject: Re: nsdocument/nsapp delegate question
- From: Alex Rice <email@hidden>
- Date: Tue, 2 Oct 2001 01:18:59 -0600
On Monday, October 1, 2001, at 11:45 PM, John C. Randolph wrote:
Where I'm stuck is that I need find out in
applicationWillFinishLaunching: whether or not the app was launched
via a document or via the app. But, application:openFile: is not sent
until after applicationWillFinishLaunching: and by the time
applicationDidFinishLaunching: is sent, there is already an untitled
document opened automatically. How else can I check how the app was
launched via a document?
I think you can get the behaviour you describe just by implementing
-applicationShouldOpenUntitledFile: in your app delegate. That
shouldn't get called until the app is finished launching.
Thanks- at first I didn't think that -applicationShouldOpenUntitledFile:
was the answer, however with some judicious setting of flags to see if
the app is finishing launching, and if another document has been loaded
already, I've got it working:
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
{
if(! launching) // don't interfere w/ normal use of untitled files
return YES;
if((! hasOpenedDocument) &&
(! [[NSUserDefaults standardUserDefaults]
boolForKey:@"loadPreviousDocumentOnStartup"]))
{
return YES;
}
return NO;
}
This works, but my cocoa sense expected to find a method like [NSApp
wasLaunchedByDocumentIcon] or somesuch.
Thanks,
Alex Rice <email@hidden>
Mindlube Software
http://www.mindlube.com/