Skip to main content
Jump to: navigation, search

CDT/Developer/FAQ/popupMenu

< CDT‎ | Developer/FAQ
Revision as of 14:54, 22 January 2020 by Jonah.kichwacoders.com (Talk | contribs) (contribution: fixup old links)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Howto add menu items, submenu to CDT Source popup

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.

01screenshot.png

Plug-in used

Eclipse PDE 3.3.1.1
CDT 4.0.2
Plug-in in development (CUTE)

Steps

  1. add extension
  2. add contribution
  3. add menu
  4. add groups
  5. 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 02extension.png

contribution

Contribution are for managing shared UI items. see Actions and contributions A viewer Contribution was created with the targetID as #CEditorContext 03viewer contribution.png

menu

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
04menu.png

Invalid path resulting in menu not shown
File:04menuA.png

Paths are not cumulative, no menu
04menuB.png

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
04menuE.png

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

05action.png

05actionA.png

05actionB.png

File:05actionc.png

05actiond.png

(menu)/(menu)/(GroupMarker)

No menu shown as based on IWorkbenchActionConstants.MB_ADDITIONS which is empty at the moment. see popup menu 05actione.png


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

C++ Unit Testing Easier

help to update this page

Back to the top