mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[file-history] split compare action into two: for files and for folders
This commit is contained in:
@@ -43,6 +43,8 @@
|
||||
<getDataRule key="Vcs.FileHistory.Ui" implementationClass="com.intellij.vcs.log.history.FileHistoryUiDataRule"/>
|
||||
|
||||
<diff.actions.ShowDiffAction.ExtensionProvider implementation="com.intellij.vcs.log.ui.actions.history.CompareRevisionsFromHistoryActionProvider"/>
|
||||
<diff.actions.ShowDiffAction.ExtensionProvider
|
||||
implementation="com.intellij.vcs.log.ui.actions.history.CompareRevisionsFromFileHistoryActionProvider"/>
|
||||
<openapi.vcs.history.actions.ShowDiffAfterWithLocalAction.ExtensionProvider implementation="com.intellij.vcs.log.ui.actions.history.ShowDiffAfterWithLocalFromHistoryActionProvider"/>
|
||||
<openapi.vcs.changes.actions.CreatePatchFromChangesAction.Dialog.ExtensionProvider implementation="com.intellij.vcs.log.ui.actions.history.CreatePatchFromHistoryActionProvider$Dialog"/>
|
||||
<openapi.vcs.changes.actions.CreatePatchFromChangesAction.Clipboard.ExtensionProvider implementation="com.intellij.vcs.log.ui.actions.history.CreatePatchFromHistoryActionProvider$Clipboard"/>
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.vcs.log.ui.actions.history;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.AnActionExtensionProvider;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
import com.intellij.openapi.vcs.VcsDataKeys;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.actions.diff.ShowDiffAction;
|
||||
import com.intellij.vcs.log.VcsLog;
|
||||
import com.intellij.vcs.log.VcsLogDataKeys;
|
||||
import com.intellij.vcs.log.statistics.VcsLogUsageTriggerCollector;
|
||||
import com.intellij.vcs.log.ui.VcsLogInternalDataKeys;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CompareRevisionsFromFileHistoryActionProvider implements AnActionExtensionProvider {
|
||||
@Override
|
||||
public boolean isActive(@NotNull AnActionEvent e) {
|
||||
FilePath filePath = e.getData(VcsDataKeys.FILE_PATH);
|
||||
return e.getData(VcsLogInternalDataKeys.FILE_HISTORY_UI) != null && filePath != null && !filePath.isDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
FilePath filePath = e.getData(VcsDataKeys.FILE_PATH);
|
||||
VcsLog log = e.getData(VcsLogDataKeys.VCS_LOG);
|
||||
if (project == null || filePath == null || filePath.isDirectory() || log == null) {
|
||||
e.getPresentation().setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
|
||||
CompareRevisionsFromHistoryActionProvider.updateActionText(e, log);
|
||||
e.getPresentation().setVisible(true);
|
||||
|
||||
if (e.getInputEvent() instanceof KeyEvent) {
|
||||
e.getPresentation().setEnabled(true);
|
||||
}
|
||||
else {
|
||||
Change[] changes = e.getData(VcsDataKeys.SELECTED_CHANGES);
|
||||
e.getPresentation().setEnabled(changes != null && changes.length == 1 && changes[0] != null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
VcsLogUsageTriggerCollector.triggerUsage(e);
|
||||
|
||||
Project project = e.getRequiredData(CommonDataKeys.PROJECT);
|
||||
Change[] changes = e.getData(VcsDataKeys.SELECTED_CHANGES);
|
||||
if (changes == null || changes.length > 1 || changes[0] == null) return;
|
||||
|
||||
ShowDiffAction.showDiffForChange(project, Arrays.asList(changes));
|
||||
}
|
||||
}
|
||||
+29
-28
@@ -23,18 +23,19 @@ import com.intellij.openapi.ui.MessageType;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
import com.intellij.openapi.vcs.VcsDataKeys;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.actions.diff.ShowDiffAction;
|
||||
import com.intellij.openapi.vcs.history.VcsDiffUtil;
|
||||
import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.vcs.log.*;
|
||||
import com.intellij.vcs.log.CommitId;
|
||||
import com.intellij.vcs.log.VcsFullCommitDetails;
|
||||
import com.intellij.vcs.log.VcsLog;
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.notNull;
|
||||
@@ -47,7 +48,8 @@ public class CompareRevisionsFromHistoryActionProvider implements AnActionExtens
|
||||
|
||||
@Override
|
||||
public boolean isActive(@NotNull AnActionEvent e) {
|
||||
return e.getData(VcsLogInternalDataKeys.FILE_HISTORY_UI) != null;
|
||||
FilePath filePath = e.getData(VcsDataKeys.FILE_PATH);
|
||||
return e.getData(VcsLogInternalDataKeys.FILE_HISTORY_UI) != null && filePath != null && filePath.isDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,29 +61,22 @@ public class CompareRevisionsFromHistoryActionProvider implements AnActionExtens
|
||||
e.getPresentation().setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
|
||||
e.getPresentation().setVisible(true);
|
||||
|
||||
List<CommitId> commits = ui.getVcsLog().getSelectedCommits();
|
||||
VcsLog log = ui.getVcsLog();
|
||||
updateActionText(e, log);
|
||||
|
||||
if (e.getInputEvent() instanceof KeyEvent) {
|
||||
e.getPresentation().setEnabled(true);
|
||||
}
|
||||
else {
|
||||
if (commits.size() == 2) {
|
||||
e.getPresentation().setEnabled(e.getData(VcsLogInternalDataKeys.LOG_DIFF_HANDLER) != null);
|
||||
}
|
||||
else {
|
||||
e.getPresentation().setEnabled(commits.size() == 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
List<CommitId> commits = log.getSelectedCommits();
|
||||
if (commits.size() == 2) {
|
||||
e.getPresentation().setText(COMPARE_TEXT);
|
||||
e.getPresentation().setDescription(COMPARE_DESCRIPTION);
|
||||
e.getPresentation().setEnabled(e.getData(VcsLogInternalDataKeys.LOG_DIFF_HANDLER) != null);
|
||||
}
|
||||
else {
|
||||
e.getPresentation().setText(DIFF_TEXT);
|
||||
e.getPresentation().setDescription(DIFF_DESCRIPTION);
|
||||
e.getPresentation().setEnabled(commits.size() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,18 +103,24 @@ public class CompareRevisionsFromHistoryActionProvider implements AnActionExtens
|
||||
|
||||
if (commits.size() != 1) return;
|
||||
|
||||
if (!filePath.isDirectory()) {
|
||||
ShowDiffAction.showDiffForChange(project, Collections.singletonList(ui.getSelectedChange()));
|
||||
List<Integer> commitIds = ContainerUtil.map(commits, c -> ui.getLogData().getCommitIndex(c.getHash(), c.getRoot()));
|
||||
ui.getLogData().getCommitDetailsGetter().loadCommitsData(commitIds, details -> {
|
||||
VcsFullCommitDetails detail = notNull(ContainerUtil.getFirstItem(details));
|
||||
List<Change> changes = ui.collectRelevantChanges(detail);
|
||||
VcsDiffUtil.showChangesDialog(project, "Changes in " + detail.getId().toShortString() + " for " + filePath.getName(),
|
||||
ContainerUtil.newArrayList(changes));
|
||||
}, t -> VcsBalloonProblemNotifier.showOverChangesView(project, "Could not load selected commits: " + t.getMessage(),
|
||||
MessageType.ERROR), null);
|
||||
}
|
||||
|
||||
public static void updateActionText(@NotNull AnActionEvent e, @NotNull VcsLog log) {
|
||||
if (log.getSelectedCommits().size() >= 2) {
|
||||
e.getPresentation().setText(COMPARE_TEXT);
|
||||
e.getPresentation().setDescription(COMPARE_DESCRIPTION);
|
||||
}
|
||||
else {
|
||||
List<Integer> commitIds = ContainerUtil.map(commits, c -> ui.getLogData().getCommitIndex(c.getHash(), c.getRoot()));
|
||||
ui.getLogData().getCommitDetailsGetter().loadCommitsData(commitIds, details -> {
|
||||
VcsFullCommitDetails detail = notNull(ContainerUtil.getFirstItem(details));
|
||||
List<Change> changes = ui.collectRelevantChanges(detail);
|
||||
VcsDiffUtil.showChangesDialog(project, "Changes in " + detail.getId().toShortString() + " for " + filePath.getName(),
|
||||
ContainerUtil.newArrayList(changes));
|
||||
}, t -> VcsBalloonProblemNotifier.showOverChangesView(project, "Could not load selected commits: " + t.getMessage(),
|
||||
MessageType.ERROR), null);
|
||||
e.getPresentation().setText(DIFF_TEXT);
|
||||
e.getPresentation().setDescription(DIFF_DESCRIPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user