Search code examples
cocoainitializationdocument-based

Document Based Application, preinitialize window (enter serial, buy, trial)


I need to create several windows before NSDocument is loaded, or create a window that blocks NSDocument window and top menu.

I tried several solutions - but they didn't work right.

  1. modal window, one after another. there were some problems with Async URLConnection, and some other problems with my NSDocument content.

  2. I created custom MainMenu.xib with no menu, that opens my preinitialize windows. here i found some other problems, when a file(associated with my application) is opened - the Document Window initializes. Here i tried to subclass NSDocumentController, but i found no way to pause the "open document". (i want the document to be opened anyway, but only after the preinitalize windows would be closed).

So what is the right way to do this?


Solution

  • So the right answer is to implement:
    * application:openFiles:
    * applicationShouldOpenUntitledFile:

    and implement your own document creation. this is the way it worked for me.

    MyDocument* document = [[MyDocument alloc] 
                                 initWithContentsOfURL:fileURL 
                                                ofType:[fileName pathExtension] 
                                                 error:nil
                           ];
      if(document)
      {
         [[NSDocumentController sharedDocumentController] addDocument:document];
         [document makeWindowControllers];
         [document showWindows];
     }
    

    of course you need to write error handling code.