通过扩展点方式为Eclispe 添加菜单:
主要包括下列3个扩展点:
org.eclipse.ui.commands (可以添加所有的菜单)
可以参考:http://www.vogella.de/articles/EclipseCommands/article.html#command 来学习commands。
org.eclipse.ui.actionSets (在新的Eclipse 版本中已经不推荐使用)
org.eclipse.ui.popupMenus
文章:http://www.ibm.com/developerworks/cn/opensource/os-cn-ecl-menuext/index.html 概述了这三种方式的应用。
当然,除了扩展点的方式,用代码也可以创建菜单。
写法大致如下:
private void hookContextMenu() {
IMenuManager fMenuMgr = new MenuManager(“#PopupMenu”);
fMenuMgr.setRemoveAllWhenShown(true);
// 添加 Actions
fMenuMgr.add(action);
Menu fMenu = fMenuMgr.createContextMenu(treeViewer.getControl());
treeViewer.getControl().setMenu(fMenu);
getSite().registerContextMenu(fMenuMgr, treeViewer);
}
总结:一般来讲,扩展点方法用来扩展已经存在的视图。而代码方式则用来新建视图时使用。
Eclispe 中一些和菜单有关的常量:
Command Core Expressions : http://wiki.eclipse.org/Command_Core_Expressions (可以通过这个来控制菜单项的可见性)