简体   繁体   English

Eclipse键绑定冲突

[英]Eclipse Key Bindings Conflicts

I am extending eclipse's platform with my own view. 我用自己的观点扩展eclipse的平台。 This view contains one action in its toolbar. 此视图在其工具栏中包含一个动作。

I want to create a key binding shortcut associated to Ctrl + R for this actions. 我想为此操作创建与Ctrl + R相关的键绑定快捷方式。 To do that I created a my.context (my context extends org.eclipse.ui.window context), my.command and a my.command.binding extensions. 为此,我创建了一个my.context(我的上下文扩展了org.eclipse.ui.window上下文),my.command和一个my.command.binding扩展。

Then when my view is created, in the createPartControl(*) method, I activate my context: 然后,在创建视图时,在createPartControl(*)方法中,激活我的上下文:

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

When my view is opened in a debug perspective I have the following warning: 在调试透视图中打开我的视图时,出现以下警告:

    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)

I am not sure to understand why I have this warning .... 我不确定为什么会收到此警告...。

Is there several active contexts at a given time ? 在给定的时间是否有几个活动的上下文?

If I change my shortcut to Ctrl + C for example, I don't have this warning but Ctrl + C is also binded to another command (copy) in the debugg context ... why ? 例如,如果我将快捷方式更改为Ctrl + C ,则不会收到此警告,但是Ctrl + C还会在调试上下文中绑定到另一个命令(副本)...为什么?

I didn't find clear ressources delaing about Eclipse contexts on the web ... 我没有找到关于Web上的Eclipse上下文的清晰资源...

Thanks in advance 提前致谢

Manu 马努

I am not sure why your context does not isolate your bindings from the eclipse one, but if CTRL+R is already associated with "Run to Line" command, you could simply change its handler by yours, as described in this thread : 我不确定为什么您的上下文没有将您的绑定与日食隔离开来,但是如果CTRL+R已经与“ Run to Line”命令相关联,您可以简单地由您自己更改其处理程序,如该线程中所述

(Example to adapt to your case) (以适应您的情况为例)

 <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>

Note: this approach is also illustrated by 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");
  }
};

Now, since it does not explain why your own IContext does not deactivate Eclipse bindings, I can only find for now this thread , explaining when your context is or is not actually active: 现在,因为它并没有解释为什么自己IContext不会禁止Eclipse的绑定,我只能找到现在这个线程 ,当你的背景是或不是真正活跃的解释:

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. 您也可以尝试使用IContextService#registerShell(*)来将窗口外壳设置为== window类型,这应该使标准窗口上下文保持有效。
You still might have to activate the context while your SW window shell is active (with matching deactivates). 在您的SW窗口外壳程序处于活动状态时,您可能仍必须激活上下文(具有禁用的匹配功能)。

To which the OP replied: 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. 通过在所需窗口的焦点增益上激活该上下文,并在失去焦点并处置同一窗口时禁用该上下文,从而获得了解决方案。

May be that could help. 可能会有所帮助。
In the meantime, you can look at " Platform Command Framework " in order to activate the "Tracing Option" and see exactly what binding is activated and for which command. 同时,您可以查看“ Platform Command Framework ”以激活“ Tracing Option”,并确切地看到激活了什么绑定以及针对哪个命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM