On 26 Oct 2012, at 01:11, Seth Willits <[email protected]> wrote:

> 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.

Strange. 
I thought that having some InfoPanel which shows data of the current NSDocument 
would be a fairly common scenario.
But anyway. 

I decided to follow your suggestions.

My app delegate now has:
@property (strong) GmdDocument *currentDocument;

In applicationDidFinishLaunching: it registers for 
NSWindowDidBecomeMainNotification and NSWindowWillCloseNotification (not for 
NSWindowDidResignMainNotification because I want my InfoPanel to keep it's data 
when some other app becomes active).

The notification method is:

- (void)someWindowChanged: (NSNotification *)noti
{
        NSWindow *window = [ noti object ];

        if ( ![ window isMemberOfClass: [ NSWindow class ] ] ) return;  //      
ignore non-Windows

        NSWindowController *windowController = [ window windowController ];
        if ( windowController == nil ) return;  //      ignore strange windows

        GmdDocument *document = [ windowController document ];
        if ( ![ document isKindOfClass: [ GmdDocument class ] ] ) return;       
//      ignore strange documents

        if ( [ [ noti name ] isEqualToString: NSWindowWillCloseNotification ] ) 
document = nil;          
                 
        self.currentDocument = document;
}

The InfoPanel binds it's things through File's Owner: currentDocument.

Seems to work perfectly now.

Thanks a lot for your help!


Kind regards,

Gerriet.


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to