visibleWhen for command to appear in context menu

前端 未结 3 1767
攒了一身酷
攒了一身酷 2021-02-15 18:09

I am trying configure visibility of a command within the context menu using \'visibleWhen\' expression within a menuContribution. What I am trying to do is make the command vis

相关标签:
3条回答
  • @blissfool, I would suggest a slight restructuring. You can put your basic test (which is correct) in a org.eclipse.core.expressions.definitions block:

    <extension point="org.eclipse.core.expressions.definitions">
       <definition id="org.eclipse.example.testExtension">
          <adapt type="org.eclipse.core.resources.IResource">
             <or>
                 <test property="org.eclipse.core.resources.extension"
                       value="ext1">
                 </test>
                 <test property="org.eclipse.core.resources.extension"
                       value="ext2">
                 </test>
             </or>
          </adapt>
       </definition>
    </extension>
    

    Then in your visibleWhen move the activeEditorInput test up to the top:

    <visibleWhen>
       <or>
          <with variable="selection">
             <iterate ifEmtpy="false">
               <reference definitionId="org.eclipse.example.testExtension"/>
             </iterate>
          </with>
          <with variable="activeEditorInput">
            <reference definitionId="org.eclipse.example.testExtension"/>
          </with>
       </or>
    </visibleWhen>
    
    0 讨论(0)
  • 2021-02-15 18:35

    You could implement your own PropertyTester.

    0 讨论(0)
  • 2021-02-15 18:37

    I was able to get it done with a with variable that I came across. Using the same code example above:

    • Add an <or> block within the <iterate> block
    • Place the existing <adapt> block in the new <or> block
    • Add a new with variable called activeEditorInput

    Here is the new code example.

    <iterate ifEmpty="false" operator="or">
      <or>
        <adapt type="org.eclipse.core.resources.IResource">
          <or>
            ...test extensions
          </or>
        </adapt>
        <with variable="activeEditorInput">
          <adapt type="org.eclipse.core.resources.IResource">
            <or>
              ...test extensions
            </or>
          </adapt>
        </with>
      </or>
    </iterate>
    
    0 讨论(0)
提交回复
热议问题