简体   繁体   中英

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 ). 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. The drawback here is that whatever boldIt: is called on needs to know about the Font Manager as well.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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