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
m
Line 22: Line 22:
 
Extension allows Eclipse IDE to be added with modules for various purpose. <code>org.eclipse.ui.popupMenus</code> will be required. For further information, see
 
Extension allows Eclipse IDE to be added with modules for various purpose. <code>org.eclipse.ui.popupMenus</code> will be required. For further information, see
 
[http://help.eclipse.org/help33/topic/org.eclipse.platform.doc.isv/guide/arch.htm Platform architecture]  
 
[http://help.eclipse.org/help33/topic/org.eclipse.platform.doc.isv/guide/arch.htm Platform architecture]  
(insert image)
+
[[Image:02extension.png]]
  
 
== contribution ==
 
== contribution ==
Line 28: Line 28:
 
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/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]
 
A viewer Contribution was created with the targetID as #CEditorContext
 
A viewer Contribution was created with the targetID as #CEditorContext
(insert image)
+
[[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'''
(image)
+
[[Image:04action.png]]
  
 
Invalid path resulting in menu not shown
 
Invalid path resulting in menu not shown

Revision as of 10:47, 8 February 2008

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.

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,object and viewer contribution 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 04action.png

Invalid path resulting in menu not shown (image 04menuA)

Paths are not cumulative, no menu (image 04menuB)

Right clicking for menu is no longer possible (image 04menuC)

Added to a new named group called abcd, just above additions,possible to appear after. (image 04menuD)

It appears that only one menu maybe added to additions, no Add Test shown (image 04menuE)

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

(image 05action) (image 05actionA-C)

(menu)/(menu)/(GroupMarker)


No menu shown as based on IWorkbenchActionConstants.MB_ADDITIONS which is empty at the moment. see popup menu (image 05actionE)


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

Platform Plug-in Developer Guide > Programmer's Guide > Plugging into the workbench > Basic workbench extension points using actions org.eclipse.ui.popupMenus

C++ Unit Testing Easier

help to update this page

Back to the top