How to capture key press event over multiple views [message #676503] |
Sat, 04 June 2011 18:32  |
Eclipse User |
|
|
|
Hello Everyone,
I am having an application where I have to detect key press event over multiple views.
There are 3 views in a perspective and out of that there is a main view. The main view has to be assigned certain short cut keys. Example there is a button named "Pain" in the main view and when the user presses "P" the event should trigger the pain functionality. In this case the user's focus might be on any of the views, i.e. the user might be scrolling through the details in view no 2 and he presses "P", appropriate action should trigger.
Regards,
Chaitannya
|
|
|
|
Re: How to capture key press event over multiple views [message #676802 is a reply to message #676774] |
Mon, 06 June 2011 11:05   |
Eclipse User |
|
|
|
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. [1] and [2] 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?
Regards,
Michael
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!!!
[1] www.vogella.de/articles/EclipseCommandsKeybindings/article.html
[2] beautifuldiscovery.wordpress.com/2010/04/26/eclipse-tip-using-icontextactivation-in-a-viewpart-or-editorpart/
|
|
|
Re: How to capture key press event over multiple views [message #676814 is a reply to message #676802] |
Mon, 06 June 2011 11:45   |
Eclipse User |
|
|
|
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);
part.doPain();
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).
Later,
PW
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06269 seconds