开发者

Detecting focus/unfocus of active NSDocument

Is there anyway to detect the focus/unfocus of an NSDocument? I would like t开发者_如何学运维o 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,


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:");
}


The above solution didn't work, this did:

I have a window controller (subclassing NSWindowController) and I add a delegate on the window

-(void)windowDidLoad {
    [super windowDidLoad];
    self.window.delegate = self;
}

-(void)windowDidBecomeKey:(NSNotification *)notification {
    // this gets called
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜