Name filter for eclipse.ui.menus

狂风中的少年 提交于 2019-12-23 13:19:08

问题


I've got a menu contribution, realised through org.eclipse.ui.menus extension point. I'd like to offer this menu contribution only for specific file extensions (e.g. *.pld), but I couldn't figure out how to do this with "visibleWhen". Any ideas?

---------------Update---------------- My extension point so far:

<extension
         point="org.eclipse.ui.menus">
      <menuContribution
            allPopups="false"
            locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?before=additions">
         <command
               commandId="org.variability.configurator.commands.createPlc"
               icon="icons/PlcWizard.png"
               label="Create Product"
               style="push">
            <visibleWhen
                  checkEnabled="false">

            </visibleWhen>
         </command>
      </menuContribution>
   </extension>

Cheers, Phil


回答1:


There are a couple of property tests you can use:

<test
   property="org.eclipse.core.resources.name"
   value="*.pld">
</test>

and

<test
   property="org.eclipse.core.resources.extension"
   value="pld">
</test>

You will need to iterate over the selection so the full visible when would be something like:

<visibleWhen
      checkEnabled="false">
    <iterate
         ifEmpty="false"
         operator="or">
        <test
            property="org.eclipse.core.resources.name"
            value="*.pld">
        </test>
    </iterate>
</visibleWhen>


来源:https://stackoverflow.com/questions/19776876/name-filter-for-eclipse-ui-menus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!