Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Contributing menu items to an existing editor at run-time
Contributing menu items to an existing editor at run-time [message #133956] Mon, 22 September 2003 18:04
Eclipse UserFriend
Originally posted by: lite_cheng.yahoo.ca

Hi,

I would like to add new menu items at runtime to an *existing* editor,
such as the Java Editor or the default Text Editor. Is it possible?

I've seen numerous examples in the newsgroup describing how to add dynamic
menu items to context menus using MenuManager.addMenuListener(), but these
seem to apply when creating a custom editor (e.g. define a brand new
editor, during initialization create a MenuManager, add a IMenuListener to
trap "menuAboutToShow", call IWorkbenchPartSite.registerContextMenu,
etc....)

However, I don't see in IEditorPart, IEditorSite, etc a way to retrieve
the MenuManager for their context menus. Thus, I can't attach my own
IMenuListener to the manager.

In my IEditorActionDelegate, I tried creating my own MenuManager from
scratch in selectionChanged(), e.g.

MenuManager myManager = new
MenuManager("#CompilationUnitEditorContext");
myManager.setRemoveAllWhenShown(true);
myManager.addMenuListener( new IMenuListener() {
public void menuAboutToShow( IMenuManager menuManager )
{
// add new menu items at runtime
menuManager.add(myAction1);
menuManager.add(myAction2);
...
}
}
editor.getEditorSite().registerContextMenu( myManager,
((AbstractTextEditor) editor).getSelectionProvider() );

However, this doesn't seem to work. Stepping through this, it looks like
the menu manager doesn't get "added" to the MenuManager of the Java
editor, and these steps normally would have calls like
"createContextMenu() ... setMenu()", which requires the actual StyledText
widget associated with the editor.

Am I missing something here, or is this cannot be done, or is pending a
future release?

Thanks,

Li-Te
Previous Topic:Add Open action to the File menu?
Next Topic:[JFace] - Question for Designers of JFace.
Goto Forum:
  


Current Time: Fri Apr 19 22:53:45 GMT 2024

Powered by FUDForum. Page generated in 0.02781 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top