问题
My question is same as asked here. But the solution provided there not works for me.
I have activated the context as said in the answer by greg-449 in createPartControl of my view.
IContextService contextService = IContextService)getSite().getService(IContextService.class);
contextService.activateContext(myViewContextId);
When my view was activated I am getting below warning on eclipse console
!MESSAGE A conflict occurred for CTRL+F:
Binding(CTRL+F, ParameterizedCommand(Command(myFindCmdId,Find, , Category(org.eclipse.core.commands.categories.autogenerated,Uncategorized,Commands that were either auto-generated or have no category,true), org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@f41266e, ,,true),null), org.eclipse.ui.defaultAcceleratorConfiguration, myViewContextId,,,system)
Binding(CTRL+F, ParameterizedCommand(Command(org.eclipse.ui.edit.findReplace,Find and Replace, Find and replace text, Category(org.eclipse.ui.category.edit,Edit,null,true), org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@24ad92b0, ,,true),null), org.eclipse.ui.defaultAcceleratorConfiguration, org.eclipse.ui.contexts.window,,,system)
===Plugin.xml has ====
<extension
point="org.eclipse.ui.contexts">
<context
id=<myViewContextId>
name="abc">
</context>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId=<myFindCmdId>
contextId=<myViewContextId>
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+F">
</key>
//some more key binding here
</extension>
回答1:
To avoid the conflict message define you own key binding scheme using the org.eclipse.ui.bindings extension point and specify the standard org.eclipse.ui.defaultAcceleratorConfiguration as the parent id for the scheme. Put your key bindings in this new scheme.
Use:
org.eclipse.ui/KEY_CONFIGURATION_ID=schemeid
in your plugin_customization.ini to select your scheme as the default.
More here
Note: If your Ctrl+F is a Find command you should hook in to the existing Eclipse find/replace retargetable action rather than defining new commands and key bindings.
So for Find do not define any command, handler or key bindings. Instead in your ViewPart use
IActionBars bars = getViewSite().getActionBars();
bars.setGlobalActionHandler(ActionFactory.FIND.getId(), your find Action);
回答2:
Try to add parentId="org.eclipse.ui.contexts.window" into your new context:
<extension
point="org.eclipse.ui.contexts">
<context
id=<myViewContextId>
name="abc">
parentId="org.eclipse.ui.contexts.window">
</context>
</extension>
来源:https://stackoverflow.com/questions/20970214/adding-context-to-my-view-and-binding-key-to-this-context