Re: Current Document
Re: Current Document
- Subject: Re: Current Document
- From: Rainer Brockerhoff <email@hidden>
- Date: Wed, 17 Oct 2001 07:06:02 -0200
At 22:24 -0700 on 16/10/2001, email@hidden wrote:
>
Date: Wed, 17 Oct 2001 00:40:43 -0400
>
From: SWC <email@hidden>
>
>
I'm writing my first multi-doc application, and think I have a pretty
>
good grasp on most of the process, but am getting slightly hung up on
>
messages which are to be routed to the current doc, whatever that may
>
be. As an example, I have a command in the MainMenu.nib file which I
>
want to get passed to the currently selected document.
If by "selected" you mean the one whose window is on top, just connect the menu command to "First Responder". It gets routed to the top window, and if the window doesn't handle it, it's owner (which should be your NSDocument subclass) automatically.
If you did this and it isn't working, you're probably messing the owner connection up somehow. I did this for my first NSDocument app. Single-stepping through the code for document and window creation usually shows where you go wrong.
>
I notice that the DocumentController class has a currentDocument method
>
which seems to be what I'm looking for, but I am having trouble figuring
>
out how to get ahold of the document controller. Is this the wrong way
>
to go?
Yes, for most purposes you don't need to get the controller itself, unless you need a list of all open documents or something like that. In any event, to get the controller(s) from the document do something like:
NSArray* controllers = [mydocument windowControllers];
which will get you a list the window controllers for the document. It's a list because you may have more than one window per document.
To get the controller from the window, do:
NSWindowController* controller = [mywindow windowController];
>
I also see that NSApp provides a mainWindow method and a
>
ketWindow method, but I dont see how to get from a given window, to the
>
NSDocument it belongs to.
NSDocument* mydocument = [[mywindow windowController] document];
>
Could someone help me out here? It seems this should be really
>
straightforward, as the need for this must come up fairly often. Am I
>
overlooking something obvious?
Plan on 1 or 2 months of obviously not knowing what's obvious or not, even when looking at it. :-)
--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"Originality is the art of concealing your sources."
http://www.brockerhoff.net/ (updated Oct. 2001)