【问题标题】:How to activate key bindings at runtime?如何在运行时激活键绑定?
【发布时间】:2017-12-20 09:33:32
【问题描述】:

在我的 RCP 应用程序的某个时刻,我想使用 F5、Shift+F5、Ctrl+N、Ctrl+P 等快捷键提供开始、停止、下一个、上一个等。这些已经在标准方案中定义,有一段时间我想覆盖标准操作。

是否可以在运行时切换活动键绑定方案?

【问题讨论】:

    标签: eclipse-rcp keyboard-shortcuts


    【解决方案1】:

    您可以使用org.eclipse.ui.contexts 扩展点为键绑定定义新的“上下文”,然后在该上下文中声明您的键绑定。

    例如,Ant 编辑器声明了一个上下文org.eclipse.ant.ui.AntEditorScope

    <extension
          point="org.eclipse.ui.contexts">
       <context
             name="%context.editingAnt.name"
             description="%context.editingAnt.description"
             parentId="org.eclipse.ui.textEditorScope"
             id="org.eclipse.ant.ui.AntEditorScope">
       </context>
    </extension>
    

    并在该上下文中声明键绑定:

    <extension point="org.eclipse.ui.bindings">
         <key
            sequence="M1+M2+F"
            contextId="org.eclipse.ant.ui.AntEditorScope"
            commandId="org.eclipse.jdt.ui.edit.text.java.format"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
    

    要使用上下文,您必须激活它。在扩展 TextEditor 的编辑器中覆盖 initializeKeyBindingScopes

    @Override
    protected void initializeKeyBindingScopes() {
        setKeyBindingScopes(new String[] { "org.eclipse.ant.ui.AntEditorScope" }); 
    }
    

    在其他地方使用IContextService 服务activateContext 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      • 2020-08-28
      • 2017-01-19
      • 1970-01-01
      相关资源
      最近更新 更多