Search in sources :

Example 1 with ShowDiffContext

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);
                }
            }
        });
    }
}
Also used : Task(com.intellij.openapi.progress.Task) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) ShowDiffContext(com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext) Change(com.intellij.openapi.vcs.changes.Change) LinkedList(java.util.LinkedList) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) Pair(com.intellij.openapi.util.Pair)

Example 2 with ShowDiffContext

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);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) Project(com.intellij.openapi.project.Project) MouseEvent(java.awt.event.MouseEvent) CommitId(com.intellij.vcs.log.CommitId) ShowDiffContext(com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext) List(java.util.List) FileHistoryUi(com.intellij.vcs.log.history.FileHistoryUi) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) VcsFullCommitDetails(com.intellij.vcs.log.VcsFullCommitDetails)

Example 3 with ShowDiffContext

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);
        }
    }
}
Also used : MessageDiffRequest(com.intellij.diff.requests.MessageDiffRequest) HashMap(com.intellij.util.containers.hash.HashMap) ShowDiffContext(com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext) Change(com.intellij.openapi.vcs.changes.Change) NotNull(org.jetbrains.annotations.NotNull) Key(com.intellij.openapi.util.Key) CalledInAwt(org.jetbrains.annotations.CalledInAwt)

Example 4 with 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);
}
Also used : ShowDiffContext(com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext)

Aggregations

ShowDiffContext (com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext)4 Change (com.intellij.openapi.vcs.changes.Change)2 MessageDiffRequest (com.intellij.diff.requests.MessageDiffRequest)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 Key (com.intellij.openapi.util.Key)1 Pair (com.intellij.openapi.util.Pair)1 FilePath (com.intellij.openapi.vcs.FilePath)1 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)1 VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)1 CommittedChangeList (com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)1 HashMap (com.intellij.util.containers.hash.HashMap)1 CommitId (com.intellij.vcs.log.CommitId)1 VcsFullCommitDetails (com.intellij.vcs.log.VcsFullCommitDetails)1 FileHistoryUi (com.intellij.vcs.log.history.FileHistoryUi)1 MouseEvent (java.awt.event.MouseEvent)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 CalledInAwt (org.jetbrains.annotations.CalledInAwt)1