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"
<filter name="projectPersistentProperty"
value="org.eclipse.team.core.repository=org.eclipse.egit.core.GitProvider">
id="org.eclipse.egit.ui.transportSubMenu"
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
Thanks a lot Paul.
Of course I already thought of your 1), but I believe this is not really an option, as it would sacrifice usability.
Your number 2) to (shadowing the original Team) menu is a very interesting approach. Leaving the issue of translating the “Team” menu label aside for the moment, I kind of like this best as it would allow us to not only add submenus but also change to pure command contribution of our menu entries (BTW, would other object contributions referring to “team.main” still appear here?).
I tried it out and it almost worked perfectly, with the small exception that the property tester appears only to return true on the first EGit project (org.eclipse.egit) in my workspace, but not on the others (org.eclipse.egit.ui, for example), so the new submenu would not show on the other projects. I debugged this and it doesn’t appear to be a problem with the persistent properties (at least I got the expected one from all projects at runtime during debugging). Perhaps you have some idea.
I also got your 3) to work (using the rather deprecated DropDownDelegate). It’s not nice and I totally agree with your reservations. I still can’t quite make up my mind if we should use it, since to me it looks far less “dangerous” than shadowing of the Team menu…
If we can get the issue with the property tester resolved, I guess I might suggest a new Team menu using 2) unless I hear some other opinions.