代码之家  ›  专栏  ›  技术社区  ›  Andrew Eisenberg

如何取消设置特定区域设置的键绑定

  •  0
  • Andrew Eisenberg  · 技术社区  · 14 年前

    我有一个Eclipse插件,它使用了几个键绑定(Alt-gx、Alt-gy等等)。对于大多数键盘布局,这些特定的键绑定没有问题。然而,对于瑞士德国人来说,Alt-G创建了“@”,这使得瑞士德国人很难使用我创建的插件。我不想更改当前的keybindings,因为这会混淆现有用户。

    如何以编程方式检测用户在瑞士-德国键盘上,并以编程方式禁用(或更改)这些键绑定?

    (这是我可以在plugin.xml中指定的吗?)

    1 回复  |  直到 14 年前
        1
  •  0
  •   Andrew Eisenberg    14 年前

    为了回答我自己的问题,可以使用org.eclipse.ui.bindings扩展点来完全解决这个问题。

    首先,像平常一样设置keybinding,然后可以在单个区域设置上取消设置特定的keybinding。仅对于该区域设置,您可以将绑定重新设置为其他内容。

    这是可行的,但不幸的是,如果要绑定、取消绑定和重新绑定大量的密钥,那么它会非常冗长。

          <!-- 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"/>