diff --git a/platform/vcs-log/impl/src/META-INF/vcs-log.xml b/platform/vcs-log/impl/src/META-INF/vcs-log.xml index 405f98da17c1..b4d9c323de5d 100644 --- a/platform/vcs-log/impl/src/META-INF/vcs-log.xml +++ b/platform/vcs-log/impl/src/META-INF/vcs-log.xml @@ -129,6 +129,7 @@ + diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/ShowDiffAfterWithLocalFromHistoryActionProvider.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/ShowDiffAfterWithLocalFromHistoryActionProvider.java index c5d5f8bdd816..595310e9afae 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/ShowDiffAfterWithLocalFromHistoryActionProvider.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/ShowDiffAfterWithLocalFromHistoryActionProvider.java @@ -23,11 +23,15 @@ import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.VcsDataKeys; import com.intellij.openapi.vcs.changes.ChangeListManager; import com.intellij.vcs.log.CommitId; +import com.intellij.vcs.log.VcsLog; +import com.intellij.vcs.log.VcsLogDataKeys; import com.intellij.vcs.log.VcsLogDiffHandler; import com.intellij.vcs.log.history.FileHistoryUi; import com.intellij.vcs.log.statistics.VcsLogUsageTriggerCollector; import com.intellij.vcs.log.ui.VcsLogInternalDataKeys; +import com.intellij.vcsUtil.VcsUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -35,29 +39,38 @@ import static com.intellij.util.ObjectUtils.notNull; import static com.intellij.util.containers.ContainerUtil.getFirstItem; public class ShowDiffAfterWithLocalFromHistoryActionProvider implements AnActionExtensionProvider { + @Nullable + private static FilePath getFilePath(@NotNull AnActionEvent e, @NotNull VcsLog log) { + FilePath filePath = e.getData(VcsDataKeys.FILE_PATH); + if (filePath != null) return filePath; + List commits = log.getSelectedCommits(); + if (commits.isEmpty() || commits.size() > 1) return null; + return VcsUtil.getFilePath(notNull(getFirstItem(commits)).getRoot()); + } + @Override public boolean isActive(@NotNull AnActionEvent e) { - return e.getData(VcsLogInternalDataKeys.FILE_HISTORY_UI) != null; + return e.getData(VcsLogDataKeys.VCS_LOG) != null; } @Override public void update(@NotNull AnActionEvent e) { Project project = e.getProject(); - FileHistoryUi ui = e.getData(VcsLogInternalDataKeys.FILE_HISTORY_UI); - if (project == null || ui == null) { + VcsLog log = e.getData(VcsLogDataKeys.VCS_LOG); + if (project == null || log == null) { e.getPresentation().setEnabledAndVisible(false); return; } e.getPresentation().setVisible(true); - List commits = ui.getVcsLog().getSelectedCommits(); + List commits = log.getSelectedCommits(); if (commits.size() != 1) { e.getPresentation().setEnabled(false); return; } - FilePath filePath = e.getData(VcsDataKeys.FILE_PATH); + FilePath filePath = getFilePath(e, log); VcsLogDiffHandler handler = e.getData(VcsLogInternalDataKeys.LOG_DIFF_HANDLER); e.getPresentation().setEnabled(filePath != null && filePath.getVirtualFile() != null && handler != null); @@ -68,17 +81,23 @@ public class ShowDiffAfterWithLocalFromHistoryActionProvider implements AnAction VcsLogUsageTriggerCollector.triggerUsage(e); Project project = e.getRequiredData(CommonDataKeys.PROJECT); - FileHistoryUi ui = e.getRequiredData(VcsLogInternalDataKeys.FILE_HISTORY_UI); + VcsLog log = e.getRequiredData(VcsLogDataKeys.VCS_LOG); - List commits = ui.getVcsLog().getSelectedCommits(); + List commits = log.getSelectedCommits(); if (commits.size() != 1) return; CommitId commit = notNull(getFirstItem(commits)); if (ChangeListManager.getInstance(project).isFreezedWithNotification(null)) return; - FilePath path = e.getRequiredData(VcsDataKeys.FILE_PATH); + FilePath path = getFilePath(e, log); VcsLogDiffHandler handler = e.getRequiredData(VcsLogInternalDataKeys.LOG_DIFF_HANDLER); - handler.showDiffWithLocal(commit.getRoot(), ui.getPathInCommit(commit.getHash()), commit.getHash(), path); + FilePath pathInCommit = path; + FileHistoryUi historyUi = e.getData(VcsLogInternalDataKeys.FILE_HISTORY_UI); + if (historyUi != null) { + pathInCommit = historyUi.getPathInCommit(commit.getHash()); + } + + handler.showDiffWithLocal(commit.getRoot(), pathInCommit, commit.getHash(), path); } }