views:

76

answers:

2

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?

A: 

Implement applicationShouldOpenUntitledFile: in your app delegate to return NO if the user has to go through the not-registered-yet dialog first.

In the action methods for your “Trial” and “Confirm Registration” buttons, create the untitled document yourself (by sending the necessary message to the document controller).

Peter Hosey
What about loading document by double clicking associated files? how to lock this? and how to save the (URL) to open it after not-registered-yet dialog?
Remizorrr
Implement `application:openFiles:`, too. Stash the paths in an array if the trial dialog is up, then, when it finishes (or if it is down), tell the document controller to open them for real.
Peter Hosey
if i catched files via NSApplication delegate (application:openFiles:). what should i do in this case to open thees files later with my NSDocument? (to transfer this action forward).
Remizorrr
As I said, send messages to the document controller. See the documentation for more details.
Peter Hosey
sorry for my newby questions. but only method in NSDocumentController i found is `-(id)openDocumentWithContentsOfURL:(NSURL )absoluteURL display:(BOOL)displayDocument error:(NSError *)outError` but i have no idea how i can use it. `addDocument:[[MyDocument alloc] init]` also dosen't create a window. can you tell me, what method exactly do you mean?
Remizorrr
Read the documentation for that method. The documentation tells you how to use it.
Peter Hosey
A: 

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.

Remizorrr