检测活动NSDocument的焦点/不聚焦 [英] Detecting focus/unfocus of active NSDocument

查看:158
本文介绍了检测活动NSDocument的焦点/不聚焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否还有检测NSDocument的焦点/不聚焦?我想动态更新与活动文档相关的菜单项,但我看不到任何直接显而易见的方式。

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.

原因是, d喜欢激活,然后在文档焦点上填充菜单,然后在失去焦点时取消填充和停用。

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.

任何想法?

感谢,

推荐答案

看起来NSDocument设置为所有文档窗口的委托,因此NSDocument子类中需要的钩子是:

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

这篇关于检测活动NSDocument的焦点/不聚焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆