带有键盘快捷键的 SWT 操作...无需将它们添加到菜单
我们目前已经实现了很多 SWT 操作,因为它是绑定单个命令以添加到菜单栏和工具栏以及为这些命令提供键盘快捷键的好方法。
现在...如何在普通 SWT/JFace 中注册一个 Action,而不必将其添加到菜单栏,但仍然可以通过键盘快捷键调用它?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 org.eclipse.ui.bindings 扩展,并添加一个新密钥。
您分配序列(M1、M2、M3 和 M4 用于表示 Shift、Command 和 Alt 等键,具体取决于系统)。例如,我已将 Alt+D 指定为命令的组合键,因此我在序列字段中输入“M3+D”。
为了让您的按键绑定正常工作,您需要选择一个schemeId。您可以在绑定扩展下制作一个。只需为其分配一个 ID 即可。然后,您需要向“plugin_customization.ini”文件添加一个条目:
或者您可以只使用“org.eclipse.ui.defaultAcceleratorConfiguration”作为您的方案 ID,但这包括许多 Eclipse 的组合键,它们将覆盖您的组合键我认为。
您可以将 contextId 字段留空,它表示在这种情况下它将默认为 org.eclipse.ui.contexts.window。
最后,只需指定命令的 ID,就可以设置了!
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:
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!
我通常通过在
KeyDown
事件上使用Display.addFilter
在普通 SWT 中解决此问题。有关示例,请参阅此问题。I use to solve this in plain SWT by using
Display.addFilter
on theKeyDown
event. See this question for an example.