Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 227595

Summary: [Contributions] menus/commands added to popup:org.eclipse.ui.popup.any show up when they shouldnt
Product: [Eclipse Project] Platform Reporter: Amy Wu <for.work.things>
Component: UIAssignee: Paul Webster <pwebster>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: pwebster
Version: 3.4   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Amy Wu CLA 2008-04-17 12:35:06 EDT
Using 3.4 m6.  I'm not sure if this is really an issue with the menu/popup extension point or with the expression framework, but if I contribute a menu like the following, MySubMenu will show up in the popup menu even when I have nothing selected.  You can see this by selecting nothing in the Project/Package explorer and invoking the context menu.  You can also see this menu in views like the Javadoc view.

<extension point="org.eclipse.ui.menus">
   <menuContribution
      locationURI="popup:org.eclipse.ui.popup.any?after=additions">
      <menu id="mySubMenu" label="MySubMenu">
         <command
            commandId="org.eclipse.ui.help.aboutAction"
            style="push">
            <visibleWhen checkEnabled="false">
               <or>
                  <iterate>
                     <adapt
                        type="org.eclipse.core.resources.IContainer">
                        <test 
                           property="org.eclipse.core.resources.name" 
                           value="*.xml"/>
                     </adapt>
                  </iterate>
                  <iterate>
                     <adapt
                        type="org.eclipse.core.resources.IFile">
                        <test
                           property="org.eclipse.core.resources.name" 
                           value="*.xml"/>
                     </adapt>
                  </iterate>
               </or>	
            </visibleWhen>
         </command>
      </menu>
   </menuContribution>
</extension>
Comment 1 Paul Webster CLA 2008-04-17 12:43:52 EDT
For legacy reasons, iterate returns true when the collection is empty and the iterate operator == and (the default).

There should be an attribute that you can set to get your desired behaviour, iterate ifEmpty="false" would probably do it.

PW
Comment 2 Amy Wu CLA 2008-04-17 13:35:51 EDT
Oh yeah, ifEmpty="false" did the trick.  Thanks!  You can go ahead and resolve this as invalid (I would, but I didn't know if you wanted a target milestone or not)

Also, I'm not sure if you'd want to update http://wiki.eclipse.org/Menu_Contributions/IFile_objectContribution or not with that ifEmpty attribute (that's what I was referencing when I was trying to do mine)
Comment 3 Paul Webster CLA 2008-04-17 14:03:20 EDT
I've updated the wiki as well,

Thanx,
PW