简体   繁体   中英

How to not show context menu for multi selection in Eclipse Plugin Development

Hi I am developing context menu in eclipse plugin. I need to show the context popup menu only if the user selects only one File. Currently, I am able to show the context menu for multi selection of Folders in the Project Explorer. The requirement is to disable or hide the context menu for multi selection of Folders. I cannot user the legacy context popup menu " " as it has been deprecated in eclipse.

I provide below the snippet of plugin.xml.

<?eclipse version="3.4"?>
<plugin>

   <extension point="org.eclipse.ui.commands">
      <category name="My Category" id="mycategory.id" />
      <command name="Drop it here" categoryId="mycategory.id" id="myCmd1" />
   </extension>

   <extension point="org.eclipse.ui.handlers">
      <handler commandId="myCmd1" class="com.toyer.FirstHandler" />
   </extension>

   <extension point="org.eclipse.ui.menus">
      <menuContribution locationURI="popup:org.eclipse.ui.popup.any">
         <command commandId="myCmd1" icon="icons/pino16.png">
            <visibleWhen>
               <with variable="activeMenuSelection">
                  <iterate ifEmpty="false">
                     <adapt type="org.eclipse.core.resources.IProject" />
                  </iterate>
               </with>
            </visibleWhen>
         </command>
      </menuContribution>
   </extension>

</plugin> 

Please help me to solve this issue.

Use count to limit the selection to 1

Something like:

<with variable="selection">
   <count value="1"/>
   <iterate>
       <adapt type="org.eclipse.core.resources.IFile"/>
   </iterate>
</with>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM