vcs: hide "Compare with Specified Revision" action when it is not supported

GitOrigin-RevId: d811fb6349db28136887a45e13480858b9fcc856
This commit is contained in:
Aleksey Pivovarov
2020-05-15 11:44:49 +00:00
committed by intellij-monorepo-bot
parent ae7ee6c20d
commit 6949455db1
@@ -19,42 +19,64 @@ import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.changes.ChangesUtil;
import com.intellij.openapi.vcs.diff.DiffProvider;
import com.intellij.openapi.vcs.diff.RevisionSelector;
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author lesya
*/
public class SelectAndCompareWithSelectedRevisionAction extends AbstractVcsAction{
public class SelectAndCompareWithSelectedRevisionAction extends AbstractVcsAction {
@Override
protected void actionPerformed(@NotNull VcsContext vcsContext) {
final VirtualFile file = vcsContext.getSelectedFiles()[0];
final Project project = vcsContext.getProject();
final VirtualFile file = vcsContext.getSelectedFile();
if (project == null || file == null) return;
final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(file);
if (vcs == null) {
return;
}
if (vcs == null) return;
RevisionSelector selector = vcs.getRevisionSelector();
final DiffProvider diffProvider = vcs.getDiffProvider();
DiffProvider diffProvider = vcs.getDiffProvider();
if (selector == null || diffProvider == null) return;
if (selector != null) {
final VcsRevisionNumber vcsRevisionNumber = selector.selectNumber(file);
if (vcsRevisionNumber != null) {
DiffActionExecutor.showDiff(diffProvider, vcsRevisionNumber, file, project);
}
VcsRevisionNumber vcsRevisionNumber = selector.selectNumber(file);
if (vcsRevisionNumber != null) {
DiffActionExecutor.showDiff(diffProvider, vcsRevisionNumber, file, project);
}
}
@Override
protected void update(@NotNull VcsContext vcsContext, @NotNull Presentation presentation) {
AbstractShowDiffAction.updateDiffAction(presentation, vcsContext);
boolean isVisible = isVisible(vcsContext);
presentation.setEnabled(isVisible && isEnabled(vcsContext));
presentation.setVisible(isVisible);
}
private static boolean isVisible(@NotNull VcsContext vcsContext) {
Project project = vcsContext.getProject();
if (project == null) return false;
AbstractVcs[] vcss = ProjectLevelVcsManager.getInstance(project).getAllActiveVcss();
return ContainerUtil.exists(vcss, SelectAndCompareWithSelectedRevisionAction::canShowDiffForVcs);
}
private static boolean isEnabled(@NotNull VcsContext vcsContext) {
Project project = vcsContext.getProject();
VirtualFile file = vcsContext.getSelectedFile();
if (project == null || file == null || file.isDirectory()) return false;
AbstractVcs vcs = ChangesUtil.getVcsForFile(file, project);
if (!canShowDiffForVcs(vcs)) return false;
if (!AbstractVcs.fileInVcsByFileStatus(project, file)) return false;
return true;
}
private static boolean canShowDiffForVcs(@Nullable AbstractVcs vcs) {
return vcs != null && vcs.getDiffProvider() != null && vcs.getRevisionSelector() != null;
}
}