Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "CDT/Developer/FAQ/popupMenu"

m
(contribution: fixup old links)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
= Howto add menu items, submenu to CDT ''Source'' popup =
 
= Howto add menu items, submenu to CDT ''Source'' popup =
  
The motivation of this page 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.
+
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.
  
 
[[Image:01screenshot.png]]
 
[[Image:01screenshot.png]]
Line 26: Line 26:
 
== contribution ==
 
== contribution ==
  
Contribution are for managing shared UI items. see [http://help.eclipse.org/help33/topic/org.eclipse.platform.doc.isv/guide/jface_actions.htm?resultof=%22%63%6f%6e%74%72%69%62%75%74%69%6f%6e%22%20%22%63%6f%6e%74%72%69%62%75%74%22%20 Actions and contributions],[http://help.eclipse.org/help33/topic/org.eclipse.platform.doc.isv/guide/workbench_basicext_popupMenus.htm?resultof=%22%70%6f%70%75%70%4d%65%6e%75%22%20%22%70%6f%70%75%70%6d%65%6e%75%22%20 object and viewer contribution]
+
Contribution are for managing shared UI items. see [http://help.eclipse.org/latest/topic/org.eclipse.platform.doc.isv/guide/jface_actions.htm Actions and contributions]
 
A viewer Contribution was created with the targetID as #CEditorContext
 
A viewer Contribution was created with the targetID as #CEditorContext
[[Image:03viewer_contribution.png]]  
+
[[Image:03viewer_contribution.png]]
  
 
== menu ==
 
== 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 [http://help.eclipse.org/help33/topic/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_popupMenus.html?resultof=%22%70%6f%70%75%70%4d%65%6e%75%22%20%22%70%6f%70%75%70%6d%65%6e%75%22%20 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'''
+
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 [http://help.eclipse.org/help33/topic/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_popupMenus.html?resultof=%22%70%6f%70%75%70%4d%65%6e%75%22%20%22%70%6f%70%75%70%6d%65%6e%75%22%20 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'''<br>
[[Image:04action.png]]  
+
[[Image:04menu.png]]  
  
Invalid path resulting in menu not shown
+
Invalid path resulting in menu not shown<br>
(image 04menuA)
+
[[Image:04menuA.png]]
  
Paths are not cumulative, no menu
+
Paths are not cumulative, no menu<br>
(image 04menuB)
+
[[Image:04menuB.png]]
  
Right clicking for menu is no longer possible
+
Right clicking for menu is no longer possible<br>
(image 04menuC)
+
[[Image:04menuC.png]]
  
Added to a new named group called '''abcd''', just above '''additions''',possible to appear after.  
+
Added to a new named group called '''abcd''', just above '''additions''',possible to appear after. <br>
(image 04menuD)
+
[[Image:04menuD.png]]
  
It appears that only one menu maybe added to additions, no Add Test shown
+
It appears that only one menu maybe added to additions, no Add Test shown<br>
(image 04menuE)
+
[[Image:04menuE.png]]
  
 
The working path that creates the submenu that I wanted
 
The working path that creates the submenu that I wanted
Line 63: Line 63:
 
For the desired submenu, the menubarPath: '''org.eclipse.cdt.ui.source.menu/addTestMenu/addTestGroup'''
 
For the desired submenu, the menubarPath: '''org.eclipse.cdt.ui.source.menu/addTestMenu/addTestGroup'''
  
(image 05action)
+
[[Image:05action.png]]<br>
(image 05actionA-C)
+
  
(menu)/(menu)/(GroupMarker)
+
[[Image:05actionA.png]]<br>
  
 +
[[Image:05actionB.png]]<br>
 +
 +
[[Image:05actionc.png]]<br>
 +
 +
[[Image:05actiond.png]]<br>
 +
 +
(menu)/(menu)/(GroupMarker)
  
 
No menu shown as based on IWorkbenchActionConstants.MB_ADDITIONS which is empty at the moment. see popup menu
 
No menu shown as based on IWorkbenchActionConstants.MB_ADDITIONS which is empty at the moment. see popup menu
(image 05actionE)
+
[[Image:05actione.png]]
  
  
Line 138: Line 144:
 
= References =
 
= References =
  
[http://help.eclipse.org/help33/topic/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_popupMenus.html?resultof=%22%70%6f%70%75%70%4d%65%6e%75%22%20%22%70%6f%70%75%70%6d%65%6e%75%22%20 Platform Plug-in Developer Guide > Reference > Extension Points Reference > Pop-up Menus]
+
[http://help.eclipse.org/latest/topic/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_popupMenus.html Platform Plug-in Developer Guide > Reference > Extension Points Reference > Pop-up Menus]
 
+
[http://help.eclipse.org/help33/topic/org.eclipse.platform.doc.isv/guide/workbench_basicext_popupMenus.htm?resultof=%22%70%6f%70%75%70%4d%65%6e%75%22%20%22%70%6f%70%75%70%6d%65%6e%75%22%20 Platform Plug-in Developer Guide > Programmer's Guide > Plugging into the workbench > Basic workbench extension points using actions org.eclipse.ui.popupMenus]
+
  
 
[http://www.ifs.hsr.ch/Projects/Projects/Cute C++ Unit Testing Easier]
 
[http://www.ifs.hsr.ch/Projects/Projects/Cute C++ Unit Testing Easier]
  
 
[http://wiki.eclipse.org/index.php?title=CDT/Developer/FAQ/popupMenu&action=edit help to update this page]
 
[http://wiki.eclipse.org/index.php?title=CDT/Developer/FAQ/popupMenu&action=edit help to update this page]

Latest revision as of 14:54, 22 January 2020

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