Re: Starting window instead of a new untitled document?
Re: Starting window instead of a new untitled document?
- Subject: Re: Starting window instead of a new untitled document?
- From: PGM <email@hidden>
- Date: Mon, 31 Jul 2006 22:34:09 -0400
I have a document-based Cocoa applcation that doesn't create
untitled documents (document windows can only be opened for
existing document files -- which are essentially databases -- and
can't exist without physical set of files).
So I've overridden newDocument: to create a file and overridden
applicationShouldOpenUntitledFile: to return NO so that a new
document isn't created when the user starts the application or
activates it via its dock icon.
But now I'd like to implement a "getting started" window that
prompts the user to create a new file or open an existing one. I
want this window to appear ONLY when the application is started
without opening an existing document. Searching the archives, the
advice has been to create this window in
applicationWillFinishLaunching:. But I don't want to see the window
every time. I only want it to appear if the application was
launched without a document to open.
What's the best way to approach this?
The way I do it (so not necessarily the best way) is as follows:
When a new document is created, loadDataRepresentation:ofType: is
called pretty early, so I implement this as follows:
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
dataFromFile = [data retain]; //(NSData *)dataFromFile is an
instance variable
return YES;
}
Then in windowControllerDidLoadNib, I do something like this:
if(dataFromFile){
//do something with the data
[dataFromFile release]; //if you don't need it anymore
}
else{
//popUp a dialog to set-up new document (I use a modal here)
}
The good thing is that at this point, the document window is not yet
visible, so there is no empty document to distract the user.
Best, Patrick
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden