开发者

How can we limit the visibility of a pop-up menu in plugin.xml to only a particular folder and it's sub-folders? Does any such way exist?

开发者 https://www.devze.com 2023-03-27 17:28 出处:网络
I am using menuContribution + command along with the <vi开发者_如何学编程sibleWhen> element in my plugin.xml.

I am using menuContribution + command along with the <vi开发者_如何学编程sibleWhen> element in my plugin.xml.

Say there is a particular folder "XYZ" in my Project Structure with subfolders "xyz1" "xyz2".

I want my popup menu entry to be only visible on right click of XYZ, xyz1 and xyz2 folders only.

Any inputs to do the same will be really helpful.

Thanks, Abbas


You should be able to define your own PropertyTester, or to use a predefined one, like the ResourcePropertyTester, which gets the path of the resource as parameter.


<test   forcePluginActivation="true"
        property="testWizard.propertyTester.checkFolder"
         value="org.eclipse.wst.jsdt.core.jsNature"
 </test>  is the reference to the property tester , which can be defined as

<extension
        point="org.eclipse.core.expressions.propertyTesters">
     <propertyTester          
        class="testwizard.wizards.MyPropTester"
           id="MyPropTesterFolder"
           namespace="testWizard.propertyTester"
           properties="checkFolder"
           type="org.eclipse.core.resources.IFolder">
     </propertyTester>

then the kind of folder and it's subfolders can be tested as below in

package testwizard.wizards;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;

public class MyPropTester extends PropertyTester{

    @Override
    public boolean test(Object receiver, String property, Object[] args,
            Object expectedValue) {

        IFolder folder=(IFolder)receiver;
        String folderPath=folder.getProjectRelativePath().toString();
        String arr[]=folderPath.split("/");     
        try {
            if(folder.getProject().hasNature(expectedValue.toString()))
            {
                if(arr[0].equals("XYZ"))
                {
                    return true;
                }
            }
        } catch (CoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return false;
    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消