如何在 Eclipse 插件开发中不显示用于多选的上下文菜单

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

我正在为 Eclipse 插件开发上下文菜单。仅当用户选择单个文件时,我才需要显示上下文弹出菜单。目前,我能够在 Project Explorer 中显示用于多选文件夹的上下文菜单。要求是禁用或隐藏用于多选文件夹的上下文菜单。 我无法使用遗留上下文弹出菜单“”,因为它已在 Eclipse 中弃用。

我提供了我的 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> 

请帮我解决这个问题。

使用count将选择限制为1

类似于:

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