2013-10-14 32 views
2

我正在寫Eclispe(Kepler)插件。這個插件的主要目標是在PackageExplorer彈出式菜單中添加「Open In Explorer」項目。對於目錄,軟件包等,這個項目應該是可見的,但是對於文件不可見我試過這個:如何在PackageExplorer中僅爲目錄創建彈出菜單項

<menuContribution 
    locationURI="popup:org.eclipse.jdt.ui.PackageExplorer"> 
    <command 
      commandId="pl.com.tt.wide.lms.core.commands.sampleCommand" 
      id="pl.com.tt.wide.lms.core.menus.sampleCommand" 
      mnemonic="S"> 
     <visibleWhen> 
       <with variable="activeMenuSelection"> 
       <iterate 
        ifEmpty="false"> 
        <adapt type="org.eclipse.core.resources.IResource"> 
         <test property="org.eclipse.core.resources.type" value="org.eclipse.core.resources.FOLDER"/> 
        </adapt> 
       </iterate> 
       </with> 
     </visibleWhen> 
    </command> 
</menuContribution> 

這是行不通的。你有什麼建議如何做到這一點? 感謝您的幫助。

+0

嗨,我有同樣的問題現在。我嘗試過使用'adapt type =「org.eclipse.core.resources.IContainer'和'IFolder',但迄今爲止我的搜索沒有找到任何解決方案。您是否找到了解決方案? – TheMorph

回答

0

我認爲,首先想到的不是隱藏菜單的元素,而是禁用它們。這至少給用戶提示,即將有命令可用,但不僅僅是現在。所以我會使用「enableWhen」而不是「visibleWhen」。 否則,您會根據選擇奇怪地更改菜單和項目順序,這可能會增加混淆。特別是在Eclipse中,你被困惑所包圍。 :-)

也許看看這對已經存在的插件:http://marketplace.eclipse.org/content/easyshell#.Ul6fNfnIZsg

0

Package Explorer中不僅使用類型的org.eclipse.core.resources但使用的各類org.ecliplse.jdt.core了。

看一看IPackageFragment,IPackageFragmentRootIJavaProject。在or聲明中使用這些可能會產生,你想要什麼。

這是對我工作:

<visibleWhen> 
    <with variable="activeMenuSelection"> 
     <iterate ifEmpty="false"> 
     <or> 
      <adapt type="org.eclipse.jdt.core.IJavaProject"> 
      </adapt> 
      <adapt type="org.eclipse.jdt.core.IPackageFragmentRoot"> 
      </adapt> 
      <adapt type="org.eclipse.jdt.core.IPackageFragment"> 
      </adapt> 
     </or> 
     </iterate> 
    </with> 
</visibleWhen> 
相關問題