Bug 201362 - [KeyBindings] Add a contextId for menus
Summary: [KeyBindings] Add a contextId for menus
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-28 00:48 EDT by Chris Aniszczyk CLA
Modified: 2019-09-06 15:29 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Aniszczyk CLA 2007-08-28 00:48:03 EDT
In the wonderful key binding and command framework... it seems menus aren't loved. It would be nice to have a contextId that can be registered against menus so you can have your key binding fire when a menu is displayed, for example, File->Import

I believe the Help component currently gets at having its bindings fired due to the old JFace Actions. I think there was something there that checked for F1 or whatever Help had registered. Other people want to have their commands invoked also :)

Another idea would be to have a contextId of org.eclipse.ui.contexts.all or everywhere... something to say that your keybinding will be hit anywhere in the workbench.

What are your thoughts Paul?

How hard do you think this is to implement, I can spare some cycles as if this is working, this would make my Plug-in Spy work so much easier.
Comment 1 Paul Webster CLA 2007-08-28 08:11:40 EDT
Hmmm, where to start ... :-)

Yeah, when a menu is up we no longer receive key binding events.  They're just ... gone.

Help is a special case.  SWT fires a HelpEvent when a menu item has a help listener and the user hits SHIFT+F12

Is this because you need to execute your command when the user has selected a menu item (to provide information about it)?

PW
Comment 2 Chris Aniszczyk CLA 2007-08-28 10:16:22 EDT
Correct paul, I would like to receive information about the menu based on the execution of my key binding.

Why should there be special cases, why can't everyone participate in the love :)?
Comment 3 Chris Aniszczyk CLA 2007-08-28 10:17:14 EDT
and this should be in Platform UI's bucket, I must've been sleepy last night.
Comment 4 Chris Aniszczyk CLA 2007-08-28 13:15:08 EDT
Paul, any sneaky way to do this via reflection possibly as a temporary workaround?
Comment 5 Paul Webster CLA 2007-08-28 14:45:00 EDT
(In reply to comment #4)
> Paul, any sneaky way to do this via reflection possibly as a temporary
> workaround?
> 

I talked to Steve and he said that as long as the menu is up, the OS will eat the key events.

Another option is to set up a command that will display info about the *next* event.  When the attached code is run, it adds a global filter.  If you then select a menu item, it will eat the selection event and you have the widget.  For commands and actions, getData() should have some form of ContributionItem.

PW

public class FindThatItemHandler extends AbstractHandler {
	private Listener listener = new Listener() {
		public void handleEvent(Event event) {
			event.display.removeFilter(SWT.Selection, this);
			System.out.println("Disarmed");
			if (event.widget instanceof MenuItem) {
				MenuItem item = (MenuItem) event.widget;
				System.out.println(item.getText());
				System.out.println(item.getData().getClass().getName());
				event.doit = false;
				event.type = SWT.None;
			}
		}
	};

	public Object execute(ExecutionEvent event) throws ExecutionException {
		Display display = HandlerUtil.getActiveWorkbenchWindowChecked(event)
				.getShell().getDisplay();
		display.addFilter(SWT.Selection, listener);
		System.out.println("Armed");
		return null;
	}
}
Comment 6 Chris Aniszczyk CLA 2007-08-28 15:55:14 EDT
Paul, you're officially a genius.

My next question would be, is this type of thing possible for items on the toolbar? 
Comment 7 Chris Aniszczyk CLA 2007-08-28 15:56:29 EDT
n/m Paul, you're a genius.

Comment 8 Paul Webster CLA 2009-03-02 10:52:26 EST
Does this need more love?
PW
Comment 9 Paul Webster CLA 2009-03-02 11:41:21 EST
Updated as per http://wiki.eclipse.org/Platform_UI/Bug_Triage
PW
Comment 10 Eclipse Webmaster CLA 2019-09-06 15:29:43 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.