Re: Panels shared by documents
Re: Panels shared by documents
- Subject: Re: Panels shared by documents
- From: Itrat Khan <email@hidden>
- Date: Fri, 21 Jun 2002 17:18:50 -0400
On Friday, June 21, 2002, at 02:44 PM, Matt Neuburg wrote:
What is the most effective mechanism for a panel associating itself
with the current active document? [snip]
That's about right, but instead of listening to window activation
notifications, implement the panel's windowDidUpdate: delegate method,
query [NSApp mainWindow] to get the current document
How's that going to help? The panel's windowDidUpdate: delegate method
will
be called when the panel updates. But that's not what Brent needs to
know;
he needs to know when a different main document becomes active.
Every window is told to update on each pass of the event loop. When a
document window becomes active, the panel will be told to update on the
next iteration of the loop, where you can then update the panel's
outlets based on the active document.
It seems to me his original proposal to listen for window activation
notifications is
exactly right - this is just what notifications are for. Look, for
instance, at the shared panel in the Learning Cocoa book example; it
listens for an NSWindowDidBecomeMainNotification to learn what document
to
associate itself with. m.
I've seen this approach mentioned in a few places. The problem with it
is that you still need a way of refreshing the panel's outlets when the
model changes. You might tell the panel to update from your action
methods, but that prevents updates from AppleScript, undo, etc.; you
might listen to notifications from your model, but that becomes tedious
to manage over a large project.
Using windowDidUpdate: was first documented in the Programming with
OpenStep book in the Rhapsody releases. I admit I found the approach a
bit confusing at first, but have since found it to be quite simple and
very effective. I don't know where you'd find that book now, which is
unfortunate because it had some useful recipes.
Regards,
Itrat.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.