The required steps for adding a keybinding to a custom action/command ? [message #435770] |
Tue, 23 August 2005 08:56  |
Eclipse User |
|
|
|
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 #435876 is a reply to message #435863] |
Thu, 25 August 2005 12:25   |
Eclipse User |
|
|
|
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 11:40   |
Eclipse User |
|
|
|
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/
|
|
|
|
Powered by
FUDForum. Page generated in 0.05228 seconds