Re: Current Document
Re: Current Document
- Subject: Re: Current Document
- From: SWC <email@hidden>
- Date: Wed, 17 Oct 2001 08:44:28 -0400
Ah, thanks to those who answered, I have it working properly. I had
considered first responder, but had forgotten that if the message wasnt
handled by the window that it would get passed along the responder
chain. Not enough time spent working with it, I suppose. I won't
forget again.
Thanks!
Spencer
On Wednesday, October 17, 2001, at 05:06 AM, Rainer Brockerhoff wrote:
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)
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev