I am working on a document-based Cocoa application. At startup, the user is presented with a "welcome panel" (of type NSPanel
) with buttons for common actions like "Create New Document" and "Open Existing Document". These actions are linked to the first responder's newDocument:
and openDocument:
actions, respectively, just like the matching items in the File menu.
Everything works as expected...with three caveats:
- The welcome panel is not dismissed when creating or opening a new document.
- Document windows do not have focus when they are created.
- Open document windows do not have the open file represented in the window title bar; likewise, new document windows do not get created with titles like "Untitled", "Untitled 2", "Untitled 3", etc., as expected. (I'm mentioning this not only because it's annoying, but because it may yield some insight into what's going wrong.)
I have partially solved #1 by making my application controller a delegate of the welcome panel. When clicking the "Open Existing Document" button, the panel resigns its key status (since a file browser dialog is being opened), so I can close the panel in the delegate's windowDidResignKey:
method. However, I can't figure out how to close the panel when creating a new document, since I can't find a notification that is posted, or a delegate method that is called, when creating a new document. And ultimately, #2 is still a problem, since the document windows don't gain focus when they're created.
I have only subclassed NSDocument
-- I'm not using a custom document or window controller at all. I've also tried changing the panel to an NSWindow
, thinking that an NSWindow
may behave differently, but the same problems are occurring.