|Re: How to capture key press event over multiple views [message #676802 is a reply to message #676774]
||Mon, 06 June 2011 15:05
| Michael Gerzabek
Registered: June 2011
I have a similar problem (and am also new to RCP). I followed the steps and declared|
- several keybindings,
- several commands
- one handler. the handler is the default handler for all commands. i do discriminiation via the command name.
I also declared a context and activate this context in createPartControl( Composite parent ) of my view.  and  have been helpful resources on the web for me in the process of figuring out how to do this. (I have to post more than 5 messages until I'm allowed to include links. So the protocol is missing.)
Now. When I define keybindings as a combination of keys, i.e. Alt+B, everything works fine. But when I define keybindings just via ordinary letters, i.e. B, my handler doesn't get called. Is there a way to consume just letters without modifier keys? What do I miss here?
PS: I worked 10 years on the server side doing webapps and enterprise integration. I'm very used to Eclipse, especially the JDT, WST, etc. This is my first dive into Eclipse as a plattform for applications. And, man, THIS IS AN AWESOME PLATFORM! I'm so impressed! Thank you very much all out there!!!
|Re: How to capture key press event over multiple views [message #676814 is a reply to message #676802]
||Mon, 06 June 2011 15:45
| Paul Webster
Registered: July 2009
Ah, and sorry this applies to the original question as well.|
First, keybindings only works with a modifier. Eclipse by default doesn't provide a way to eat the normal, none modified keys. That's because it breaks UI guidelines. Once you eat, say, the B key, it's gone for good.
That being said you can do this per view by adding a SWT.KeyDown listener to the controls in your view. This helps limit your change to only your view. Once you get your key, you can act on it, even using org.eclipse.ui.handlers.IHandlerService.executeCommand(String, Event) to execute a command (which is what the standard keybinding framework is doing anyway).
In the case of the original question, you can add your keydown listener to all 3 views, and if you get the key you want use something like:
MyMainView part = (MyMainView) getSite().getPage().findView(MyMainView.ID);
In this case it's OK to use findView(String) because you're working with your main view. In the general case, you would use findViewReference(String).
Powered by FUDForum
. Page generated in 0.02014 seconds