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:
  1. <extension point="org.eclipse.ui.contexts">  
  2.  <context description="allow refresh via f5" id="com.iwaysoftware.explorer.refresh" <br="">   name="refresh" parentId="org.eclipse.ui.contexts.window">  
  3.  </context>  
  4. </extension>  


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

  1. View.createPartControl(Composite parent) {  
  2. ...  
  3. ...  
  4.  IContextService contextService = (IContextService) getSite().getService(IContextService.class);  
  5.         contextService.activateContext("com.iwaysoftware.explorer.refresh");  
  6. }  


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.

  1. <extension point="org.eclipse.ui.commands">  
  2.   <command categoryid="org.eclipse.debug.ui.category.run" <br=""></command>   defaultHandler="com.iwaysoftware.explorer.handler.RefreshHandler" id="com.iwaysoftware.explorer.refreshCommand"  
  3.    name="Refresh">  
  4.     
  5.  </extension>  
  6.  <extension point="org.eclipse.ui.bindings">  
  7.   <key commandid="com.iwaysoftware.explorer.refreshCommand" <br="">   sequence="F5" schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"  
  8.    contextId="com.iwaysoftware.explorer.refresh" />  
  9.  </key></extension>  
  10.  <extension point="org.eclipse.ui.contexts">  
  11.   <context description="allow refresh via F5" id="com.iwaysoftware.explorer.refresh" <br="">   name="refresh" parentId="org.eclipse.ui.contexts.window">  
  12.   </context>  
  13.  </extension>  

No comments:

Post a Comment

Blogger Syntax Highliter