Re: Document-based app - creating independent floating window
Re: Document-based app - creating independent floating window
- Subject: Re: Document-based app - creating independent floating window
- From: James Spencer <email@hidden>
- Date: Sat, 30 Oct 2004 10:42:12 -0500
On Oct 28, 2004, at 10:32 PM, Andrew White wrote:
Questions:
(1) How does NSDocumentController (the first responder for the main
menu) know to instantiate MathDocument.nib (rather than some other
NSDocument)?
First note that the nib is NOT the document. The document is your
subclassed NSDocument. You tell the default document controller which
type of document to create by specifying a your document's class name
in the Info.plist file which is most easily edited by editing the
target. If you have more than one document class, the default behavior
is to create a document of the class first listed in the plist.
The nib on the other hand essentially must be loaded, either explicitly
or implicitly, by you. From your description (sorry, I haven't build
MathPaper), you don't use a subclass of NSWindowController to control
the main window so you would load the nib by overriding your document's
-windowNibName method to return the name of your MathDocument. If you
do this, then the default behavior for the document will load the nib
and make the document the nib file's owner. If you have a subclassed
window controller or if your document has multiple nibs each with it's
own window then you would override your document's
-makeWindowControllers method and then in your window controller's
init method call NSWindowController's initWithWindowNibName: method
passing your nib file's name (without the .nib extension).
(2) In order to display the keypad, I figure I'm at some point going
to need to call [NSBundle loadNibNamed: @"Keypad.nib" owner: <owner>
]. Where does this call go? How do I link the 'keypad' menu item to
the code that contains this call? Do I subclass NSDocumentController
or is there a better place?
It sounds like there is only one keypad for the application and it
works on whatever is the main window. This being true, you should be
considering adding this behavior to the application in some way. At
the same time, you don't usually subclass NSApplication. Rather, you
create an application controller class (it can be a simple subclass of
NSObject) and implement your menu items' action in that class then set
that class to be your application's delegate. The easy way to do that
is to instantiate your controller class in the MainMenu nib, set the
MainMenu.nib's File Owner (which should be of class NSApplication)
delegate outlet to your instance and then connect the menu item's
action to your action method in the delegate. Note that you very very
rarely subclass NSDocumentController. You probably want to read the
documentation on document based applications pretty thoroughly as it
answers a lot of these questions.
(3) Finally, considering that the Keypad is in a different nib to the
document window, how do I get connect the keypad button press to the
main window? For now, I simply want the name of the button entered
into the main window.
Currently, the button press messages go to a keypad controller, which
then needs to pass them on to the main window. How (and who) do I ask
to find the identity of the main window?
Would it be easier to send a special message to the first responder?
You ask the application for the main window: [NSApp mainWindow];
James P. Spencer
Rochester, MN
email@hidden
"Badges?? We don't need no stinkin badges!"
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden