Dynamically adding context/popup menus to Editors [message #329223] |
Mon, 16 June 2008 19:39 |
Eclipse User |
|
|
|
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 #329255 is a reply to message #329246] |
Tue, 17 June 2008 16:06 |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03223 seconds