Eclipse 3.5: Implementing my own context menu for a MultipageEditorPart --> no viewer involved
In my current RCP-project i use a MultipageEditorPart
. It has various pages, with simple SWT composites on it. The composites contain some Text and Combo elements. When the user right clicks onto the editor page, I want a context menu to open. This menu holds a command for creating a new editor page, with a composite on it.
The command is already working, but I'm quite cluele开发者_运维技巧ss about how to implement the context menu for the editor. Can someone help with this?
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));
}
See also Step 18 for extending that context menu (section "Delete - Contextual Menu, requiring using GEF).
精彩评论