SWT Actions with Keyboard Shortcuts… without having to add them to the menu

女生的网名这么多〃 提交于 2019-12-10 17:42:07

问题


We currently have implemented a lot of SWT Actions, because it is a nice way to bind a single command to be added to the menubars and toolbars, and to have Keyboard Shortcuts for these commands.

Now... how can I register an Action in plain SWT/JFace without having to add it to a menubar, but in a way that it still can be called by a keyboard shortcut?


回答1:


I use to solve this in plain SWT by using Display.addFilter on the KeyDown event. See this question for an example.




回答2:


Use the org.eclipse.ui.bindings extension, and add a new key.

You assign the sequence (M1, M2, M3, and M4 are used to represent keys like Shift, Command, and Alt, depending on the system). For example, I have assigned Alt+D as my key combo for a command, so I entered "M3+D" in the sequence field.

To get your key binding to work, you'll need to pick a schemeId. You could make one under the bindings extension. Just assign it an ID. Then you need to add an entry to the "plugin_customization.ini" file:

org.eclipse.ui/KEY_CONFIGURATION_ID=your.binding.scheme.id

Or you could just use the "org.eclipse.ui.defaultAcceleratorConfiguration" as your scheme ID, but that includes a lot of Eclipse's key combos, which will override yours I think.

You can leave the contextId field blank, it says it will default to org.eclipse.ui.contexts.window in that case.

Finally, just specify the ID of your command, and you should be set!



来源:https://stackoverflow.com/questions/5244948/swt-actions-with-keyboard-shortcuts-without-having-to-add-them-to-the-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!