Re: Convert a per-doc window to inspector?
Re: Convert a per-doc window to inspector?
- Subject: Re: Convert a per-doc window to inspector?
- From: Quincey Morris <email@hidden>
- Date: Fri, 2 Oct 2009 16:15:54 -0700
On Oct 2, 2009, at 15:20, Rick Mann wrote:
I have a window and controller that get instantiated per-document,
and there's some confusion when multiple documents are open as to
which of these windows belongs to which document.
I'm considering changing it to behave like an inspector window,
where a single window changes its content to reflect the selected
document. Currently, the window UI elements bind to objects in the
document's Managed Object Context, via the window controller's
document property (actually, I'm not sure how that's getting set on
this controller in the first place, but it seems to work).
It happens a result of -[NSDocument addWindowController:] being called
for the window controller. This happens explicitly in your document
subclass's 'makeWindowControllers', if you've overridden it, or
implicitly if you're supplying 'windowNibName' to get your initial
window controller created for you.
I figure I need to disassociate the window controller from any
specific document, and then switch the context it uses when doc
windows become active. But I don't really know the right place/way
to do that. Is there a way for a responder subclass to know it's now
"active" (in the responder chain)? Is there a completely different
approach I should use? Will the UI update properly when I change the
MOC?
There are two easy avenues of approach. One is to use
NSDocumentController's "currentDocument" (though I don't know if its
KVO compliance can be relied on, so that might make detecting a change
a bit more complex). The other is to implement the NSWindow delegate
methods "windowDidBecomeMain:" and "windowDidResignMain:" in your
document window controller, and track the changes yourself (also
dealing with the situation when there's no main window or your
application becomes inactive).
Once you have current document detection under control, it's
straightforward for your inspector window to keep track of which
window controller, and hence which document, it's associated with.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden