|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
| Daniel KrÃ¼gler
Registered: July 2009
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)
This should have the wanted effect.
HTH & Greetings from Bremen,
Powered by FUDForum
. Page generated in 0.13255 seconds