[英]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.