1

I've added to my perspective's org.eclipse.ui.menus

<command
      commandId="org.eclipse.ui.views.showView"
      style="pulldown">
</command>

This adds Show View item to main menu, but this item is not a menu (as in the Eclipse Window menu). Instead pressing it shows a dialog where I can select a view. How do I get a menu instead?

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487

2 Answers2

1

Just to share on my recent experiment in trying to do the same thing, what Max suggested in his answer will work but leaves you using internal code (resulting in a 'Discouraged Access' warning).

Another approach is to build the menu through your applications action bar advisor. Although, this approach will leave you to having to write code (oppose to use providing menu contributions in the plugin XML definition). Consider the following example:

public class ApplicationActionBarAdvisor extends ActionBarAdvisor
{
    private IContributionItem contributionOpenPerspective;
    private IContributionItem contributionShowView; 

    ...

    protected void makeActions(IWorkbenchWindow window)
    {
        ...
        contributionOpenPerspective = ContributionItemFactory.
           PERSPECTIVES_SHORTLIST.create(window);
        contributionShowView = ContributionItemFactory.
           VIEWS_SHORTLIST.create(window);
        ...
    }

    protected void fillMenuBar(IMenuManager menuBar)
    {
        ...
        MenuManager windowMenu = new MenuManager("&Window", 
           IWorkbenchActionConstants.M_WINDOW);
        menuBar.add(windowMenu);

        MenuManager openPerspectiveMenu = new MenuManager("&Open Perspective");
        openPerspectiveMenu.add(perspectivesContribution);
        windowMenu.add(openPerspectiveMenu);

        MenuManager showViewMenu = new MenuManager("Show &View");
        showViewMenu.add(viewsContribution);
        windowMenu.add(showViewMenu);
        ...
    } 
}

A possible downside to this approach is with the interaction between menus created in the advisor and menus created by menu contributions. Since advisor menu items are created before menu contributions, you are left to deal with adding more sorting logic in your menu contributions. This might be fine for most people, however, you lose the 'feel' of a centralized menu structure from org.eclipse.ui.menus (even if the feeling is an illusion when other plugins come into play with their own menu contributions).

I've also included the building of a perspective menu as well; completely option, but I added it if anyone was attempting to perform the same menu building with perspectives.

Community
  • 1
  • 1
jdknight
  • 1,801
  • 32
  • 52
1

You have to create ContributionItem class like below:

public class MyShowViewContributionItem extends org.eclipse.ui.internal.ShowViewMenu {
    public MyShowViewContributionItem() {
        this("om.myplugin.myShowViewId");
    }
    public MyShowViewContributionItem(String id) {
        super(org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow(), id);
    }
}

then in your plugin.xml org.eclipse.ui.menus extension:

    <menu
          label="My Show View">
       <dynamic
             class="com.myplugin.MyShowViewContributionItem"
             id="com.myplugin.myShowViewId">
       </dynamic>
    </menu>

Cheers, Max

Chandrayya G K
  • 8,719
  • 5
  • 40
  • 68
Max
  • 2,917
  • 1
  • 16
  • 16
  • After doing this, I see `` in the menu, despite adding ``s in perspective extensions and clearing the workspace data. Any idea how to fix this? – Alexey Romanov Aug 01 '11 at 09:46