Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Accelerator key to the Action
Accelerator key to the Action [message #467613] Wed, 09 May 2007 01:40 Go to next message
Eclipse UserFriend
Hi,


I have defined ExitAction and added to the view's menubar and
toolbar and context menu...
But the accelerator key is not display and also not working..

public ExitAction()
{
this.setText("E&xit\tCtrl+X");
this.setToolTipText("Exit the main window");
this.setAccelerator(SWT.CTRL+'X');
}

Why the Accelerator key is not working

Thanks in advance,
Swetha
Re: Accelerator key to the Action [message #467635 is a reply to message #467613] Wed, 09 May 2007 07:21 Go to previous messageGo to next message
Eclipse UserFriend
> this.setText("E&xit\tCtrl+X");

Try with: E&xit@Ctrl+X
Re: Accelerator key to the Action [message #467650 is a reply to message #467613] Wed, 09 May 2007 13:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: valere.fedronic.ext.streamezzo.com

Hi,

If you want your action to be accessed by a shortcut you must associate
it to a command.

Use this extension point : org.eclipse.ui.commands
--> create a command
--> create a key binding associated to this command
commandId="your.command.id"
keyConfigurationId="org.eclipse.ui.defaultAcceleratorConfiguration "
keySequence="Ctrl+X"




In your code, register your action to this command
/* e.g. in the createPartControl */
YourAction action = ...;
IHandlerService handlerService = (IHandlerService)
window.getService(IHandlerService.class);
handlerService.activateHandler("your.command.id",new ActionHandler(action));


You don' have to set the accelerator in your action constructor, and the
key sequence is automatically added to the action label.
public ExitAction()
{
setId("my.exit.action");
setActionDefinitionId("your.command.id");
this.setText("E&xit");
this.setToolTipText("Exit the main window");
}
valere.

PS: take a look at this
http://wiki.eclipse.org/index.php/Platform_Command_Framework



Swetha a écrit :
> Hi,
>
>
> I have defined ExitAction and added to the view's menubar and
> toolbar and context menu...
> But the accelerator key is not display and also not working..
>
> public ExitAction()
> { this.setText("E&xit\tCtrl+X");
> this.setToolTipText("Exit the main window");
> this.setAccelerator(SWT.CTRL+'X');
> }
>
> Why the Accelerator key is not working
> Thanks in advance,
> Swetha
>
>
>
Re: Accelerator key to the Action [message #467689 is a reply to message #467650] Thu, 10 May 2007 01:09 Go to previous messageGo to next message
Eclipse UserFriend
Hi,


The following is included in plug-n.xml,I have just removed < > form
the actual code

extension
point="org.eclipse.ui.commands">
category
description="Actions take at lunch time."
id="view.keybindings.category"
name="endUser">
/category>
command
categoryId="view.keybindings.category"
description="Exit from the view"
id="view.keybindings.exit"
name="Exit">
/command
/extension

extension
point="org.eclipse.ui.bindings"
key
commandId="view.keybindings.exit"
contextId="keybindings.contexts.exit"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="CTRL+X"
/key>
/extension>

And in the View class I have included,

window = getSite().getWorkbenchWindow();
IHandlerService handlerService = (IHandlerService)
window.getService(IHandlerService.class);
handlerService.activateHandler("view.keybindings.exit", new
ActionHandler(exitAction));



And in the ExitAction class,

public ExitAction()
{
this.setText("E&xit");
this.setToolTipText("Exit the main window");
this.setId("EXIT");
this.setActionDefinitionId("view.keybindings.exit");

}


Still the shortcut key is not displaying as a label and its not working,
Am I doing anything wrong here,

Thanks in advance,
Swetha
Re: Accelerator key to the Action [message #467694 is a reply to message #467689] Thu, 10 May 2007 03:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: valere.fedronic.ext.streamezzo.com

Try this:

<extension
point="org.eclipse.ui.commands">
<category
description="Actions take at lunch time."
id="view.keybindings.category"
name="endUser">
</category>
<command
categoryId="view.keybindings.category"
description="Exit from the view"
id="view.keybindings.exit"
name="Exit"/>
<keyBinding
commandId="view.keybindings.exit"
keyConfigurationId="org.eclipse.ui.defaultAcceleratorConfiguration "
keySequence="Ctrl+X"/>
</extension>


You can enable tracing for the command framework :

In your launching configuration ( Run --> run...) go to the tracing tab
and check the following debug options :
org.eclipse.ui/debug=true
org.eclipse.ui/trace/keyBindings=true
org.eclipse.ui/trace/keyBindings.verbose=true
org.eclipse.ui/trace/sources=true
org.eclipse.ui/trace/handlers=true
org.eclipse.ui/trace/handlers.verbose=true
org.eclipse.ui/trace/handlers.verbose.commandId=org.eclipse. jdt.ui.navigate.open.type
org.eclipse.ui/trace/contexts=true
org.eclipse.ui/trace/contexts.verbose=true


valere.


Swetha a écrit :
> Hi,
>
>
> The following is included in plug-n.xml,I have just removed < > form
> the actual code
> extension
> point="org.eclipse.ui.commands">
> category
> description="Actions take at lunch time."
> id="view.keybindings.category"
> name="endUser">
> /category>
> command
> categoryId="view.keybindings.category"
> description="Exit from the view"
> id="view.keybindings.exit"
> name="Exit">
> /command
> /extension
>
> extension
> point="org.eclipse.ui.bindings"
> key
> commandId="view.keybindings.exit"
> contextId="keybindings.contexts.exit"
> schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
> sequence="CTRL+X"
> /key>
> /extension>
>
> And in the View class I have included,
>
> window = getSite().getWorkbenchWindow();
> IHandlerService handlerService = (IHandlerService)
> window.getService(IHandlerService.class);
> handlerService.activateHandler("view.keybindings.exit", new
> ActionHandler(exitAction));
>
>
>
> And in the ExitAction class,
>
> public ExitAction()
> { this.setText("E&xit");
> this.setToolTipText("Exit the main window");
> this.setId("EXIT");
> this.setActionDefinitionId("view.keybindings.exit");
> }
>
>
> Still the shortcut key is not displaying as a label and its not working,
> Am I doing anything wrong here,
>
> Thanks in advance,
> Swetha
>
>
>
>
>
>
>
>
Re: Accelerator key to the Action [message #467698 is a reply to message #467694] Thu, 10 May 2007 04:51 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

it didn't work.. Am I missing anything ... Mnemonic is working.. but
Ctrl + X is not working

Thanks,
Swetha
Re: Accelerator key to the Action [message #467700 is a reply to message #467698] Thu, 10 May 2007 04:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: valere.fedronic.ext.streamezzo.com

Did you enable the tracing?
Look at the console output.

valere.


Swetha a écrit :
> Hi,
>
> it didn't work.. Am I missing anything ... Mnemonic is working.. but
> Ctrl + X is not working
>
> Thanks,
> Swetha
>
Re: Accelerator key to the Action [message #467702 is a reply to message #467698] Thu, 10 May 2007 05:05 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

The above code is working only for the first time the view is
opened....

If I open it again form the ShowView menu, the key binding is not working..

Thanks,
Swetha
Re: Accelerator key to the Action [message #467703 is a reply to message #467702] Thu, 10 May 2007 05:20 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: valere.fedronic.ext.streamezzo.com

Is the 'activateHanlder' call is in the createPartControl() method ?

handlerService.activateHandler("view.keybindings.exit", new
ActionHandler(exitAction));

Swetha a écrit :
> Hi,
>
> The above code is working only for the first time the view is
> opened....
>
> If I open it again form the ShowView menu, the key binding is not working..
>
> Thanks,
> Swetha
>
>
>
Re: Accelerator key to the Action [message #467704 is a reply to message #467703] Thu, 10 May 2007 06:59 Go to previous messageGo to next message
Eclipse UserFriend
Hi,


Yes.. I called there only .. so do I need to write in ExitAction()
constructor..or in run() method
Re: Accelerator key to the Action [message #467736 is a reply to message #467694] Thu, 10 May 2007 09:33 Go to previous messageGo to next message
Eclipse UserFriend
valere fedronic wrote:
> Try this:
>
> <extension
> point="org.eclipse.ui.commands">
> <category
> description="Actions take at lunch time."
> id="view.keybindings.category"
> name="endUser">
> </category>
> <command
> categoryId="view.keybindings.category"
> description="Exit from the view"
> id="view.keybindings.exit"
> name="Exit"/>
> <keyBinding
> commandId="view.keybindings.exit"
> keyConfigurationId="org.eclipse.ui.defaultAcceleratorConfiguration "
> keySequence="Ctrl+X"/>


^^^^ oh, don't use this, it's all deprecated :-)

PW
Re: Accelerator key to the Action [message #467738 is a reply to message #467689] Thu, 10 May 2007 09:38 Go to previous messageGo to next message
Eclipse UserFriend
Swetha wrote:
> Hi,
>
>
> The following is included in plug-n.xml,I have just removed < > form
> the actual code
> extension
> point="org.eclipse.ui.commands">
> category
> description="Actions take at lunch time."
> id="view.keybindings.category"
> name="endUser">
> /category>
> command
> categoryId="view.keybindings.category"
> description="Exit from the view"
> id="view.keybindings.exit"
> name="Exit">
> /command
> /extension
>
> extension
> point="org.eclipse.ui.bindings"
> key
> commandId="view.keybindings.exit"
> contextId="keybindings.contexts.exit"
> schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
> sequence="CTRL+X"
> /key>
> /extension>

Don't fill in the contextId ... unless you've created a special context
and are activating it and deactivating it. Leave it out and the binding
will be in org.eclipse.ui.contexts.window (which might not work for
CTRL+X), or create your own special context and active it in your
createPartControl(*)


>
> And in the View class I have included,
>
> window = getSite().getWorkbenchWindow();
> IHandlerService handlerService = (IHandlerService)
> window.getService(IHandlerService.class);
> handlerService.activateHandler("view.keybindings.exit", new
> ActionHandler(exitAction));


You can just use getSite().getService(IHandlerService.class); ... then
your handler will be bound while your view is active. This is even more
important if you activate your own context for the keybinding.

It's fine to do this call in the createPartControl(*)

Later,
PW
Re: Accelerator key to the Action [message #467822 is a reply to message #467738] Fri, 11 May 2007 00:33 Go to previous message
Eclipse UserFriend
Hi,

I am confused.. I want to tell u once again what I am doing ..

In pulg-in.xml,

<extension
point="org.eclipse.ui.commands">
<category
description="Actions take at lunch time."
id="view.keybindings.category"
name="EndUser">
</category>
<command
categoryId="view.keybindings.category"
defaultHandler="org.eclipse.ui.handlers.IHandlerActivation"
description="Exit from the view"
id="view.keybindings.exit"
name="Exit">
</command>
<keyBinding
commandId="view.keybindings.exit"

keyConfigurationId="org.eclipse.ui.defaultAcceleratorConfiguration "
keySequence="Ctrl+3"/>
</extension>

And in the View Class,

in createPartControl() method,

IHandlerService handlerService = (IHandlerService)
window.getService(IHandlerService.class);
handlerService.activateHandler("view.keybindings.exit", new
ActionHandler(exitAction));
getSite().getService(IHandlerService.class);


And in the ExitAction Class,

public ExitAction()
{
this.setText("E&xit@Ctrl+3");
this.setToolTipText("Exit the main window");
this.setId("EXIT");
this.setActionDefinitionId("view.keybindings.exit");

}

This is working only for the first time the view is displayed.. If I close
it and open it again from the ShowView menu, its not working,... sorry for
irritating u all... Please tell me what I am doing wrong here


Thanks,
Swetha
Previous Topic:Plug-in Development
Next Topic:focus and SWT_AWT bridge
Goto Forum:
  


Current Time: Wed May 21 07:26:22 EDT 2025

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

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

Back to the top