use of com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext in project intellij-community by JetBrains.
the class ShowDiffFromAnnotation method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final int actualNumber = currentLine;
if (actualNumber < 0)
return;
final VcsRevisionNumber revisionNumber = myFileAnnotation.getLineRevisionNumber(actualNumber);
if (revisionNumber != null) {
final VcsException[] exc = new VcsException[1];
final List<Change> changes = new LinkedList<>();
final FilePath[] targetPath = new FilePath[1];
ProgressManager.getInstance().run(new Task.Backgroundable(myVcs.getProject(), "Loading revision " + revisionNumber.asString() + " contents", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
final CommittedChangesProvider provider = myVcs.getCommittedChangesProvider();
try {
final Pair<CommittedChangeList, FilePath> pair = provider.getOneList(myFile, revisionNumber);
if (pair == null || pair.getFirst() == null) {
VcsBalloonProblemNotifier.showOverChangesView(myVcs.getProject(), "Can not load data for show diff", MessageType.ERROR);
return;
}
targetPath[0] = pair.getSecond() == null ? VcsUtil.getFilePath(myFile) : pair.getSecond();
final CommittedChangeList cl = pair.getFirst();
changes.addAll(cl.getChanges());
Collections.sort(changes, ChangesComparator.getInstance(true));
} catch (VcsException e1) {
exc[0] = e1;
}
}
@Override
public void onSuccess() {
if (exc[0] != null) {
VcsBalloonProblemNotifier.showOverChangesView(myVcs.getProject(), "Can not show diff: " + exc[0].getMessage(), MessageType.ERROR);
} else if (!changes.isEmpty()) {
int idx = findSelfInList(changes, targetPath[0]);
final ShowDiffContext context = new ShowDiffContext(DiffDialogHints.FRAME);
if (idx != -1) {
context.putChangeContext(changes.get(idx), DiffUserDataKeysEx.NAVIGATION_CONTEXT, createDiffNavigationContext(actualNumber));
}
if (ChangeListManager.getInstance(myVcs.getProject()).isFreezedWithNotification(null))
return;
ShowDiffAction.showDiffForChange(myVcs.getProject(), changes, idx, context);
}
}
});
}
}
use of com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext in project intellij-community by JetBrains.
the class CompareRevisionsFromHistoryAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getRequiredData(CommonDataKeys.PROJECT);
FileHistoryUi ui = e.getRequiredData(VcsLogInternalDataKeys.FILE_HISTORY_UI);
FilePath filePath = e.getRequiredData(VcsDataKeys.FILE_PATH);
if (e.getInputEvent() instanceof MouseEvent && ui.getTable().isResizingColumns()) {
// disable action during columns resize
return;
}
VcsLogUtil.triggerUsage(e);
List<CommitId> commits = ui.getVcsLog().getSelectedCommits();
if (commits.size() != 1 && commits.size() != 2)
return;
List<Integer> commitIds = ContainerUtil.map(commits, c -> ui.getLogData().getCommitIndex(c.getHash(), c.getRoot()));
ui.getLogData().getCommitDetailsGetter().loadCommitsData(commitIds, details -> {
if (details.size() == 2) {
VcsFileRevision newestRevision = ui.createRevision(details.get(0));
VcsFileRevision olderRevision = ui.createRevision(details.get(1));
if (olderRevision != null && newestRevision != null) {
myDiffHandler.showDiffForTwo(project, filePath, olderRevision, newestRevision);
}
} else if (details.size() == 1) {
VcsFullCommitDetails detail = ObjectUtils.notNull(ContainerUtil.getFirstItem(details));
List<Change> changes = ui.collectRelevantChanges(detail);
if (filePath.isDirectory()) {
VcsDiffUtil.showChangesDialog(project, "Changes in " + detail.getId().toShortString() + " for " + filePath.getName(), ContainerUtil.newArrayList(changes));
} else {
ShowDiffAction.showDiffForChange(project, changes, 0, new ShowDiffContext());
}
}
}, null);
}
use of com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext in project intellij-community by JetBrains.
the class VcsDiffUtil method showDiffFor.
@CalledInAwt
public static void showDiffFor(@NotNull Project project, @NotNull final Collection<Change> changes, @NotNull final String revNumTitle1, @NotNull final String revNumTitle2, @NotNull final FilePath filePath) {
if (filePath.isDirectory()) {
showChangesDialog(project, getDialogTitle(filePath, revNumTitle1, revNumTitle2), ContainerUtil.newArrayList(changes));
} else {
if (changes.isEmpty()) {
DiffManager.getInstance().showDiff(project, new MessageDiffRequest("No Changes Found"));
} else {
final HashMap<Key, Object> revTitlesMap = new HashMap<>(2);
revTitlesMap.put(VCS_DIFF_LEFT_CONTENT_TITLE, revNumTitle1);
revTitlesMap.put(VCS_DIFF_RIGHT_CONTENT_TITLE, revNumTitle2);
ShowDiffContext showDiffContext = new ShowDiffContext() {
@NotNull
@Override
public Map<Key, Object> getChangeContext(@NotNull Change change) {
return revTitlesMap;
}
};
ShowDiffAction.showDiffForChange(project, changes, 0, showDiffContext);
}
}
}
use of com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext in project intellij-community by JetBrains.
the class ChangesBrowserBase method showDiffForChanges.
protected void showDiffForChanges(Change[] changesArray, final int indexInSelection) {
final ShowDiffContext context = new ShowDiffContext(isInFrame() ? DiffDialogHints.FRAME : DiffDialogHints.MODAL);
context.addActions(createDiffActions());
if (myDiffBottomComponent != null) {
context.putChainContext(DiffUserDataKeysEx.BOTTOM_PANEL, myDiffBottomComponent);
}
updateDiffContext(context);
ShowDiffAction.showDiffForChange(myProject, Arrays.asList(changesArray), indexInSelection, context);
}
Aggregations