EclipseRCP开发(三)-如何去除顽固原生菜单项

去除new-project及other菜单

获取所有菜单项,筛选出new菜单,将new菜单清空,再重新从已注册的向导中添加所需菜单。记录之。

java 复制代码
if ("new".equals(ii.getId())) {
	MenuManager newMenu = (MenuManager) ii;
	// 清除现有的所有子项
	newMenu.removeAll();
	// 手动填充 New Wizard 项目
	fillNewWizardMenu(newMenu, window);
}


private void fillNewWizardMenu(MenuManager newMenu, IWorkbenchWindow window) {
		// 获取已注册的所有 New Wizard
		IWizardRegistry wizardRegistry = PlatformUI.getWorkbench().getNewWizardRegistry();
		IWizardCategory[] categories = wizardRegistry.getRootCategory().getCategories();
		// 遍历每个分类中的向导New4diacProjectWizard
		for (IWizardCategory category : categories) {
			//筛选自定义的导航类
			if(!category.getId().contains("xxxxx")) {
				continue;
			}
			for (IWizardDescriptor wizard : wizards) {
				if (wizard.getId().contains("xxxx")) {
					Action action = new Action(wizard.getLabel()) {
						@Override
						public void run() {
							try {
								// 打开向导
								IWizard newWizard = wizard.createWizard();
								WizardDialog wizardDialog = new WizardDialog(window.getShell(), newWizard);
								wizardDialog.open();
							} catch (Exception e) {
								e.printStackTrace();
							}
						}
					};
					// 设置向导的图标
					ImageDescriptor imageDescriptor = wizard.getImageDescriptor();
					if (imageDescriptor != null) {
						action.setImageDescriptor(imageDescriptor);
					}
					// 添加向导项到 New 菜单
					newMenu.add(action);
				}

			}
		}
	}
相关推荐
Chase-Hart1 天前
【每日一题】LeetCode 1184.公交站间的距离问题(数组)
java·算法·leetcode·eclipse·intellij-idea
疑惑的杰瑞1 天前
[乱码]确保命令行窗口与主流集成开发环境(IDE)统一采用UTF-8编码,以规避乱码问题
java·c++·vscode·python·eclipse·sublime text·visual studio
Chase-Hart2 天前
【每日一题】LeetCode 7.整数反转(数学)
java·数据结构·算法·leetcode·eclipse
.生产的驴2 天前
SpringBoot 消息队列RabbitMQ 消息可靠性 数据持久化 与 LazyQueue
java·spring boot·后端·eclipse·rabbitmq·maven·java-rabbitmq
lljss20203 天前
ESP8266+eclipse+AP+最简单webserver
eclipse·esp8266
customer084 天前
【开源免费】基于SpringBoot+Vue.JS房产销售系统(JAVA毕业设计)
java·vue.js·spring boot·spring cloud·java-ee·eclipse·maven
深度不睡觉6 天前
NS3的3.36版本将Eclipse作IDE
ide·eclipse
wangshuai09277 天前
Eclipse折叠if、else、try catch的{}
eclipse
lljss20207 天前
win10+eclipse+ESP8266_RTOS_SDK开发环境构建
eclipse·esp8266