【问题标题】:Adding context to my view and binding key to this context将上下文添加到我的视图并将键绑定到此上下文
【发布时间】:2014-01-07 11:17:02
【问题描述】:

我的问题与here 相同。但是那里提供的解决方案对我不起作用。

我已按照 greg-449 在我的观点的createPartControl 中的回答中所述激活了上下文。

IContextService contextService =  IContextService)getSite().getService(IContextService.class);        
        contextService.activateContext(myViewContextId);

当我的视图被激活时,我在 Eclipse 控制台上收到以下警告

!MESSAGE CTRL+F 发生冲突:

绑定(CTRL+F, ParameterizedCommand(Command(myFindCmdId,Find, , 类别(org.eclipse.core.commands.categories.autogenerated,未分类,自动生成或没有类别的命令,true), org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@f41266e, ,,true),null), org.eclipse.ui.defaultAcceleratorConfiguration, myViewContextId,,,system)

绑定(CTRL+F, ParameterizedCommand(Command(org.eclipse.ui.edit.findReplace,查找和替换, 查找和替换文本, 类别(org.eclipse.ui.category.edit,Edit,null,true), org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@24ad92b0, ,,true),null), org.eclipse.ui.defaultAcceleratorConfiguration, org.eclipse.ui.contexts.window,,,system)

===Plugin.xml 有 ====

<extension
     point="org.eclipse.ui.contexts">
  <context
        id=<myViewContextId>
        name="abc">
  </context>
</extension>
<extension
     point="org.eclipse.ui.bindings">
  <key
        commandId=<myFindCmdId>
        contextId=<myViewContextId>
        schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
        sequence="M1+F">
  </key> 
  //some more key binding here
</extension> 

【问题讨论】:

    标签: eclipse eclipse-rcp eclipse-plugin


    【解决方案1】:

    为避免冲突消息,使用org.eclipse.ui.bindings 扩展点定义您自己的键绑定方案,并将标准org.eclipse.ui.defaultAcceleratorConfiguration 指定为方案的父ID。将您的键绑定放入这个新方案中。

    用途:

    org.eclipse.ui/KEY_CONFIGURATION_ID=schemeid
    

    在您的plugin_customization.ini 中选择您的方案作为默认方案。

    更多here

    注意:如果您的 Ctrl+F 是 Find 命令,您应该挂接到现有的 Eclipse 查找/替换可重定向操作,而不是定义新命令和键绑定。

    所以对于 Find 不要定义任何命令、处理程序或键绑定。而是在您的 ViewPart 中使用

    IActionBars bars = getViewSite().getActionBars();
    
    bars.setGlobalActionHandler(ActionFactory.FIND.getId(), your find Action);
    

    【讨论】:

    • 它的部分工作我想要的是当我的视图处于活动状态并且用户按下 Ctrl + F 然后我的命令也应该在我的视图处于非活动状态时执行然后它应该打开日食Find and Replace 对话框。我需要为此使用方案吗?或者有没有其他方法可以做到这一点。
    • 添加 Eclipse IDE 插件方式使用 find
    【解决方案2】:

    尝试将 parentId="org.eclipse.ui.contexts.window" 添加到您的新上下文中:

    <extension
         point="org.eclipse.ui.contexts">
      <context
            id=<myViewContextId>
            name="abc">
            parentId="org.eclipse.ui.contexts.window">
      </context>
    </extension>
    

    【讨论】:

      猜你喜欢
      • 2019-06-02
      • 2020-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-23
      • 2018-03-17
      • 2021-07-19
      • 1970-01-01
      相关资源
      最近更新 更多