Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Hide ContributionItem but be able to trigger it via accellerator
Hide ContributionItem but be able to trigger it via accellerator [message #642182] Tue, 30 November 2010 09:57 Go to next message
Raffaele Gambelli is currently offline Raffaele GambelliFriend
Messages: 27
Registered: July 2009
Junior Member
Hi all,

I would like to have a not visible action but I would like to trigger it via shortcut keys.

I tried to set accelerator 'CTRL + D' and it works only if action is visible.
If I set visible false on that menu contribution, then the shortcut key doesn't work anymore

Any hints?

Thanks and best regards
Raffaele
Re: Hide ContributionItem but be able to trigger it via accellerator [message #642265 is a reply to message #642182] Tue, 30 November 2010 15:58 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Raffaele Gambelli wrote:
> Any hints?

You cannot do that. i.e. shortcuts that are in a menu item only work
when the menu item is there (since that's what hooks it up for the OS
accelerator table).

That's why eclipse has commands/handlers and org.eclipse.ui.bindings.
It needed a system so that it can provide keybindings to commands that
aren't rendered as a MenuItem in the main menu somewhere.

If you're an RCP app, use commands, handlers, org.eclipse.ui.bindings,
and org.eclipse.ui.menus, since the menu item for a command is
independent of the keybinding for the command.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Hide ContributionItem but be able to trigger it via accellerator [message #642283 is a reply to message #642265] Tue, 30 November 2010 16:24 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 11/30/2010 16:58, Paul Webster wrote:
> Raffaele Gambelli wrote:
>> Any hints?
>
> You cannot do that. i.e. shortcuts that are in a menu item only work
> when the menu item is there (since that's what hooks it up for the OS
> accelerator table).
>
> That's why eclipse has commands/handlers and org.eclipse.ui.bindings. It
> needed a system so that it can provide keybindings to commands that
> aren't rendered as a MenuItem in the main menu somewhere.
>
> If you're an RCP app, use commands, handlers, org.eclipse.ui.bindings,
> and org.eclipse.ui.menus, since the menu item for a command is
> independent of the keybinding for the command.

I agree with what Paul says. But if you really want that, I believe this
is doable (even though one might consider it as a hack):

1) You can realize that your program reacts on key-pressed events: E.g.
register a KeyListener on the control that has the current focus of
interest (e.g. the viewer control) and on keyReleased evaluate your
KeyEvent (you may need to do an internet search how to realize that).

If your handler is rather global instead of local, you need a global
event listener, e.g. by adding a filter to the shell display
(getDisplay().addFilter(SWT.UP, listener)), which is really a hammer
that you should care of!

2) If you found that the key-combination of interest has occurred you
programmatically invoke a command, e.g.

IHandlerService handlerService = (IHandlerService)
serviceLocator.getService(IHandlerService.class);
handlerService.executeCommand(commandId, null);

This should have the wanted effect.

HTH & Greetings from Bremen,

Daniel Krügler
Re: Hide ContributionItem but be able to trigger it via accellerator [message #642458 is a reply to message #642283] Wed, 01 December 2010 12:44 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Daniel Krügler wrote:
> If your handler is rather global instead of local, you need a global
> event listener, e.g. by adding a filter to the shell display
> (getDisplay().addFilter(SWT.UP, listener)), which is really a hammer
> that you should care of!

:-) yes, that's how we do it in the eclipse keybinding system.

The WorkbenchKeyboard is the global filter, and is what analyzes
SWT.KeyDown events. If the cumulative KeyDown events (and collecting
them correctly is not as simple as you think) match a keybinding (like
CTRL+SHIFT+5) then it executes the command through the handler service.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Previous Topic:DataTime Widget on solaries
Next Topic:Extension points: How to define new identifiers?
Goto Forum:
  


Current Time: Tue Apr 23 09:38:13 GMT 2024

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

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

Back to the top