Eclipse密钥绑定冲突

我正在用自己的观点扩展
eclipse的平台.此视图在其工具栏中包含一个操作.

我想为此操作创建与Ctrl R关联的键绑定快捷方式.为此,我创建了一个my.context(我的上下文扩展了org.eclipse.ui.window上下文),my.command和my.command.binding扩展.

然后,当我的视图被创建时,在createPartControl(*)方法中,我激活我的上下文:

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

当我在调试透视图中打开我的视图时,我有以下警告:

    Warning: A conflict occurred for CTRL+R:
    Binding(CTRL+R,
    ParameterizedCommand(Command(org.eclipse.debug.ui.commands.RunToLine,Run to Line,
    Resume and break when execution reaches the current line,
    Category(org.eclipse.debug.ui.category.run,Run/Debug,Run/Debug command category,true),
 ActionDelegateHandlerProxy(null,org.eclipse.debug.internal.ui.actions.RetargetRunToLineAction),
    ,,true),null),
    org.eclipse.ui.defaultAcceleratorConfiguration,
    org.eclipse.debug.ui.debugging,,,system)
    Binding(CTRL+R,
    ParameterizedCommand(Command(RestoreAction,Restore Chart (T-Charts),
    Restore the initial chart display,
    Category(TChartsActions,T-Charts Actions,null,true),
    ActionHandler(com.st.tcharts.internal.actions.RestoreChartAction@1997b8a),
    ,,true),null),
    org.eclipse.ui.defaultAcceleratorConfiguration,
    com.st.tcharts.ui.view,,,system)

我不明白为什么我有这个警告….

在给定时间有几个活动的上下文?

例如,如果我将快捷方式更改为Ctrl C,我没有此警告,但Ctrl C也绑定到debugg上下文中的另一个命令(副本)…为什么?

我没有在网上找到关于Eclipse上下文的明确资源…

提前致谢

马努

最佳答案 我不确定为什么你的上下文没有将你的绑定与eclipse隔离,但如果CTRL R已经与“Run to Line”命令相关联,你可以简单地用你的改变它的处理程序,如
this thread中所述:

(示例以适应您的情况)

 <handler
       class="test.handlers.DeleteFooHandler"
       commandId="org.eclipse.ui.edit.delete">
    <activeWhen>
       <iterate
             ifEmpty="false"
             operator="and">
          <instanceof
                value="test.model.Foo">
          </instanceof>
       </iterate></activeWhen>
 </handler>

注意:这种方法也在this thread中说明:

IHandlerService handlerService =
  getSite().getService(IHandlerService.class);


IHandler myPaste = new org.eclipse.core.commands.AbstractHandler() {
  public Object execute(ExecutionEvent event) throws ExecutionException{
    System.out.println("This is MyPaste");
  }
};

现在,由于它没有解释为什么你自己的IContext没有停用Eclipse绑定,我现在只能找到this thread,解释你的上下文何时或实际上没有活动:

If you are opening your own window (dialog or shell) and that makes the workbench window not active, your context will also not be active.
You can try setting your window shell to type == window also using IContextService#registerShell(*) … that should leave the standard window contexts valid.
You still might have to activate the context while your SW window shell is active (with matching deactivates).

OP回复:

I got the solution of it by activating that context on the focus gain of required window and deactivate that context on focus lost and dispose of the same window.

可能会有所帮助.
在此期间,您可以查看“Platform Command Framework”以激活“跟踪选项”并确切地查看激活的绑定和命令.

点赞