简体   繁体   English

Eclipse JFace ::在多页编辑器中工作时如何摆脱键绑定冲突

[英]Eclipse JFace :: How to get rid of key binding conflicts while working in a multipage editor

I have an editor with multipage in which each page has copy paste delete actions and f3 navigation action. 我有一个具有多页的编辑器,其中每个页面都有复制粘贴删除操作和f3导航操作。 I create context and activate and deactivate the actions 我创建上下文并激活和停用操作

Below is how the plugin.xml looks like : 以下是plugin.xml的外观:

<extension
         point="org.eclipse.ui.bindings">
      <key
            commandId="com.sap.adt.wda.controller.ui.navigate"
            contextId="com.sap.adt.wda.controller.ui.contextTabScope"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            sequence="F3">
      </key>

</extension>
   <extension
         point="org.eclipse.ui.contexts">
      <context
            description="%context_navigateToController_ymsg"
            id="com.sap.adt.wda.controller.ui.contextTabScope"
            name="%context_navigateToController_yins"
            parentId="org.eclipse.ui.contexts.window">
      </context>
   </extension>

It is done through activation and deactivation of context. 通过激活和停用上下文来完成。 Below is the code snippet. 下面是代码片段。

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 navigateHandlerActivation = service.activateHandler(NavigationHandler.COMMAND_ID, new NavigationHandler());
        activatedHandlers = new ArrayList<IHandlerActivation>();
        activatedHandlers.add(navigateHandlerActivation);
    }


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

These two methods are called respectively from the page change to activate the context once the page is active and deactivate when the page is not active. 从页面更改中分别调用这两种方法,以在页面处于活动状态时激活上下文,并在页面处于非活动状态时取消激活。

The problem is that it still conflicts with another opened editor as when I switch between editors, pagechange is not even called!! 问题是它仍然与另一个打开的编辑器冲突,因为当我在编辑器之间切换时,甚至没有调用pagechange! Please tell me what is the best way to implement this. 请告诉我什么是实现此目标的最佳方法。

Add focus listener on sourceViewer of editor 在编辑器的sourceViewer上添加焦点侦听器

    focusListener = new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            deactivateHandlers();
        }

        @Override
        public void focusGained(FocusEvent arg0) {
            activateHandlers();
        }
    };

   sourceViewer.getTextWidget().addFocusListener(focusListener);

On switch of every page the focusLost and focusGained will be called. 在每页切换时,将调用focusLost和focusGained。 Override activateHandlers() and deactivateHandlers() to enable and disable respective handlers for each parts of editor 重写activateHandlers()和deactivateHandlers()可以为编辑器的每个部分启用和禁用相应的处理程序

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

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