Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » The required steps for adding a keybinding to a custom action/command ?
The required steps for adding a keybinding to a custom action/command ? [message #435770] Tue, 23 August 2005 12:56 Go to next message
Max Rydahl Andersen is currently offline Max Rydahl AndersenFriend
Messages: 233
Registered: July 2009
Senior Member
Hi,

It seems eclipse contains N possible methods to perform keybinding
(unfortunately I haven't made one of these work yet),
so I'm asking if someone could show me the few magic steps that is
required to simply add a key binding (e.g. Ctrl+Enter)
to my own action (defined in an actionset) when my specific Editor is
activated ?

Thank you!

/max
Re: The required steps for adding a keybinding to a custom action/command ? [message #435773 is a reply to message #435770] Tue, 23 August 2005 13:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: daniel.megert.gmx.net

Max Rydahl Andersen wrote:

> Hi,
>
> It seems eclipse contains N possible methods to perform keybinding
> (unfortunately I haven't made one of these work yet),
> so I'm asking if someone could show me the few magic steps that is
> required to simply add a key binding (e.g. Ctrl+Enter)
> to my own action (defined in an actionset) when my specific Editor is
> activated ?

1. define a command (see org.eclipse.ui.commands extension point)
Note: you might define your own category (if so, make sure that your
editor registers the context with the key binding service)
2. define the key binding (see org.eclipse.ui.bindings extension point)
3. bind your action to this command when defining the action set (use
the command id as definitionId)

HTH
Dani

>
> Thank you!
>
> /max
Re: The required steps for adding a keybinding to a custom action/command ? [message #435824 is a reply to message #435773] Wed, 24 August 2005 19:30 Go to previous messageGo to next message
Max Rydahl Andersen is currently offline Max Rydahl AndersenFriend
Messages: 233
Registered: July 2009
Senior Member
Thank you for the pointers, but still not working for me ;)

#1 - ok, I got a command and what if I don't have a category - which
category should I place it in to make work in my editor ?
(and to be complete how/where does an editor register it self ?)

#2 - the key binding also has a scheme and contextid - what should they be
?

/max


> Max Rydahl Andersen wrote:
>
>> Hi,
>>
>> It seems eclipse contains N possible methods to perform keybinding
>> (unfortunately I haven't made one of these work yet),
>> so I'm asking if someone could show me the few magic steps that is
>> required to simply add a key binding (e.g. Ctrl+Enter)
>> to my own action (defined in an actionset) when my specific Editor is
>> activated ?
>
> 1. define a command (see org.eclipse.ui.commands extension point)
> Note: you might define your own category (if so, make sure that your
> editor registers the context with the key binding service)
> 2. define the key binding (see org.eclipse.ui.bindings extension point)
> 3. bind your action to this command when defining the action set (use
> the command id as definitionId)
>
> HTH
> Dani
>
>>
>> Thank you!
>>
>> /max



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: The required steps for adding a keybinding to a custom action/command ? [message #435859 is a reply to message #435824] Thu, 25 August 2005 10:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: daniel.megert.gmx.net

Max Rydahl Andersen wrote:

> Thank you for the pointers, but still not working for me ;)
>
> #1 - ok, I got a command and what if I don't have a category - which
> category should I place it in to make work in my editor ?
> (and to be complete how/where does an editor register it self ?)

The category is used in the preference ui to group the commands. Either
use an existing category or create a new one.

>
> #2 - the key binding also has a scheme and contextid - what should
> they be ?

Out of the box there's the default and the emacs scheme. Normally you
use the default one.
Regarding the context id: hard to say. From what class does your editor
inherit?

Dani

>
> /max
>
>
>> Max Rydahl Andersen wrote:
>>
>>> Hi,
>>>
>>> It seems eclipse contains N possible methods to perform keybinding
>>> (unfortunately I haven't made one of these work yet),
>>> so I'm asking if someone could show me the few magic steps that is
>>> required to simply add a key binding (e.g. Ctrl+Enter)
>>> to my own action (defined in an actionset) when my specific Editor
>>> is activated ?
>>
>>
>> 1. define a command (see org.eclipse.ui.commands extension point)
>> Note: you might define your own category (if so, make sure that
>> your editor registers the context with the key binding service)
>> 2. define the key binding (see org.eclipse.ui.bindings extension point)
>> 3. bind your action to this command when defining the action set
>> (use the command id as definitionId)
>>
>> HTH
>> Dani
>>
>>>
>>> Thank you!
>>>
>>> /max
>>
>
>
>
Re: The required steps for adding a keybinding to a custom action/command ? [message #435863 is a reply to message #435859] Thu, 25 August 2005 12:16 Go to previous messageGo to next message
Max Rydahl Andersen is currently offline Max Rydahl AndersenFriend
Messages: 233
Registered: July 2009
Senior Member
>> #1 - ok, I got a command and what if I don't have a category - which
>> category should I place it in to make work in my editor ?
>> (and to be complete how/where does an editor register it self ?)
>
> The category is used in the preference ui to group the commands. Either
> use an existing category or create a new one.

Yes, and that is one of my biggest issues - is it really required to
unpack all the
src of eclipse and then do a search to find these constants...

>>
>> #2 - the key binding also has a scheme and contextid - what should they
>> be ?
>
> Out of the box there's the default and the emacs scheme. Normally you
> use the default one.

yes, but as I found out yesterday, the default is not named default - its
named org.eclipse.ui.defaultAccelleratorSchema (or similar, typing from
top of my head) - again a big issue of finding which id to use ;)

> Regarding the context id: hard to say. From what class does your editor
> inherit?

The editor is just a normal editor extending from TextEditor...

/max

> Dani
>
>>
>> /max
>>
>>
>>> Max Rydahl Andersen wrote:
>>>
>>>> Hi,
>>>>
>>>> It seems eclipse contains N possible methods to perform keybinding
>>>> (unfortunately I haven't made one of these work yet),
>>>> so I'm asking if someone could show me the few magic steps that is
>>>> required to simply add a key binding (e.g. Ctrl+Enter)
>>>> to my own action (defined in an actionset) when my specific Editor
>>>> is activated ?
>>>
>>>
>>> 1. define a command (see org.eclipse.ui.commands extension point)
>>> Note: you might define your own category (if so, make sure that
>>> your editor registers the context with the key binding service)
>>> 2. define the key binding (see org.eclipse.ui.bindings extension point)
>>> 3. bind your action to this command when defining the action set (use
>>> the command id as definitionId)
>>>
>>> HTH
>>> Dani
>>>
>>>>
>>>> Thank you!
>>>>
>>>> /max
>>>
>>
>>
>>



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: The required steps for adding a keybinding to a custom action/command ? [message #435876 is a reply to message #435863] Thu, 25 August 2005 16:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: daniel.megert.gmx.net

Max Rydahl Andersen wrote:

>
>>> #1 - ok, I got a command and what if I don't have a category -
>>> which category should I place it in to make work in my editor ?
>>> (and to be complete how/where does an editor register it self ?)
>>
>>
>> The category is used in the preference ui to group the commands.
>> Either use an existing category or create a new one.
>
>
> Yes, and that is one of my biggest issues - is it really required to
> unpack all the
> src of eclipse and then do a search to find these constants...

You can import the plug-ins (all those that you require) as binary
projects and then use the search dialog to find all contexts in the
plugin.xml files.

>
>>>
>>> #2 - the key binding also has a scheme and contextid - what should
>>> they be ?
>>
>>
>> Out of the box there's the default and the emacs scheme. Normally
>> you use the default one.
>
>
> yes, but as I found out yesterday, the default is not named default -
> its named org.eclipse.ui.defaultAccelleratorSchema (or similar,
> typing from top of my head) - again a big issue of finding which id
> to use ;)

>
>> Regarding the context id: hard to say. From what class does your
>> editor inherit?
>
>
> The editor is just a normal editor extending from TextEditor...

OK, then I suggest the following:

1. create your own scope that uses 'org.eclipse.ui.textEditorScope' as
parent
<extension
point="org.eclipse.ui.contexts">
<context
name="YOUR.name"
description="YOUR.description"
parentId="org.eclipse.ui.textEditorScope"
id="YOUR.id">
</context>
</extension>

2. add the following method to your editor:

/*
* @see
org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initia lizeKeyBindingScopes()
*/
protected void initializeKeyBindingScopes() {
setKeyBindingScopes(new String[] { "YOUR.id" }); //$NON-NLS-1$
}

3. use YOUR.id when defining the commands for your editor

Enjoy!

Dani

>
> /max
>
>> Dani
>>
>>>
>>> /max
>>>
>>>
>>>> Max Rydahl Andersen wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> It seems eclipse contains N possible methods to perform
>>>>> keybinding (unfortunately I haven't made one of these work yet),
>>>>> so I'm asking if someone could show me the few magic steps that
>>>>> is required to simply add a key binding (e.g. Ctrl+Enter)
>>>>> to my own action (defined in an actionset) when my specific
>>>>> Editor is activated ?
>>>>
>>>>
>>>>
>>>> 1. define a command (see org.eclipse.ui.commands extension point)
>>>> Note: you might define your own category (if so, make sure
>>>> that your editor registers the context with the key binding service)
>>>> 2. define the key binding (see org.eclipse.ui.bindings extension
>>>> point)
>>>> 3. bind your action to this command when defining the action set
>>>> (use the command id as definitionId)
>>>>
>>>> HTH
>>>> Dani
>>>>
>>>>>
>>>>> Thank you!
>>>>>
>>>>> /max
>>>>
>>>>
>>>
>>>
>>>
>
>
>
Re: The required steps for adding a keybinding to a custom action/command ? [message #435972 is a reply to message #435876] Fri, 26 August 2005 15:40 Go to previous messageGo to next message
Max Rydahl Andersen is currently offline Max Rydahl AndersenFriend
Messages: 233
Registered: July 2009
Senior Member
Thank you! That was the missing part of the puzzle!

It works like a charm.

/max

> Max Rydahl Andersen wrote:
>
>>
>>>> #1 - ok, I got a command and what if I don't have a category -
>>>> which category should I place it in to make work in my editor ?
>>>> (and to be complete how/where does an editor register it self ?)
>>>
>>>
>>> The category is used in the preference ui to group the commands.
>>> Either use an existing category or create a new one.
>>
>>
>> Yes, and that is one of my biggest issues - is it really required to
>> unpack all the
>> src of eclipse and then do a search to find these constants...
>
> You can import the plug-ins (all those that you require) as binary
> projects and then use the search dialog to find all contexts in the
> plugin.xml files.
>
>>
>>>>
>>>> #2 - the key binding also has a scheme and contextid - what should
>>>> they be ?
>>>
>>>
>>> Out of the box there's the default and the emacs scheme. Normally you
>>> use the default one.
>>
>>
>> yes, but as I found out yesterday, the default is not named default -
>> its named org.eclipse.ui.defaultAccelleratorSchema (or similar, typing
>> from top of my head) - again a big issue of finding which id to use ;)
>
>>
>>> Regarding the context id: hard to say. From what class does your
>>> editor inherit?
>>
>>
>> The editor is just a normal editor extending from TextEditor...
>
> OK, then I suggest the following:
>
> 1. create your own scope that uses 'org.eclipse.ui.textEditorScope' as
> parent
> <extension
> point="org.eclipse.ui.contexts">
> <context
> name="YOUR.name"
> description="YOUR.description"
> parentId="org.eclipse.ui.textEditorScope"
> id="YOUR.id">
> </context>
> </extension>
>
> 2. add the following method to your editor:
>
> /*
> * @see
> org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initia lizeKeyBindingScopes()
> */
> protected void initializeKeyBindingScopes() {
> setKeyBindingScopes(new String[] { "YOUR.id" }); //$NON-NLS-1$
> }
>
> 3. use YOUR.id when defining the commands for your editor
>
> Enjoy!
>
> Dani
>
>>
>> /max
>>
>>> Dani
>>>
>>>>
>>>> /max
>>>>
>>>>
>>>>> Max Rydahl Andersen wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> It seems eclipse contains N possible methods to perform
>>>>>> keybinding (unfortunately I haven't made one of these work yet),
>>>>>> so I'm asking if someone could show me the few magic steps that
>>>>>> is required to simply add a key binding (e.g. Ctrl+Enter)
>>>>>> to my own action (defined in an actionset) when my specific Editor
>>>>>> is activated ?
>>>>>
>>>>>
>>>>>
>>>>> 1. define a command (see org.eclipse.ui.commands extension point)
>>>>> Note: you might define your own category (if so, make sure that
>>>>> your editor registers the context with the key binding service)
>>>>> 2. define the key binding (see org.eclipse.ui.bindings extension
>>>>> point)
>>>>> 3. bind your action to this command when defining the action set
>>>>> (use the command id as definitionId)
>>>>>
>>>>> HTH
>>>>> Dani
>>>>>
>>>>>>
>>>>>> Thank you!
>>>>>>
>>>>>> /max
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>
>>
>>



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: The required steps for adding a keybinding to a custom action/command ? [message #436117 is a reply to message #435876] Wed, 31 August 2005 09:55 Go to previous message
Oliver Wahl is currently offline Oliver WahlFriend
Messages: 13
Registered: July 2009
Junior Member
Hi guys,

I had trouble getting the key bindings to work (in a non texteditor derived editor). This tip with using/setting my own scope did it! Now everything works 'as advertised'.

ThanX
Oliver
Previous Topic:[Newbie] Where to fill the widget content?
Next Topic:Only use packages which are inside a plugin
Goto Forum:
  


Current Time: Thu Dec 05 17:10:42 GMT 2024

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

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

Back to the top