Skip navigation.
 
mlRe: Starting window instead of a new untitled document?
FROM : PGM
DATE : Tue Aug 01 04:34:09 2006

> 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

Related mailsAuthorDate
mlStarting window instead of a new untitled document? James Bucanek Aug 1, 01:02
mlRe: Starting window instead of a new untitled document? Michael Nickerson Aug 1, 03:36
mlRe: Starting window instead of a new untitled document? James Bucanek Aug 1, 03:46
mlRe: Starting window instead of a new untitled document? PGM Aug 1, 04:34
mlRe: Starting window instead of a new untitled document? PGM Aug 2, 16:49
mlRe: Starting window instead of a new untitled document? [Simple SOLUTION] James Bucanek Aug 2, 20:23