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.
Thanks
Please sign in to leave a comment.
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.
As I pasted on http://stackoverflow.com/a/30303919/685796
public class YourAction extends DumbAwareAction { ... @Override public void update(AnActionEvent e) { super.update(e); determineVisibility(e); } private void determineVisibility(AnActionEvent e) { DataContext dataContext = e.getDataContext(); VirtualFile virtualFile = PlatformDataKeys.VIRTUAL_FILE.getData(dataContext); e.getPresentation().setVisible(isXml(virtualFile)); } private boolean isXml(VirtualFile file) { if (file == null) { return false; } return XmlFileType.INSTANCE.equals(file.getFileType()); } }