mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs-log] add compare with local to log
This commit is contained in:
@@ -129,6 +129,7 @@
|
||||
<reference id="Vcs.CopyRevisionNumberAction"/>
|
||||
<reference id="ChangesView.CreatePatchFromChanges"/>
|
||||
<reference id="Vcs.Log.CompareRevisions"/>
|
||||
<reference id="Vcs.ShowDiffWithLocal"/>
|
||||
</group>
|
||||
<group id="Vcs.Log.ChangesBrowser.Toolbar">
|
||||
<reference id="Vcs.RepositoryChangesBrowserToolbar"/>
|
||||
|
||||
+28
-9
@@ -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<CommitId> 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<CommitId> commits = ui.getVcsLog().getSelectedCommits();
|
||||
List<CommitId> 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<CommitId> commits = ui.getVcsLog().getSelectedCommits();
|
||||
List<CommitId> 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user