简体   繁体   English

急救人员遇到麻烦

[英]Trouble with First Responder

I've had some trouble implementing some shortcuts in a document based application (ie Bold, Italic etc) available here: 我在此处提供的基于文档的应用程序中(例如粗体,斜体等)实现一些快捷方式时遇到了一些麻烦:

Connecting Menu Items in Document Based Applications 在基于文档的应用程序中连接菜单项

The issue is that the method described disconnects the actual 'Bold' menu item from the Font Manager, and replaces it with my action I created (in this case, boldIt ). 问题在于所描述的方法将实际的“ Bold”菜单项与“字体管理器”断开连接,并将其替换为我创建的动作(在本例中为boldIt )。 Because there can be only one sent action, it is replaced, not added. 因为只能有一个已发送的操作,所以它被替换而不是添加。 How can I overcome this? 我该如何克服? Very frustrating. 非常沮丧。 If anyone can help me I would greatly appreciate it. 如果有人可以帮助我,我将不胜感激。

Zach 扎克

Since you can't have a menu trigger two actions, there's two good ways to approach this: 由于您不能让菜单触发两个动作,因此有两种方法可以解决此问题:

1) Have your boldIt: action call the appropriate method in the NSFontManager when it's done with it's work. 1)让你的boldIt:行动呼吁在适当的方法NSFontManager当它完成它的工作。 The drawback here is that whatever boldIt: is called on needs to know about the Font Manager as well. 这里的缺点是,无论boldIt:还是需要知道字体管理器。

2) Subclass NSFontManager and override addFontTrait: to include your desired behaviour when 'Bold' is selected, and then call the original method on the super class with [super addFontTrait:sender] . 2)子类NSFontManager并重写addFontTrait:在选择“ Bold”时包含您想要的行为,然后使用[super addFontTrait:sender]在超类上调用原始方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM