Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » key bindings to command and action
key bindings to command and action [message #334963] Thu, 12 March 2009 14:26 Go to next message
Parvez is currently offline ParvezFriend
Messages: 181
Registered: July 2009
Senior Member
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 #334981 is a reply to message #334963] Fri, 13 March 2009 15:25 Go to previous messageGo to next message
Parvez is currently offline ParvezFriend
Messages: 181
Registered: July 2009
Senior Member
Any suggestions, how to achieve this?

Thanks.


PC wrote:
> 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 16:58 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

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


Previous Topic:question on visible when for command
Next Topic:Problems starting eclipse on moblin
Goto Forum:
  


Current Time: Fri Apr 19 01:33:49 GMT 2024

Powered by FUDForum. Page generated in 0.03055 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top