1

在我当前的 RCP 项目中,我使用MultipageEditorPart. 它有各种页面,上面有简单的 SWT 组合。组合包含一些 Text 和 Combo 元素。当用户右键单击编辑器页面时,我想要打开一个上下文菜单。这个菜单包含一个用于创建新编辑器页面的命令,上面有一个组合。

该命令已经在工作,但我对如何为编辑器实现上下文菜单一无所知。有人可以帮忙吗?

4

1 回答 1

2

This should be based on Action contributions: see Contributing Actions to the Eclipse Workbench

As an RCP-based example, You could check out "Designing a Workflow Editor Eclipse XML", where a contextual menu is added to an EditorPart, included in a MultipageEditorPart.

protected void createContextMenuFor(StructuredViewer viewer) { 
   MenuManager contextMenu = new MenuManager("#PopUp"); 
   contextMenu.add(new Separator("additions")); 
   contextMenu.setRemoveAllWhenShown(true); 
   contextMenu.addMenuListener(this); 
   Menu menu= contextMenu.createContextMenu(viewer.getControl()); 
   viewer.getControl().setMenu(menu); 
   getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer)); 

   } 

alt text

See also Step 18 for extending that context menu (section "Delete - Contextual Menu, requiring using GEF).

于 2010-02-11T12:41:33.110 回答