How to remove default wizards from File > New Menu in RCP application?

时光总嘲笑我的痴心妄想 提交于 2019-12-08 06:17:00

问题


I wanted to add some of my wizards in File > New menu of my RCP application by adding org.eclipse.ui.newWizards extension point into plugin.xml file.

<extension point="org.eclipse.ui.newWizards">
<category
    id="com.my.testapp.ui.objects"
    name="Objects"/>
<wizard
    category="com.my.testapp.ui.objects"
    class="com.my.testapp.ui.wizard.create.COWizard"
    icon="icons/co.gif"
    id="com.my.testapp.ui.wizard.co"
    name="Configure Object"
    preferredPerspectives="com.my.testapp.ui.perspective"/>
</wizard>
</extension>

By default File > New > Other menu except my Objects folder with Configure Object Wizard, also contains General folder with following wizards: File, Folder, Project and Untitled Text File. As in my application these wizards does not make sense I would like to get rid of them. How to do that?


回答1:


Solution provided here (thanks @bananeweizen and @stracka) for removing default import wizards can also be applied to this issue. So, solution is to add following code to postWindowOpen() method of ApplicationWorkbenchWindowAdvisor class in order to remove default "General" category from File > New > Other menu.

AbstractExtensionWizardRegistry wizardRegistry = (AbstractExtensionWizardRegistry)PlatformUI.getWorkbench().getNewWizardRegistry();
IWizardCategory[] categories = PlatformUI.getWorkbench().getNewWizardRegistry().getRootCategory().getCategories();
for(IWizardDescriptor wizard : getAllWizards(categories)){
    if(wizard.getCategory().getId().matches("org.eclipse.ui.Basic")){
        WorkbenchWizardElement wizardElement = (WorkbenchWizardElement) wizard;
        wizardRegistry.removeExtension(wizardElement.getConfigurationElement().getDeclaringExtension(), new Object[]{wizardElement});
    }
}



回答2:


While this question asks about hiding some of the "Import" wizards (instead of the "New" wizards), the solution should apply to your problem also.

If you are googling around for further details, please be aware that the extension point for that mechanism is called activities, but the Eclipse terminology referring to it is capabilities.




回答3:


Have you tried removing related action sets? I've never removed the items you're referring to, but I have removed things like the default 'Search' action, the 'Annotation' actions, and the 'Navigation' actions, as I usually don't support those functions in my applications.

Once you puzzle out what packages those actions live in, which often takes a bit of research and digging around, you can hide them in the postWindowOpen() method of your ApplicationWorkbenchWindowAdvisor class, like this:

public void postWindowOpen() { 
    // 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 '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");
        }
    }
}


来源:https://stackoverflow.com/questions/11307367/how-to-remove-default-wizards-from-file-new-menu-in-rcp-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!