My document-based app has a dock menu with a 'New Document' item. The dock menu is made in Interface Builder, its item's action is connected to 'First Responder's -newDocument:
The document controller is a subclass of NSDocumentController
called DocumentController
.
In the app delegate this code is used to prevent the opening of an untitled document upon launch (instead the document controller's open panel is shown) :
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender {
[(DocumentController *)[NSDocumentController sharedDocumentController] openDocument:self];
return NO;
}
If I now launch my app, it'll show the open panel instead of an untitled document. If I then click on the dock menu's 'New Document' item, no new document opens. If I click on the standard file menu option 'New Document' in the template main menu, a new document does open.
I can't think of a reason as to why this is so, can you? How do I get the dock menu to open a new document?
EDIT : Here is a sample project which has no NSDocumentController subclass but still has the same problem.
Menu item calls newDocument method on the document controller. If you click on the dock you trigger NSApplication stuff and it's delegate. E.g. if you have a existing app window than you will not get called there. No window will trigger applicationShouldOpenUntitledFile
In your document controller override like this:
And instead of responding to appdelegate(should bla bla) do this if you want after launch to display openPanel. If you want to trigger it when user clicks on the icon then do the second method