[英]Eclipse JFace :: How to get rid of key binding conflicts while working in a multipage editor
我有一个具有多页的编辑器,其中每个页面都有复制粘贴删除操作和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! 请告诉我什么是实现此目标的最佳方法。
在编辑器的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()可以为编辑器的每个部分启用和禁用相应的处理程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.