Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 417806

Summary: Accelerators not shown in declarative menu items (commands)
Product: [RT] RAP Reporter: Andreas Fischl <andreas.r.fischl.work>
Component: JFaceAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: andreas.r.fischl.work
Version: 2.1   
Target Milestone: 2.3 M2   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Andreas Fischl CLA 2013-09-23 07:01:59 EDT
Although RAP is now capable of displaying accelerators (e.g. CTRL-X) in menus since 2.1 (see bug 303034) it doesn't do so when the menu is built declaratively (with Commands instead of Actions).


Steps to reproduce:

1. Create a Command beneath the extension point "org.eclipse.ui.commands":
      <command
            description="%My_Command"
            id="my.command"
            name="My Command">
      </command>

2. Define a key binding (accelerator) beneath extension point "org.eclipse.ui.bindings":
      <key
            commandId="my.command"
            contextId="org.eclipse.ui.contexts.window"
            schemeId="my.scheme"
            sequence="M1+O">
      </key>
3. Don't forget the binding beneath extension point "org.eclipse.ui.bindings":
      <scheme
            id="my.scheme"
            name="My Default Scheme">
      </scheme>

4a. Use the command in a menu, e.g.:
       <menuContribution locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               id="myMenu"
               label="%My_Menu"
            <command
                  commandId="my.command"
                  style="push">
            </command>
         </menu>

4b. Alternative (add the command programmatically to any menu):
        IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService(IMenuService.class);
        menuService.populateContributionManager(menuManager, location);

Expected behavior:
The accelerator text ("CTRL-O") should appear beside the menu item in RAP. It does work in RCP.
Comment 1 Ivan Furnadjiev CLA 2013-09-23 07:19:55 EDT
Thanks for reporting. The accelerator support has been enabled in ActionContributionItem with commit 7ccd138f02817ff71d74737a7f14ea0e2452d5dd.
Comment 2 Andreas Fischl CLA 2014-02-12 07:47:31 EST
Sorry, not completely fixed.

Please open org.eclipse.ui.menus.CommandContributionItem got to the method updateMenuItem(), line 617-632. You'll find a commented out block of code ("[bm] no binding manager") there, and in this block is this commented out line:

item.setText(text + '\t' + keyBindingText);

This line would add the accelerator text to the menu items text (it does so in RCP).
Comment 3 Ivan Furnadjiev CLA 2014-02-12 12:59:29 EST
Fixed in master with change https://git.eclipse.org/r/21879