Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [egit-dev] Submenu in Team context menu?


Comments inline:

On Fri, Jan 21, 2011 at 7:03 AM, Kinzler, Mathias <mathias.kinzler@xxxxxxx> wrote:

1. First approach: adding a “menu” element
I added a “menu” element to the popupMenu extension like this:
 
   <extension point="org.eclipse.ui.popupMenus">
      <objectContribution id="org.eclipse.egit.ui.projectContributions"
            objectClass="org.eclipse.core.resources.IProject"
            adaptable="true">
         <filter name="projectPersistentProperty"
               value="org.eclipse.team.core.repository=org.eclipse.egit.core.GitProvider">
         </filter>
         <menu
               id="org.eclipse.egit.ui.transportSubMenu"
               label="GitSubMenu"
               path="test">
            <groupMarker
                  name="group1">
            </groupMarker>
         </menu>
         ...
 

Using popupMenus this is your best bet.
 
 
The trouble seems to be that the menu manager that tries to add the contribution can not find the "team.main" submenu (which is probably because the team.main submenu is itself implemented using the "objectContribution" extension).

Right.  In objectContributions, all menus are processed and then all actions are processed.  That's why actions can depend on menus from other objectContributions.  But menus can't, since extension order is indeterminate and there's no guarantee that the menu you want will have been processed.
 
 
2. Second approach: Adding an "action" element and trying to dynamically instantiate a sub-menu
This is possible by letting the implementation class implement IActionDelegate2, as this provides the "run"-event into the run()

I would recommend against dropdown action delegates, as they are not well supported in e4/4.x (they were a horrible breaking of encapsulation).

Some options:

1) just contribute your menu right next to the Team menu, using your first approach.

2) you can use org.eclipse.ui.menus although you have to add the "team" [1] menu first.  ex:

      <menuContribution
            allPopups="false"
            locationURI="popup:team.main?after=group1">
         <menu
               id="z.ex.target.git"
               label="Git About">
            <command
                  commandId="org.eclipse.ui.help.aboutAction"
                  id="z.ex.target.team.aboutAction"
                  label="Team About"
                  mnemonic="u"
                  style="push">
               <visibleWhen
                     checkEnabled="false">
                  <with
                        variable="activeMenuSelection">
                        <count value="+"/>
                        <iterate operator="and" ifEmpty="false">
                           <test
                                 args="org.eclipse.team.core.repository,org.eclipse.egit.core.GitProvider"
                                 property="org.eclipse.core.resources.projectPersistentProperty">
                           </test>
                        </iterate>
                  </with>
               </visibleWhen>
            </command>
         </menu>
      </menuContribution>

3) if you want to use a dropdown delegate, see how org.eclipse.debug.internal.ui.actions.RunContextualLaunchAction implements it for &Run As.  I still recommend against this.



[1] adding the team menu using org.eclipse.ui.menus.  Since the Team label is translatable, I'm not sure what to do about that.

      <menuContribution
            allPopups="false"
            locationURI="popup:org.eclipse.ui.popup.any?after=additions">
         <menu
               id="team.main"
               label="Team"
               mnemonic="e">
            <separator
                  name="group1"
                  visible="true">
            </separator>
            <separator
                  name="applyPatchGroup"
                  visible="false">
            </separator>
            <separator
                  name="group2"
                  visible="true">
            </separator>
            <separator
                  name="group3"
                  visible="true">
            </separator>
            <separator
                  name="group4"
                  visible="true">
            </separator>
            <separator
                  name="group5"
                  visible="true">
            </separator>
            <separator
                  name="group6"
                  visible="true">
            </separator>
            <separator
                  name="group7"
                  visible="true">
            </separator>
            <separator
                  name="group8"
                  visible="true">
            </separator>
            <separator
                  name="group9"
                  visible="true">
            </separator>
            <separator
                  name="group10"
                  visible="true">
            </separator>
            <separator
                  name="targetGroup"
                  visible="true">
            </separator>
            <separator
                  name="projectGroup"
                  visible="true">
            </separator>
            <visibleWhen
                  checkEnabled="false">
               <with
                     variable="activeMenuSelection">
                  <count
                        value="+">
                  </count>
                  <!--iterate
                        ifEmpty="false"
                        operator="and">
                     <adapt // I wasn't quite sure what to do here.
                           type="org.eclipse.core.resources.mapping.ResourceMapping">
                     </adapt>
                  </iterate-->
               </with>
            </visibleWhen>
         </menu>
      </menuContribution>




--
Paul Webster
Hi floor.  Make me a sammich! - GIR

Back to the top