Cocoa Keyboard Shortcuts in Dialog without an Edit Menu

前端 未结 16 1289
Happy的楠姐
Happy的楠姐 2020-12-04 07:28

I have an LSUIElement application that displays a menubar status item. The application can display a dialog window that contains a text field.

If the u

16条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 08:01

    Just about 1 hour ago I stumbled upon the same problem. You don't need to code anything. I could do this in Interface Builder:

    • Create a menu (e.g. "Edit") which contains your Cut / Copy / Paste menu items
    • Add the KeyEquivalent for the CMD key to your "Edit" menu (don't know, if this is really needed, I just copied the structure from another project)
    • Add the KeyEquivalents to these menu items (CMD + X and so on)
    • Link the FirstResponder's cut:, copy: and paste: functions to your corresponding menu items

    That worked for me. Unfortunately this (default) behavior doesn't seem to work when you hide the "Edit" menu (just tried it).

提交回复
热议问题