Eclipse快捷键冲突

4

我正在使用自己的视图扩展eclipse平台。这个视图在其工具栏中包含一个操作。

我想要为这个操作创建一个与Ctrl+R相关联的快捷键绑定。为此,我创建了一个my.context(我的上下文扩展org.eclipse.ui.window context)、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也绑定到另一个命令(复制)...为什么呢?

我在网上没有找到关于Eclipse上下文的清晰资源...

提前感谢!

Manu


更新了我的答案,加入了一些新的想法。 - VonC
1个回答

2
我不确定为什么您的上下文没有将绑定与 Eclipse 的隔离开来,但是如果 CTRL+R 已经与“运行到行”命令关联,您可以按照 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>

注意:这种方法也可以通过此帖子进行说明。
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,解释当您的上下文实际上是否处于活动状态时:
如果您打开自己的窗口(对话框或shell)并使工作台窗口不活动,则您的上下文也将不活动。 您可以尝试使用IContextService#registerShell(*)将窗口shell设置为type == window,这应该使标准窗口上下文有效。 在您的SW窗口shell处于活动状态时(具有匹配的停用),您仍然可能需要激活上下文。
OP回复道: 我通过在所需窗口获得焦点时激活该上下文并在失去焦点并处理相同窗口时停用该上下文来解决了它的问题。
也许那可以帮助一下。 同时,您可以查看“Platform Command Framework”以激活“Tracing Option”,并查看确切的绑定以及哪个命令被激活。

谢谢你的回答,但我觉得这个解决方案有点像一个“hack”。 正如你所说,我想要的是将“我的上下文与Eclipse的绑定隔离开来”。它应该可以工作,但是…… - Manuel Selva
再次感谢您的补充。我没有打开自己的窗口,所以这对我没有更多帮助。我的上下文在我的view.createPartControl方法中被激活,而视图是通过编程方式打开的。我认为有一个bug出现了.. 在eclipse或者我的代码中...我会尽力调查并让您知道。再次感谢您的时间。 - Manuel Selva

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接