Eclipse插件(Kepler)中的自定义视图上的弹出菜单 [英] Popup menu on custom view in Eclipse Plug-In (Kepler)
问题描述
是否可以为Eclipse Kepler中的自定义视图提供静态弹出菜单?创建动态控件很容易,但是我希望能够像在Project Explorer中一样在plugin.xml文件中定义命令。
用Eclipse Spy查看我的自定义视图,我看不到任何活动菜单贡献标识符。如何定义一个?
Is there a way to provide a static popup menu for a custom view in Eclipse Kepler? Creating a dynamic one is easy, but I would like to be able to define the commands in the plugin.xml file as for the Project Explorer. Looking at my custom view with the Eclipse Spy I see no active menu contribution identifiers. How can I define one?
推荐答案
在您的视图部件中设置上下文菜单,如下所示:
In your view part set up the context menu like this:
MenuManager contextMenu = new MenuManager();
contextMenu.setRemoveAllWhenShown(true);
Control control = viewer.getControl();
Menu menu = contextMenu.createContextMenu(control);
control.setMenu(menu);
getSite().registerContextMenu(contextMenu, viewer);
registerContextMenu
调用使菜单可用于 org.eclipse.ui.menus
扩展点,因此您可以定义如下菜单项:
The registerContextMenu
call makes the menu available to the org.eclipse.ui.menus
extension point so you can define menu items like this:
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:your view id here">
... you menu items ...
这篇关于Eclipse插件(Kepler)中的自定义视图上的弹出菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!