简体   繁体   English

插件,编译单元

[英]Plugin, compilation unit

I'm making some plugin, for popup menu to appear only if .java file that contains class is selected. 我正在制作一些插件,仅当选择了包含类的.java文件时,弹出菜单才会出现。 My problem is, when I select .java file menu appears, but also when I select class within .java file (IType), menu also appears. 我的问题是,当我选择.java文件菜单时,而且当我在.java文件(IType)中选择类时,菜单也会出现。 I want it only to appear when .java file is selected (Compilation unit) 我只希望在选择.java文件时出现(编译单元)

Example: 例: 例 .

My xml code: ` 我的xml代码:

<menuContribution
        allPopups="true"
   locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions"
        >
     <menu
           id="org.plugin.generate_test.handlers.menus.popupTestMenu2"
           label="Generate"
           mnemonic="P2">
        <command
              commandId="org.plugin.generate_test.handlers.commands.generateCommand"
              id="org.plugin.generate_test.handlers.menus.generateCommand"
              mnemonic="PC2"
              style="push">
           <visibleWhen
                 checkEnabled="false">
              <with
                    variable="activeMenuSelection">
                 <iterate
                       ifEmpty="false">
                    <adapt
                          type="org.eclipse.core.resources.IResource">
                       <test
                             property="org.eclipse.core.resources.extension"
                             value="java">
                       </test>
                    </adapt>
                 </iterate>
              </with>
           </visibleWhen>
        </command>
     </menu>
  </menuContribution>`

尝试用ICompilationUnit的测试替换<adapt

<instanceof value="org.eclipse.jdt.core.ICompilationUnit"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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