开发者

How to un-set a keybinding for a particular locale

开发者 https://www.devze.com 2023-01-10 16:23 出处:网络
I have an Eclipse plugin that make开发者_运维问答s use of several keybindings (Alt-G x, Alt-G y, etc...).For most keyboard layouts, there are no problems for these specific keybindings.However, for Sw

I have an Eclipse plugin that make开发者_运维问答s use of several keybindings (Alt-G x, Alt-G y, etc...). For most keyboard layouts, there are no problems for these specific keybindings. However, for Swiss German, it turns out that 'Alt-G' creates '@' and this makes it very hard for Swiss Germans to use the plugins I created. I do not want to change the current keybindings since this would confuse existing users.

My question is:

How can I programmatically detect that a user is on a Swiss German keyboard and programmatically disable (or change) those keybindings?

(Is this something I can specify in the plugin.xml?)


To answer my own question, you can use the org.eclipse.ui.bindings extension point to completely solve the problem.

First, you set a keybinding as you normally would, and then you can un-set that particular keybinding on a single locale. And for that locale only, you can re-set the binding to something different.

This works, but is unfortunately very verbose if you have lots of keys to bind, unbind, and rebind.

Here is an example:

      <!-- set binding globally -->
      <key
        commandId="com.foo.myCommandId"
        contextId="org.eclipse.ui.contexts.window"
        schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
        sequence="M3+G T"/>
      <!-- un-set binding for Swiss German -->
      <key
        commandId="com.foo.myCommandId"
        contextId="org.eclipse.ui.contexts.window"
        locale="de_CH"
        schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
        sequence="M3+G C"/>
      <!-- re-set binding for Swiss German with a new key combo -->
      <key
        commandId="com.foo.myCommandId"
        contextId="org.eclipse.ui.contexts.window"
        locale="de_CH"
        schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
        sequence="M1+M3+G C"/>
0

精彩评论

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

关注公众号