Jump to: navigation, search

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

Revision as of 07:24, 21 September 2006 by Annamalai.chockalingam.gmail.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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)