Tuesday, September 15, 2009

Bind a key binding that is already defined

To correctly bind a key that is already defined for example by platform - F5 for refresh, the important thing is to create your own context:


name="refresh" parentId="org.eclipse.ui.contexts.window">




Once correct context is defined, it needs to be activated. For example, in view:


View.createPartControl(Composite parent) {
...
...
IContextService contextService = (IContextService) getSite().getService(IContextService.class);
contextService.activateContext("com.iwaysoftware.explorer.refresh");
}


Then the usual, command is created that is tied to a handler that extends AbstractHandler, command is tied to a binding, and the binding is in turn uses earlier created custom context.



defaultHandler="com.iwaysoftware.explorer.handler.RefreshHandler" id="com.iwaysoftware.explorer.refreshCommand"
name="Refresh">



sequence="F5" schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="com.iwaysoftware.explorer.refresh" />


name="refresh" parentId="org.eclipse.ui.contexts.window">


Blogger Syntax Highliter