Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
CDT/Developer/FAQ/popupMenu
Contents
The motivation of this page(draft of the draft quality) is to allow the plug-in developer to add more menus to the Source menu. It stem from spending two working days trying to learn how to add a submenu with 3 items.
Plug-in used
Eclipse PDE 3.3.1.1
CDT 4.0.2
Plug-in in development (CUTE)
Steps
- add extension
- add contribution
- add menu
- add groups
- add action
extension
Extension allows Eclipse IDE to be added with modules for various purpose. org.eclipse.ui.popupMenus
will be required. For further information, see
Platform architecture
contribution
Contribution are for managing shared UI items. see Actions and contributions A viewer Contribution was created with the targetID as #CEditorContext
An option that may/may not be displayed. In this case, Test Code will not be shown, where as Add Test will be shown. Each menu requires an unique identifier, a label which may include mnemonic and a path. see Pop-up Menus The path is separated by /, and thus you can have an id with period within as shown. For CDT Source, the path is org.eclipse.cdt.ui.source.menu. For Test Code the group marker was omitted and thus defaulted to the group called additions
Invalid path resulting in menu not shown
File:04menuA.png
Paths are not cumulative, no menu
Right clicking for menu is no longer possible
File:04menuC.png
Added to a new named group called abcd, just above additions,possible to appear after.
File:04menuD.png
It appears that only one menu maybe added to additions, no Add Test shown
The working path that creates the submenu that I wanted org.eclipse.cdt.ui.source.menu/ch.hsr.ifs.cutelauncher.testCodeMenu
groups
Groupmarker are virtual entity used to represent the menu. It doesnt have any visual representation but action are attached to it.
action
Action do the processing work, the Action class doesnt have any UI, its UI is represented via popupMenus.
For the desired submenu, the menubarPath: org.eclipse.cdt.ui.source.menu/addTestMenu/addTestGroup
(menu)/(menu)/(GroupMarker)
No menu shown as based on IWorkbenchActionConstants.MB_ADDITIONS which is empty at the moment. see popup menu
plugin.xml extract
<extension point="org.eclipse.ui.popupMenus"> <viewerContribution id="ch.hsr.ifs.cutelauncher.cEditorContribution" targetID="#CEditorContext"> <action class="ch.hsr.ifs.cutelauncher.ui.sourceactions.NewTestFunctionActionDelegate" definitionId="cute_plugin.command1" id="ch.hsr.ifs.cutelauncher.addTestMemberSuiteAction" label="Add Test Member to Suite" menubarPath="org.eclipse.cdt.ui.source.menu/addTestMenu/addTestGroup"> </action> <action class="ch.hsr.ifs.cutelauncher.ui.sourceactions.NewTestFunctionActionDelegate" definitionId="cute_plugin.command1" id="ch.hsr.ifs.cutelauncher.addTestFunctorSuiteAction" label="Add Test Functor to Suite" menubarPath="org.eclipse.cdt.ui.source.menu/addTestMenu/addTestGroup"> </action> <action class="ch.hsr.ifs.cutelauncher.ui.sourceactions.NewTestFunctionActionDelegate" definitionId="cute_plugin.command1" id="ch.hsr.ifs.cutelauncher.addTestFunctionSuiteAction" label="Add Test Function to Suite" menubarPath="org.eclipse.cdt.ui.source.menu/addTestMenu/addTestGroup"> </action> <action class="ch.hsr.ifs.cutelauncher.ui.sourceactions.NewTestFunctionActionDelegate" definitionId="ch.hsr.ifs.cutelauncher.newTestFunctionCommand" id="ch.hsr.ifs.cutelauncher.newTestFunctionAction" label="New Test Function" menubarPath="org.eclipse.cdt.ui.source.menu/ch.hsr.ifs.cutelauncher.testCodeMenu"> </action> <menu id="ch.hsr.ifs.cutelauncher.testCodeMenu" label="Test Code" path="org.eclipse.cdt.ui.source.menu"> <groupMarker name="ch.hsr.ifs.cutelauncher.testCodeMenu"> </groupMarker> </menu> <menu id="addTestMenu" label="Add Test" path="org.eclipse.cdt.ui.source.menu/ch.hsr.ifs.cutelauncher.testCodeMenu"> <groupMarker name="addTestGroup"> </groupMarker> </menu> </viewerContribution> </extension>
ideas
Writing XML by hand is difficult. The wonderful wizards in Eclipse lighten the load, but troubleshooting are still extremely difficult. If only it were smart enough to know the different linkage.
popupMenus extension Designer similar to Visual Studio Menu editor[1].
References
Platform Plug-in Developer Guide > Reference > Extension Points Reference > Pop-up Menus