activate/deactivate plugin option for particular file type.

I am developing a plugin, which has number of actions.

I want to disable few actions by default  and it would get activated only for particular file type.

For e.g.; When I right click on .java file, it should be deactivated or disabled. And when I right click on .xml file, that particular plugin action should be activated or enabled.

Please provide sample or useful references.


Comment actions Permalink

In the update() method of your action, get the virtual file from context using e.getData(PlatformDataKeys.VIRTUAL_FILE) and call getPresentation().setEnabled(false) if the type of the file does not match the one that you need.

Comment actions Permalink

As I pasted on

public class YourAction extends DumbAwareAction {
    public void update(AnActionEvent e) {

    private void determineVisibility(AnActionEvent e) {
        DataContext dataContext = e.getDataContext();
        VirtualFile virtualFile = PlatformDataKeys.VIRTUAL_FILE.getData(dataContext);

    private boolean isXml(VirtualFile file) {
        if (file == null) {
            return false;
        return XmlFileType.INSTANCE.equals(file.getFileType());

Please sign in to leave a comment.