Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Dynamically adding context/popup menus to Editors
Dynamically adding context/popup menus to Editors [message #329223] Mon, 16 June 2008 19:39 Go to next message
Eclipse UserFriend
Originally posted by: prasad.chand.gmail.com

Hi All,

I wish to dynamically add a context/popup menu to an editor created by
me. I have declared a TextEditor inisde my editor. I have been following
"Building Commercial-Quality plugins" but I am unable to find any
examples of adding these menus dynamically *for TextEditors*. All the
examples have viewers or trees. Can someone please enlighten me about
how to add these menus. Any code samples would be greatly useful. I have
looked at the editorContextMenuAboutToShow() in TextEditor but it is a
protected method and I am already extending EditorPart.

I have been struggling for days with this problem.

Prasad
Re: Dynamically adding context/popup menus to Editors [message #329246 is a reply to message #329223] Tue, 17 June 2008 12:39 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Declared a text editor "inside" your editor? What do you mean? Are you
in a MultiPageEditorPart?

Normally for text based editors, you would subclass AbstractTextEditor
or TextEditor itself. Another alternative is to use a TextViewer or
SourceViewer in your EditorPart (both of which are configurable).


Or do you mean you are using TextEditor inside your editor with
something like "textEditor.createPartControl(parent)"?

If the latter, that really won't work reliably since you can't host an
editor in an editor (at least not well).

As for context menus, you can add to them programmatically if you are
the EditorPart that creates them or if owning EditorPart exposes the
context MenuManager some way. The other alternative is to use
org.eclipse.ui.popupMenus/viewerContribution,
org.eclipse.ui.popupMenus/objectContribution or
org.eclipse.ui.menus/menuContribution ... once you find the correctly
registered context menu id.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: Dynamically adding context/popup menus to Editors [message #329255 is a reply to message #329246] Tue, 17 June 2008 16:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: prasad.chand.gmail.com

Hi Paul,

Thanks for your response.

Paul Webster wrote:
> Declared a text editor "inside" your editor? What do you mean? Are you
> in a MultiPageEditorPart?

Yes I am using a MultiPageEditorPart. My editor class(say GrammerEditor)
extends MultipageEditorPart. I declared a private instance of TextEditor
in this editor class(GrammerEditor). I have been trying to add the menu
to this private instance (texteditor) rather than the GrammerEditor.

>
> Normally for text based editors, you would subclass AbstractTextEditor
> or TextEditor itself. Another alternative is to use a TextViewer or
> SourceViewer in your EditorPart (both of which are configurable).
>

Well truth is I was sticking to the examples in the book. So I guess I
would now extend TextEditor rather than MultipageEditorPart inspite of
loosing multi-tab functionality which I was hoping to use later. If I
extend TextEditor I hope to use the editorContextMenuAboutToShow() to
create the menus.

>
> Or do you mean you are using TextEditor inside your editor with
> something like "textEditor.createPartControl(parent)"?
>
> If the latter, that really won't work reliably since you can't host an
> editor in an editor (at least not well).
>
> As for context menus, you can add to them programmatically if you are
> the EditorPart that creates them or if owning EditorPart exposes the
> context MenuManager some way. The other alternative is to use
> org.eclipse.ui.popupMenus/viewerContribution,
> org.eclipse.ui.popupMenus/objectContribution or
> org.eclipse.ui.menus/menuContribution ... once you find the correctly
> registered context menu id.

This is another problem. I am still confused about the targetID for
popupMenus/viewerContribution. Is this achieved by appending ".context"
to the id of the editor?

>
> PW
>
>

Thanks again,
Prasad
Re: Dynamically adding context/popup menus to Editors [message #329334 is a reply to message #329255] Thu, 19 June 2008 14:19 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Prasad Chand wrote:
> Hi Paul,
>
> This is another problem. I am still confused about the targetID for
> popupMenus/viewerContribution. Is this achieved by appending ".context"
> to the id of the editor?

No, for example use ALT+SHIFT+F1 while in the java editor. It will list
a set of active context menu IDs. They default to the viewId when
registerContextMenu(*) is called with no ID, or to the ID specified in
the registerContextMenu(*) call.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Previous Topic:Save off workspace on close
Next Topic:preventing the user from deleting certain resources in the project?
Goto Forum:
  


Current Time: Sat Jul 27 19:21:04 GMT 2024

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

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

Back to the top