[file-history] use VcsLogDiffHandler for diff with local in file history

This fixes directory diff IDEA-171150.
This commit is contained in:
Julia Beliaeva
2017-04-14 14:31:35 +03:00
parent 15b98239ea
commit 1e2e154c7b
@@ -20,30 +20,29 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.VcsDataKeys;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.history.CurrentRevision;
import com.intellij.openapi.vcs.history.StandardDiffFromHistoryHandler;
import com.intellij.openapi.vcs.history.VcsFileRevision;
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcs.log.CommitId;
import com.intellij.vcs.log.VcsFullCommitDetails;
import com.intellij.vcs.log.VcsLogDiffHandler;
import com.intellij.vcs.log.history.FileHistoryUi;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static com.intellij.util.ObjectUtils.notNull;
import java.util.List;
public class ShowDiffWithLocalFromHistoryAction extends FileHistorySingleCommitAction {
@Override
protected boolean isEnabled(@NotNull FileHistoryUi ui, @Nullable VcsFullCommitDetails detail, @NotNull AnActionEvent e) {
FilePath filePath = e.getData(VcsDataKeys.FILE_PATH);
if (filePath == null || filePath.isDirectory() || filePath.getVirtualFile() == null) {
// currently not working for directories, to be fixed later
if (filePath == null || filePath.getVirtualFile() == null) {
return false;
}
if (detail != null) {
VcsFileRevision fileRevision = ui.createRevision(detail);
if (fileRevision == null) return false;
List<CommitId> commits = ui.getVcsLog().getSelectedCommits();
if (filePath.isDirectory()) {
VcsLogDiffHandler handler = ui.getLogData().getLogProvider(commits.get(0).getRoot()).getDiffHandler();
if (handler == null) return false;
}
return true;
@@ -57,11 +56,11 @@ public class ShowDiffWithLocalFromHistoryAction extends FileHistorySingleCommitA
if (ChangeListManager.getInstance(project).isFreezedWithNotification(null)) return;
FilePath path = e.getRequiredData(VcsDataKeys.FILE_PATH);
VcsFileRevision revision = ui.createRevision(detail);
if (revision != null) {
StandardDiffFromHistoryHandler handler = new StandardDiffFromHistoryHandler();
handler.showDiffForTwo(project, path, revision, new CurrentRevision(notNull(path.getVirtualFile()), VcsRevisionNumber.NULL));
VirtualFile root = detail.getRoot();
VcsLogDiffHandler handler = ui.getLogData().getLogProvider(root).getDiffHandler();
if (handler != null) {
handler.showDiffWithLocal(root, ui.getPath(detail), detail.getId(), path);
}
}
}