Re: Binding InfoPanel to currentDocument
Re: Binding InfoPanel to currentDocument
- Subject: Re: Binding InfoPanel to currentDocument
- From: Seth Willits <email@hidden>
- Date: Thu, 25 Oct 2012 09:42:49 -0700
On Oct 25, 2012, at 4:36 AM, Gerriet M. Denkmann wrote:
> This works, but I have a strong feeling that there is a very obvious better solution which I somehow cannot see.
There actually isn't an obvious solution.
-[NSDocumentController currentDocument] isn't KVOable (which is a bummer), but in theory you can register for notifications whenever the main window changes and you can look at currentDocument to see if it changed.
However, in practice (I was just testing this to be sure my advice was going to be good) and it seems that even though a document window is main and the application is active, -currentDocument can return nil in some cases. For example, activate another app and then click back onto a document window and applicationDidBecomeActive fires but currentDocument is nil, then windowDidBecomeMain fires but currentDocument is still nil. If you click on the app icon in the Dock the notifications are reversed and currentDocument isn't nil.
So, you can't really use -currentDocument because it seems it's not always first to get the notification that the main window (and thus currentDocument) has changed.
But, if you just use the -object in the notification to windowDidBecomeMain: you're fine. So if you keep a reference to that window/document yourself and return it from your own currentDocument that'd work. You also need to watch windowWillResignMain: windowWillClose: and optionally(?) applicationDidBecomeActive: (And actually, this is how Omni has been doing it for yeeeears.)
--
Seth Willits
_______________________________________________
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