| 
| key bindings to command and action [message #334963] | Thu, 12 March 2009 10:26  |  | 
| Eclipse User  |  |  |  |  | Hi, 
 Is it possible to bind key sequence to one command in one view and to
 amother command/action in another editor?
 
 
 This is how I tried but no success:
 
 
 application has scheme and context e.g.
 
 
 myScheme
 myContext
 
 M1+R is bound to command - command1 and available in most of views and
 works fine.
 
 Now one editor has action say editorAction1 and I want to bind M1+R to
 that action when user is working on that editor.
 
 In plugin.xml
 
 org.eclipse.ui.contexts
 subContext - parent - myContext
 
 org.eclipse.ui.commands
 command - id set to ActionDefinitionId of editorAction1 say
 editorAction1
 
 
 org.eclipse.ui.bindings
 commandId="editorAction1"
 contextId="subContext"
 schemeId="myScheme"
 sequence="M1+R"
 
 I put code to activate  this context in focus gain of editor and
 deactivate in focus lost i.e.
 
 
 contextActivation = ((IContextService)
 getSite().getService(IContextService.class))
 .activateContext("subContext");
 
 
 ((IContextService)
 getSite().getService(IContextService.class)).deactivateConte xt(contextActivation);
 
 
 
 
 May be I am doing something wrong or missing something, any suggestions?
 
 Thanks.
 |  |  |  | 
|  | 
| 
| Re: key bindings to command and action [message #334988 is a reply to message #334963] | Fri, 13 March 2009 12:58  |  | 
| Eclipse User  |  |  |  |  | You're close. 
 PC wrote:
 
 >
 > In plugin.xml
 >
 > org.eclipse.ui.contexts
 >  subContext - parent - myContext
 >
 > org.eclipse.ui.commands
 >    command - id set to ActionDefinitionId of editorAction1 say
 > editorAction1
 
 you need to define your command and then bind that to the keybinding in
 your context (actionDefinitionIDs aren't really relevant)  Is it that
 you want a completely different command to be active in your editor (say
 end-of-line) than active everywhere else (say copy-to-clipboard)?
 
 >
 >
 > org.eclipse.ui.bindings
 >     commandId="editorAction1"
 >     contextId="subContext"
 >     schemeId="myScheme"
 >     sequence="M1+R"
 
 OK
 >
 > I put code to activate  this context in focus gain of editor and
 > deactivate in focus lost i.e.
 >
 >
 > contextActivation = ((IContextService)
 > getSite().getService(IContextService.class))
 >       .activateContext("subContext");
 
 This is fine.  As long as you get your activation from your site, you
 can do this once in createPartControl(*) and you don't need the
 deactivateContext(*) anywhere (you get it for free).
 
 What you have so far has created the keybinding, context, command, and
 tied them all together.
 
 Now you need to add a handler for your command.  If you have an action
 in your editor, you can do it directly using:
 
 IHandlerService hs
 =  (IHandlerService)getSite().getService(IHandlerService.class) ;
 hs.activateHandler("editorAction1",
 new ActionHandler(yourEditorAction));
 
 Use org.eclipse.jface.commands.ActionHandler
 
 Later,
 PW
 
 
 --
 Paul Webster
 http://wiki.eclipse.org/Platform_Command_Framework
 http://wiki.eclipse.org/Command_Core_Expressions
 http://wiki.eclipse.org/Menu_Contributions
 http://wiki.eclipse.org/Menus_Extension_Mapping
 http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.05984 seconds