java - org.eclipse.ui.menus 的名称过滤器 - 也适用于编辑器 View

标签 java eclipse plugins menu contextmenu

我有一个由此扩展点定义的菜单:org.eclipse.ui.menus。 它的位置 URI 是 popup:org.eclipse.ui.popup.any,这意味着它也会从不同的资源管理器 View 和编辑器 View 中显示(右键单击代码上的某处)。

我希望此菜单仅在某些扩展中显示。我使用了 here 中格雷格的答案它非常适合浏览器 View 。 如何为编辑器 View 执行相同的过滤器?

我想以某种方式更改它,如果有人从编辑器 View (和资源管理器 View )右键单击某个文件,则仅当该文件是“*.myextension”文件时才会显示该文件。

谢谢。

尝试组合过滤器 - 根据 greg 的回答,这是我的代码,但无法按预期工作。

        <visibleWhen
              checkEnabled="false">
            <iterate
                 ifEmpty="false"
                 operator="or">
                <or>
                <test
                    property="org.eclipse.core.resources.name"
                    value="*.myextension">
                </test>
                </or>
                <or>
                  <with variable="activeEditorInput">
                     <adapt type="org.eclipse.core.resources.IResource">
                        <test
                            property="org.eclipse.core.resources.name"
                            value="*.myextension">
                        </test>
                     </adapt>
                  </with>   
               </or>                
            </iterate>
        </visibleWhen>

最佳答案

对于编辑器,您可以使用以下方法测试“Activity 编辑器输入”:

<visibleWhen
  checkEnabled="false">
  <with variable="activeEditorInput">
     <adapt type="org.eclipse.core.resources.IResource">
        <test
            property="org.eclipse.core.resources.name"
            value="*.myextension">
        </test>
     </adapt>
  </with>
</visibleWhen>

这将获取 Activity 编辑器输入,获取正在编辑的 IResource 并对其进行测试。

组合可能会给出:

<visibleWhen
   checkEnabled="false">
   <or>
     <with variable="activeEditorInput">
       <adapt type="org.eclipse.core.resources.IResource">
          <test
              property="org.eclipse.core.resources.name"
              value="*.myextension">
          </test>
       </adapt>
     </with>
     <iterate
           ifEmpty="false"
           operator="or">
        <test
            property="org.eclipse.core.resources.name"
            value="*.myextension">
        </test>
     </iterate>
   </or>
 </visibleWhen>

关于java - org.eclipse.ui.menus 的名称过滤器 - 也适用于编辑器 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41240806/

相关文章:

php - WordPress - 插件页面上的更新通知

java - libGDX actor 在运动时不会表现得正确

Java:在多个线程上等待/通知

java - 将 Android-DirectoryChooser 导入 Eclipse

java - 如何使用 setUrl() 从附加到 GWT 框架的 HTML 文件中检索元素?

php - 创建或转换 TinyMCE 下拉工具栏菜单

java - 如何在不映射根 xml 元素的情况下解码 xml?

java - 通过 Spring Boot application.yml 配置 Hazelcast

Java 控制台无法正确读取中文字符

java - 列出java编译器在编译过程中需要的所有类