eclipse菜单原理

Eclipse菜单原理

需要自己设计一个菜单管理功能,特此研究了一下eclipse菜单管理实现机制。

eclipse的导航菜单分为menu,toolbar,popup三种。 其中menu又有command separate input checkbox radio sub menu

菜单的扩展通过menuContribution来实现,一个menuContribution就是一个menu的builder。 内部是一个菜单的定义片段,用来定义菜单项,最常用的菜单项就是command定义,这个command定义又和另一种command插件定义相关联了。

菜单项的定义包括了 文字,访问键,图标,快捷键,提示。 label,tooltip,还支持国际化和属性文件定义,这些通过插件组件来完成了。

menuContribution一个locationURI 属性,其中的值定义了这个菜单扩展要附加到主菜单体系中的位置。如:"menu:org.eclipse.ui.main.menu?after=additions"
表示 这个菜单是菜单扩展会作为org.eclipse.ui.main.menu的子菜单项并在additions项目的后面添加。additions实际是一个占位符,并不显示出来的。

A URI specification that defines the insertion point at which the contained additions will be added. The format for the URI is comprised of three basic parts: Scheme: One of "menu", "popup" or
"toolbar. Indicates the type of the manager used to handle the contributions Id: This is either the id of an existing menu, a view id or the id of the editor 'type' Query: The query format is
<placement>=<id> where: <placement> is either "before", "after", or "endof" and <id> is the id of an existing menu item. The placement modifier is executed when this contribution is processed. Following contributions may change the final shape of the menu when they are processed.

启动原理

这个只是概览,具体细节尚未验证。

eclipse的主菜单的加载是硬编码上去的,在org.eclipse.ui.internal.WorkbenchWindow 中定义了一个菜单:

<!-- lang: java -->
mainMenu.setElementId("org.eclipse.ui.main.menu"); //$NON-NLS-1$

接着通过 org.eclipse.ui.internal.ide.WorkbenchActionBuilder来填充workbench菜单

<!-- lang: java -->
protected void More ...fillMenuBar(IMenuManager menuBar) {
    menuBar.add(createFileMenu());
     menuBar.add(createEditMenu());
    menuBar.add(createNavigateMenu());
     menuBar.add(createProjectMenu());
     menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
     menuBar.add(createWindowMenu());
     menuBar.add(createHelpMenu());
 }

这样入口就有了,其余的插件就在这个的基础上来附加,并且菜单项目还有visibleWhen子项来测试菜单项目是否可以在当前条件下面显示。

如果要创建一个产品需要创建自己的主菜单定义那么需要扩展自己的ApplicationActionBarAdvisor来定义主菜单中的条目。但这个时候主菜单的id依然是”org.eclipse.ui.main.menu“

转载于:https://my.oschina.net/lxbzj/blog/156834

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值