Gennady Gromov
Gennady Gromov

Reputation: 21

A handler for menu

I have created the menu contribution in my Eclipse RCP application as an extension (org.eclipse.ui.menus). The items of this menu contribution are made as commands with handlers. I want to have such handlers not only for items (commands), but also for menus which are containing their items too (such as "File", "Edit"...).

The menus can have a field "commandID" in plugin.xml. I tried to create the command with this ID with a Handler extended the AbstractHandler, but it does't work.

Upvotes: 1

Views: 237

Answers (1)

Paul Webster
Paul Webster

Reputation: 10654

Menus can take commandIds so they can display a key shortcut. That part is simply a display convenience. There's still work to do behind the scenes to make the menu auto-popup.

See how the command org.eclipse.ui.navigate.showInQuickMenu is defined and used in the org.eclipse.ui.ide plugin.

It also has some supporting code in the org.eclipse.ui.internal.ide.WorkbenchActionBuilder:

    String showInQuickMenuId = IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_QUICK_MENU;
    showInQuickMenu = new QuickMenuAction(showInQuickMenuId) {
        protected void fillMenu(IMenuManager menu) {
            menu.add(ContributionItemFactory.VIEWS_SHOW_IN
                    .create(window));
        }
    };
    register(showInQuickMenu);

Upvotes: 1

Related Questions