我在尝试从上下文菜单中删除添加插入点的一些插件时遇到了一些问题。在大多数情况下,我使用活动,这是有效的,因为大多数贡献都是通过行动完成的。但在其他一些情况下,贡献是弹出菜单贡献,我无法成功禁用这些条目。一个例子是Source-> Format菜单贡献。该贡献由插件org.eclipse.wst.sse.ui以下列方式完成:
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<menu
id="sourceMenuId"
label="%Source">
<command
commandId="org.eclipse.wst.sse.ui.format"
id="sourceFormat"
style="push">
<!-- Check to make sure that the handler is enabled before making visible -->
<visibleWhen checkEnabled="true" />
</command>
</menu>
</menuContribution>
我一直在尝试使用模式org.eclipse.wst.sse.ui / sourceFormat和org.eclipse.wst.sse.ui /.*。它们都在Eclipe HELIOS中工作,但它们不能在RAD(Rational Application Developer 8.0.2)中工作。 有没有其他方法可以禁用此弹出菜单贡献?这个问题可以与Eclipse版本相关吗?
答案 0 :(得分:0)
我遇到了类似的问题(例如:我在视图中出现的与Eclipse相关的右键菜单条目),我可以使用以下代码进行修复。
解决方案是我的应用程序中缺少的语句getSite().setSelectionProvider(viewer);
。这导致非视图相关的选择条目进入并激活菜单条目。希望它可以帮助有人在同一个问题上挣扎。
private void hookContextMenu() {
MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
....
Menu menu = menuMgr.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, viewer);
getSite().setSelectionProvider(viewer);
}