开发者

Eclipse 3.5: Implementing my own context menu for a MultipageEditorPart --> no viewer involved

开发者 https://www.devze.com 2022-12-20 08:08 出处:网络
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

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)); 

   } 

Eclipse 3.5: Implementing my own context menu for a MultipageEditorPart --> no viewer involved

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

0

精彩评论

暂无评论...
验证码 换一张
取 消