0

我有一个多页编辑器,其中每个页面都有复制粘贴删除操作和 f3 导航操作。我创建上下文并激活和停用操作

下面是 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>

它是通过上下文的激活和停用来完成的。下面是代码片段。

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

这两个方法分别从页面更改中调用,以在页面处于活动状态时激活上下文,在页面不处于活动状态时取消激活。

问题是它仍然与另一个打开的编辑器冲突,因为当我在编辑器之间切换时,甚至没有调用 pagechange !请告诉我实现这一点的最佳方法是什么。

4

1 回答 1

1

在编辑器的 sourceViewer 上添加焦点监听器

    focusListener = new FocusListener() {

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

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

   sourceViewer.getTextWidget().addFocusListener(focusListener);

在每页切换时,将调用 focusLost 和 focusGained。覆盖 activateHandlers() 和 deactivateHandlers() 以启用和禁用编辑器每个部分的相应处理程序

于 2013-09-04T07:13:21.090 回答