Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

FAQ How to create a context menu & add actions to the same?

To create a Context Menu for your View or Editor do the following :


Step 1. Use popupMenus Extension point as explained in the Help of Eclipse. Creating Popup Menus

Step 2. You need to also register the context menu to the ViewSite or to the EditorSite which will contain the context menu. This is done using the registerContextMenu function available with ISite.

The following code snippet explains how to register the context menu to your View.

      private void hookContextMenu() {
		MenuManager menuMgr = new MenuManager("#PopupMenu");
		menuMgr.setRemoveAllWhenShown(true);
		Menu menu = menuMgr.createContextMenu(<Your Viewer>.getControl());
		<Your Viewer>.getControl().setMenu(menu);
		getSite().registerContextMenu(menuMgr, <Your Viewer>);
	}
 

This function needs to be implemented and then called from createPartControl().

--Annamalai.chockalingam.gmail.com 07:24, 21 September 2006 (EDT)

Back to the top