开发者

How do I allow ⌘V into NSTextField without having a Menu?

开发者 https://www.devze.com 2023-04-04 02:10 出处:网络
I\'ve removed the menu from my cocoa app, all of the interaction should happen from within a status item, that links to a menu, that links to different NSPanels.But this seems to have removed the abil

I've removed the menu from my cocoa app, all of the interaction should happen from within a status item, that links to a menu, that links to different NSPanels. But this seems to have removed the ability to ⌘C or ⌘V within a NSTextField.开发者_如何学C Is there a way to add this back without having to have a standard menu included with my app?


Even if your app is a faceless background app, so it never shows a menu bar, you should still have a full main menu because that's what provides all of the default actions (and enables the user to redefine the key commands if they so choose). If you remove the main menu, you have to reimplement everything in it, including anything Apple adds in the future, in code.

And I'd especially warn you against trying to handle keyboard shortcuts yourself. That's damned tricky. A lot of applications get it wrong, causing us Dvorak users (among others) to curse their developers.


I assume you can just implement the actions originally connected to the menu items in a keyDown event. Check out this page for details: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html

Just have it respond to cmd-v with paste:, and cmd-C with copy:

Edit: Though I have to agree with Peter, you really should have a main menu...

0

精彩评论

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