简体   繁体   English

如何在多页编辑器中管理不同命令的键冲突处理程序

[英]How to manage key conflict handler of different commands in multipage editor

I have multipage editor and i'm using different commands in two pages with same key sequence 'M3+O'. 我有多页编辑器,并且在两个页面中使用相同的键序列“ M3 + O”使用不同的命令。 I am getting key conflicting handlers. 我遇到了关键的冲突处理程序。

Error: 错误:

!MESSAGE A conflict occurred for ALT+O:
      Binding(ALT+O,
            ParameterizedCommand(Command(adt.tools.wda_com.sap.adt.wda.controller.ui.addmethcommand,Add Method,
                ,
                Category(org.eclipse.core.commands.categories.autogenerated,Uncategorized,Commands that were either auto-generated or have no category,true),
                org.eclipse.ui.internal.MakeHandlersGo@2f2e3d,
                ,,true),null),
            org.eclipse.ui.defaultAcceleratorConfiguration,
            com.sap.adt.wda.controller.ui.contextTabScope,,,system)
        Binding(ALT+O,
            ParameterizedCommand(Command(adt.tools.wda_com.sap.adt.wda.controller.ui.addnodecommand,Add Node,

        ,
                Category(org.eclipse.core.commands.categories.autogenerated,Uncategorized,Commands that were either auto-generated or have no category,true),
                org.eclipse.ui.internal.MakeHandlersGo@184af18,
                ,,true),null),
            org.eclipse.ui.defaultAcceleratorConfiguration,
            com.sap.adt.wda.controller.ui.contextTabScope,,,system)

Extensions: 扩展:

  <extension
             point="org.eclipse.ui.bindings">
          <key
                commandId="adt.tools.wda_com.sap.adt.wda.controller.ui.addmethcommand"
                contextId="com.sap.adt.wda.controller.ui.contextScope"
                schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
                sequence="M3+O">
          </key>
          <key
                commandId="adt.tools.wda_com.sap.adt.wda.controller.ui.addnodecommand"
                contextId="com.sap.adt.wda.controller.ui.contextScope"
                schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
                sequence="M3+O">
          </key>
    </extension>

My own Context: 我自己的上下文:

   <extension
         point="org.eclipse.ui.contexts">
      <context
            description="context scope"
            id="com.sap.adt.wda.controller.ui.contextScope"
            name="context scope"
            parentId="org.eclipse.ui.contexts.window">
      </context>
   </extension>

Activation and deactivation: It is done through activation and deactivation of context. 激活和停用:这是通过上下文的激活和停用来完成的。 Below is the code snippet on page change. 以下是页面更改上的代码段。

Activation in 1st Page: 在第一页中激活:

private void activateHandlers() {
            IContextService contextService = (IContextService) (PlatformUI.getWorkbench().getService(IContextService.class));
            if (contextService != null) {
                activation = contextService.activateContext(IControllerConstants.CONTEXT_TAB_ECLIPSE_CONTEXT_ID);
            }
            IEditorSite site = getEditor().getEditorSite();
            IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);

            IHandlerActivation nodeActivation = service.activateHandler(AddNodeHandler.COMMAND_ID, new AddNodeHandler());
            activatedHandlers = new ArrayList<IHandlerActivation>();
            activatedHandlers.add(nodeActivation );

        }

Activation in 2nd Page: 在第二页中激活:

private void activateHandlers() {
                IContextService contextService = (IContextService) (PlatformUI.getWorkbench().getService(IContextService.class));
                if (contextService != null) {
                    activation = contextService.activateContext(IControllerConstants.CONTEXT_TAB_ECLIPSE_CONTEXT_ID);
                }
                IEditorSite site = getEditor().getEditorSite();
                IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);


    IHandlerActivation methodActivation = service.activateHandler(AddMethodHandler.COMMAND_ID, new AddMethodHandler());
                activatedHandlers = new ArrayList<IHandlerActivation>();
                activatedHandlers.add(methodActivation );
            }

Deactivation similar in respective page: 在相应页面中停用类似:

public void deactivateHandlers() {
            IContextService contextService = (IContextService) (PlatformUI.getWorkbench().getService(IContextService.class));
            contextService.deactivateContext(activation);
            IHandlerService service = (IHandlerService) getEditor().getEditorSite().getService(IHandlerService.class);
            if (activatedHandlers != null) {
                service.deactivateHandlers(activatedHandlers);
                activatedHandlers = null;
            }
        }

Even after deactivation / activation on page change, the conflict appears. 即使在停用/激活页面更改之后,也会出现冲突。 Please let me know if there is a better approach. 请让我知道是否有更好的方法。

Thanks. 谢谢。

Use a different context id for each page. 为每个页面使用不同的上下文ID。 You could make your main com.sap.adt.wda.controller.ui.contextScope the parent of each page context. 您可以将您的主要com.sap.adt.wda.controller.ui.contextScope每个页面上下文的父级。

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

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