views:

16

answers:

1

Hi,

Is there anyway to detect the focus/unfocus of an NSDocument? I would like to dynamically update a menu item that pertains to the active document but I can't see any immediately obvious way of doing it.

The reason being, I'd like to activate and then populate the menu on document focus, and then unpopulate and deactivate on loss of focus.

Any ideas?

Thanks,

+1  A: 

It appears the NSDocument is set as the delegate for all the document windows, and so the hooks required in my NSDocument subclass were:

- (void) windowDidBecomeMain: (NSNotification *) notification
{
    NSLog(@"windowDidBecomeMain:");     
}


- (void) windowDidResignMain: (NSNotification *) notification
{
    NSLog(@"windowWillResign:");        
}


- (void) windowWillClose: (NSNotification *) notification
{
    NSLog(@"windowWillClose:");
}
Tricky
This is what I use as well.
Leibowitzn