如何从RCP应用程序中的文件>新菜单中删除默认向导?

fra*_*anz 1 eclipse eclipse-plugin eclipse-rcp

我想通过将org.eclipse.ui.newWizards扩展点添加到plugin.xml文件中,在我的RCP应用程序的File> New菜单中添加我的一些向导.

<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>
Run Code Online (Sandbox Code Playgroud)

默认情况下,"文件">"新建">"其他"菜单("我的对象"文件夹除了"配置对象向导")外,还包含"常规"文件夹以及以下向导:文件,文件夹,项目和无标题文本文件.在我的应用程序中,这些向导没有意义我想摆脱它们.怎么做?

fra*_*anz 7

此处提供的解决方案(感谢@bananeweizen和@stracka)删除默认导入向导也可以应用于此问题.因此,解决方案是将以下代码添加到类的postWindowOpen()方法中ApplicationWorkbenchWindowAdvisor,以便从"文件">"新建">"其他"菜单中删除默认的"常规"类别.

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});
    }
}
Run Code Online (Sandbox Code Playgroud)