Remove “File, edit,…etc” menus from Eclipse RCP ap

2019-02-25 00:27发布

I want to remove the File, edit, Source, Refactor, etc. menus from my RCP application Can I use hideActionSet() ? or what should I do ?

标签: eclipse-rcp
2条回答
混吃等死
2楼-- · 2019-02-25 01:17

That's right; in your ApplicationWorkbenchWindowAdvisor, override postWindowOpen().

The tricky bit is usually figuring out the names of the actionsets that you want to remove, but you can use the old standby ALT-SHIFT-F2 (the default keybinding for 'Plugin-in Menu Spy') and click on one of the menu items that you want to remove.

Note that if the menu item is disabled, the spy won't give you any info on it.

public void postWindowOpen() {
    runApplicationWorkbenchDelegate();

    // remove unwanted UI contributions that eclipse makes by default
    IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();

    for (int i = 0; i < windows.length; ++i) {
        IWorkbenchPage page = windows[i].getActivePage();
        if (page != null) {
            // hide generic 'File' commands
            page.hideActionSet("org.eclipse.ui.actionSet.openFiles");

            // hide 'Convert Line Delimiters To...'
            page.hideActionSet("org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo");

            // hide 'Search' commands
            page.hideActionSet("org.eclipse.search.searchActionSet");

            // hide 'Annotation' commands
            page.hideActionSet("org.eclipse.ui.edit.text.actionSet.annotationNavigation");

            // hide 'Forward/Back' type navigation commands
            page.hideActionSet("org.eclipse.ui.edit.text.actionSet.navigation");
        }
    }
}
查看更多
看我几分像从前
3楼-- · 2019-02-25 01:27

Although the question is old:

Lars Vogel's tutorial about Eclipse Activities shows how to hide entire menus in an RCP application rather than removing single menu-entries.

EDIT: Alternatively you can use the MenuManager attached to the workbench window to show or hide Menus/Contributions. Try the following code to hide all menus:

WorkbenchWindow workbenchWin = (WorkbenchWindow)PlatformUI.getWorkbench().getActiveWorkbenchWindow();
MenuManager menuManager = workbenchWin.getMenuManager();
IContributionItem[] items = menuManager.getItems();

for(IContributionItem item : items) {
  item.setVisible(false);
}
查看更多
登录 后发表回答