Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [pde-dev] dynamically contributing to the target editor's context menu

Hi Brian,
 
I have posted the questions to the Eclipse newsgroup with no solutions yet. Please provide me some input for the below mentioned problem :
I want to access the context menu of any text editor and populate my menu items (submenus and menu items within the submenus) dynamically.
 
I was able to add nested submenus and menu items to the submenus in the context menu of the default text editor, through the plugin.xml.
The action class i.e. the actiondelegate class run method runs the IExtensionRegistry's addContribution function to append menuitems to the submenu. But after a click on the context menu, it is not displayed(as normal behaviour) and again i need to right click to bring up the updated context menu.
 
Is it possible to first programatically populate the context menu before showing it in the editor. so that whenever i right click before showing the context menu , my dynamic code should be run to show the updated context menu.
 
Earlier the same functionality was implemented with the following steps:
1) Created my text editor, MacrosEditor, by extending the TextEditor.
2) In the CreateActions() created actions and submenus.
3) In the editorContextMenuAboutToShow(IMenumanager menu) added the above submenus  in the context Menu of the editor .It has the code to check whether further menu items need to be added to the submenus before the context menu is displayed.
Then after i open any file with MacrosEditor, I can easily see my submenu and their child menu items in the context menu. Whenever I right click within the editor window, the editorContextMenuAboutToShow(..) is called to reflect the latest menu items before the context menu is displayed.
This implementation was simple.But the only drawback with this implementation was that a file should be opened with the MacrosEditor to show the functionality.
What I currently require is that the functionality should be provided with any text editor.
 
Hope you may have understood this much elaborated problem.
Please let me know if you have any solution to it.
 
Thanks
 
 
 
 
 

 
On 4/9/07, Brian de Alwis <bsd@xxxxxxxxx> wrote:
You really should post your questions to the Eclipse newsgroups: you'll
get far better answers there.  I've tried to avoid understanding
menus as much as possible.  But I think your problem is that you can
only add items to groups, and not to menus directly.  So in your
second menu (....InsertTag) I think you need to create a separator,
and reference that separator in your action's menubarPath.

Brian.

On 2007.04.09 18:02:27 +0530, Eclipse Questions wrote:
> Hi Brian,
>
> I am looking for a dynamic menu creation. But before using the
> IExtensionRegistry,first I tried to look for the static menu creation.
>
> I have the following in plugin.xml
>
>
> <menu  id="macros.action.contribution.subMenu.Macros" label="Macros"
> path="additions">
>     <separator name="group1"/>
>     </menu>
>
>     <menu id="macros.action.contribution.subMenu.InsertTag" label = "Insert
> Tag"
>      path="additions/macros.action.contribution.subMenu.Macros/group1">
>   </menu>
>
>
>   <action id="macros.action.contribution.insertaction1" label="Insert
> Action 1"
>        icon="icons/sample.gif"
>        menubarPath=" macros.action.contribution.subMenu.InsertTag"
>         class="
> com.accenture.dde.plugins.macroseditor.actions.PopupMenuActionDelegate1">
>    </action>
>
>     <action
>        id="macros.action.contribution.createaction"
>        label="Create Tag"
>        icon="icons/sample.gif"
>        menubarPath="macros.action.contribution.subMenu.Macros /group1"
>        class="
> com.accenture.dde.plugins.macroseditor.actions.PopupMenuActionDelegate1">
>     </action>
>
> >From the above part , I wish the following in the context menu:
>
> Macros - > Insert Tag - > Insert Action 1
>            - > Create Tag
>
> where 'Macros' is a submenu , 'Insert Tag' is a submenu under 'Macros'
> submenu ; 'Insert Action 1' and  'Create Tag' are simple actions
> But i am not getting the desired display of the menu . What I get in the
> context menu is as follows:
>
> Macros -> Create Tag
> ...........
> ...........
> Insert Action 1
>
> Please let me know where am i going wrong .... Also I am using Eclipse v3.2.
>
> Thanks
>
>
>
> On 4/5/07, Eclipse Questions < eclipse.questions@xxxxxxxxx> wrote:
> >
> >Hi Brain,
> >
> >Thanks.
> >1) Are there any messages in the log?      *Let me know where are the logs
> >stored ?*
> >2) Are you sure it's a #TextEditorContext? Yes "#TextEditorContext" is the
> >context menu id for the default editor. The 'EditorAction1' label is
> >shown in the context menu of all the editors that (i think) are extended
> >from the TextEditor class.
> >3) Are you sure testdynamiccont.actions.PopupMenuActionDelegate1implements
> >IEditorActionDelegate? *This is the right catch :-).* I saw that the class
> >was extended from IObjectActionDelegate ( this is the copy/paste problem).
> >I
> >changed it accordingly.Now it works fine. it shown me the dialog box.
> >
> >Thanks so much for the quick help. Now I will try to dynamically generate
> >the submenus and actions by parsing an xml file using the
> >IExtentionRegistry
> >API.
> >I will continue appending queries to this post. Please continue with the
> >help further.
> >
> >Regards.
> >
> >
> >
> >
> >On 4/4/07, Brian de Alwis <bsd@xxxxxxxxx> wrote:
> >>
> >> On 2007.04.04 18:02:27 +0530, Eclipse Questions wrote:
> >> > <viewerContribution
> >> >      id=" com.action.contribution.popup.view"
> >> >   targetID="#TextEditorContext">
> >> >   <action
> >> >         id=" com.accenture.testdynamic.action3"
> >> >         label="*EditorAction1*"
> >> >         icon="icons/sample.gif"
> >> >      menubarPath="additions"
> >> >      class="testdynamiccont.actions.PopupMenuActionDelegate1">
> >> >      </action>
> >> >   </viewerContribution>
> >> > </extension>
> >> > </plugin>
> >>
> >> Are there any messages in the log?
> >> Are you sure it's a #TextEditorContext?
> >> Are you sure testdynamiccont.actions.PopupMenuActionDelegate1 implements
> >> IEditorActionDelegate?
> >>
> >> Looking at my code, I have two differences in the action element:
> >> * I have an explicit enablesFor="*"
> >> * I have a definitionId to a defined command
> >>
> >> Brian.
> >>
> >> --
> >> Brian de Alwis | Software Practices Lab | UBC |
> >> http://www.cs.ubc.ca/~bsd/
> >>      "Amusement to an observing mind is study." - Benjamin Disraeli
> >>
> >
> >

--
Brian de Alwis | Software Practices Lab | UBC | http://www.cs.ubc.ca/~bsd/
     "Amusement to an observing mind is study." - Benjamin Disraeli


Back to the top