Eclipse 键绑定(bind)冲突

标签 eclipse

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

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

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

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

当我的 View 在调试透视图中打开时,我收到以下警告:
    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 也绑定(bind)到调试上下文中的另一个命令(副本)...为什么?

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

提前致谢

马努

最佳答案

我不确定为什么您的上下文不会将您的绑定(bind)与 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>

注意: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 绑定(bind),我现在只能找到 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”以激活“跟踪选项”并准确查看激活了哪些绑定(bind)以及针对哪个命令。

关于Eclipse 键绑定(bind)冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1032610/

相关文章:

c++ - 如何在 Windows 上使用 MinGW 安装/启用 OpenMP for Eclipse?

java - 使用 Maven & Eclipse & Glassfish 4 进行热部署/增量 Java 部署?

eclipse - 像使用 Java 一样使用 Scala

eclipse - 如何在 Eclipse 中使用 ssh 隧道设置颠覆?

android - Unity 与 qualcomm 集成到 eclipse

java - 如何清理和组织 Eclipse Package Explorer?

java - 安卓依赖配置

eclipse - 第谷无法从不同的 Reactor 构建中解析从产品到 Eclipse 功能的引用

java - JUnit Eclipse 与 Ant

java - 从 Eclipse 中的依赖 jar 运行 JUnit 测试