Search in sources :

Example 11 with SimpleDiffRequest

use of com.intellij.diff.requests.SimpleDiffRequest in project intellij-plugins by JetBrains.

the class DiffWindowOpener method showDiff.

public void showDiff() {
    String title = "Diff for " + myVFile.getDisplayName();
    String title1 = "My Version";
    String title2 = myRemoteUser.getDisplayName() + "'s Version";
    DiffContent content1 = DiffContentFactory.getInstance().create(myProject, myVirtualFile);
    DiffContent content2 = DiffContentFactory.getInstance().create(myRemoteText, myVirtualFile.getFileType());
    DiffRequest request = new SimpleDiffRequest(title, content1, content2, title1, title2);
    DiffManagerEx.getInstance().showDiff(myProject, request, DiffDialogHints.NON_MODAL);
}
Also used : SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) DiffRequest(com.intellij.diff.requests.DiffRequest) DiffContent(com.intellij.diff.contents.DiffContent)

Example 12 with SimpleDiffRequest

use of com.intellij.diff.requests.SimpleDiffRequest in project intellij-community by JetBrains.

the class CompareClipboardWithSelectionAction method getDiffRequest.

@Nullable
@Override
protected DiffRequest getDiffRequest(@NotNull AnActionEvent e) {
    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    Editor editor = getEditor(e);
    FileType editorFileType = getEditorFileType(e);
    assert editor != null;
    DocumentContent content2 = createContent(project, editor, editorFileType);
    DocumentContent content1 = DiffContentFactory.getInstance().createClipboardContent(project, content2);
    String title1 = DiffBundle.message("diff.content.clipboard.content.title");
    String title2 = createContentTitle(editor);
    String title = DiffBundle.message("diff.clipboard.vs.editor.dialog.title");
    SimpleDiffRequest request = new SimpleDiffRequest(title, content1, content2, title1, title2);
    if (editor.isViewer()) {
        request.putUserData(DiffUserDataKeys.FORCE_READ_ONLY_CONTENTS, new boolean[] { false, true });
    }
    return request;
}
Also used : Project(com.intellij.openapi.project.Project) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) FileType(com.intellij.openapi.fileTypes.FileType) UnknownFileType(com.intellij.openapi.fileTypes.UnknownFileType) DocumentContent(com.intellij.diff.contents.DocumentContent) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with SimpleDiffRequest

use of com.intellij.diff.requests.SimpleDiffRequest in project intellij-community by JetBrains.

the class PatchDiffRequestFactory method createDiffRequest.

@NotNull
public static DiffRequest createDiffRequest(@Nullable Project project, @Nullable VirtualFile file, @NotNull List<String> contents, @Nullable String windowTitle, @NotNull List<String> titles) {
    assert contents.size() == 3;
    assert titles.size() == 3;
    if (windowTitle == null)
        windowTitle = getPatchTitle(file);
    String localTitle = StringUtil.notNullize(titles.get(0), VcsBundle.message("patch.apply.conflict.local.version"));
    String baseTitle = StringUtil.notNullize(titles.get(1), "Base Version");
    String patchedTitle = StringUtil.notNullize(titles.get(2), VcsBundle.message("patch.apply.conflict.patched.version"));
    FileType fileType = file != null ? file.getFileType() : null;
    DiffContentFactory contentFactory = DiffContentFactory.getInstance();
    DocumentContent localContent = file != null ? contentFactory.createDocument(project, file) : null;
    if (localContent == null)
        localContent = contentFactory.create(project, contents.get(0), fileType);
    DocumentContent baseContent = contentFactory.create(project, contents.get(1), fileType);
    DocumentContent patchedContent = contentFactory.create(project, contents.get(2), fileType);
    return new SimpleDiffRequest(windowTitle, localContent, baseContent, patchedContent, localTitle, baseTitle, patchedTitle);
}
Also used : SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) DiffContentFactory(com.intellij.diff.DiffContentFactory) FileType(com.intellij.openapi.fileTypes.FileType) DocumentContent(com.intellij.diff.contents.DocumentContent) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with SimpleDiffRequest

use of com.intellij.diff.requests.SimpleDiffRequest in project intellij-community by JetBrains.

the class DiffActionExecutor method showDiff.

public void showDiff() {
    final Ref<VcsException> exceptionRef = new Ref<>();
    final Ref<DiffRequest> requestRef = new Ref<>();
    final Task.Backgroundable task = new Task.Backgroundable(myProject, VcsBundle.message("show.diff.progress.title.detailed", mySelectedFile.getPresentableUrl()), true) {

        public void run(@NotNull ProgressIndicator indicator) {
            final VcsRevisionNumber revisionNumber = getRevisionNumber();
            try {
                if (revisionNumber == null) {
                    return;
                }
                DiffContent content1 = createRemote(revisionNumber);
                if (content1 == null)
                    return;
                DiffContent content2 = DiffContentFactory.getInstance().create(myProject, mySelectedFile);
                String title = DiffRequestFactory.getInstance().getTitle(mySelectedFile);
                boolean inverted = false;
                String title1;
                String title2;
                final FileStatus status = FileStatusManager.getInstance(myProject).getStatus(mySelectedFile);
                if (status == null || FileStatus.NOT_CHANGED.equals(status) || FileStatus.UNKNOWN.equals(status) || FileStatus.IGNORED.equals(status)) {
                    final VcsRevisionNumber currentRevision = myDiffProvider.getCurrentRevision(mySelectedFile);
                    inverted = revisionNumber.compareTo(currentRevision) > 0;
                    title1 = revisionNumber.asString();
                    title2 = VcsBundle.message("diff.title.local.with.number", currentRevision.asString());
                } else {
                    title1 = revisionNumber.asString();
                    title2 = VcsBundle.message("diff.title.local");
                }
                Integer line = null;
                if (content2 instanceof DocumentContent) {
                    Editor[] editors = EditorFactory.getInstance().getEditors(((DocumentContent) content2).getDocument(), myProject);
                    if (editors.length != 0)
                        line = editors[0].getCaretModel().getLogicalPosition().line;
                }
                if (inverted) {
                    SimpleDiffRequest request = new SimpleDiffRequest(title, content2, content1, title2, title1);
                    if (line != null)
                        request.putUserData(DiffUserDataKeys.SCROLL_TO_LINE, Pair.create(Side.LEFT, line));
                    request.putUserData(DiffUserDataKeys.MASTER_SIDE, Side.LEFT);
                    requestRef.set(request);
                } else {
                    SimpleDiffRequest request = new SimpleDiffRequest(title, content1, content2, title1, title2);
                    if (line != null)
                        request.putUserData(DiffUserDataKeys.SCROLL_TO_LINE, Pair.create(Side.RIGHT, line));
                    request.putUserData(DiffUserDataKeys.MASTER_SIDE, Side.RIGHT);
                    requestRef.set(request);
                }
            } catch (ProcessCanceledException e) {
            //ignore
            } catch (VcsException e) {
                exceptionRef.set(e);
            } catch (IOException e) {
                exceptionRef.set(new VcsException(e));
            }
        }

        @Override
        public void onCancel() {
            onSuccess();
        }

        @Override
        public void onSuccess() {
            myHandler.completed(VcsBackgroundableActions.keyFrom(mySelectedFile));
            if (!exceptionRef.isNull()) {
                AbstractVcsHelper.getInstance(myProject).showError(exceptionRef.get(), VcsBundle.message("message.title.diff"));
                return;
            }
            if (!requestRef.isNull()) {
                DiffManager.getInstance().showDiff(myProject, requestRef.get());
            }
        }
    };
    myHandler.register(VcsBackgroundableActions.keyFrom(mySelectedFile));
    ProgressManager.getInstance().run(task);
}
Also used : SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) Task(com.intellij.openapi.progress.Task) DiffRequest(com.intellij.diff.requests.DiffRequest) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DocumentContent(com.intellij.diff.contents.DocumentContent) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) Editor(com.intellij.openapi.editor.Editor) DiffContent(com.intellij.diff.contents.DiffContent) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 15 with SimpleDiffRequest

use of com.intellij.diff.requests.SimpleDiffRequest in project intellij-community by JetBrains.

the class VcsHistoryUtil method showDiff.

/**
   * Invokes {@link com.intellij.openapi.diff.DiffManager#getDiffTool()} to show difference between the given revisions of the given file.
   * @param project   project under vcs control.
   * @param path  file which revisions are compared.
   * @param revision1 first revision - 'before', to the left.
   * @param revision2 second revision - 'after', to the right.
   * @throws VcsException
   * @throws IOException
   */
public static void showDiff(@NotNull final Project project, @NotNull FilePath path, @NotNull VcsFileRevision revision1, @NotNull VcsFileRevision revision2, @NotNull String title1, @NotNull String title2) throws VcsException, IOException {
    final byte[] content1 = loadRevisionContent(revision1);
    final byte[] content2 = loadRevisionContent(revision2);
    FilePath path1 = getRevisionPath(revision1);
    FilePath path2 = getRevisionPath(revision2);
    String title;
    if (path1 != null && path2 != null) {
        title = DiffRequestFactoryImpl.getTitle(path1, path2, " -> ");
    } else {
        title = DiffRequestFactoryImpl.getContentTitle(path);
    }
    DiffContent diffContent1 = createContent(project, content1, revision1, path);
    DiffContent diffContent2 = createContent(project, content2, revision2, path);
    final DiffRequest request = new SimpleDiffRequest(title, diffContent1, diffContent2, title1, title2);
    diffContent1.putUserData(DiffUserDataKeysEx.REVISION_INFO, getRevisionInfo(revision1));
    diffContent2.putUserData(DiffUserDataKeysEx.REVISION_INFO, getRevisionInfo(revision2));
    WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() {

        public void run() {
            DiffManager.getInstance().showDiff(project, request);
        }
    }, null, project);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) DiffRequest(com.intellij.diff.requests.DiffRequest) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) DiffContent(com.intellij.diff.contents.DiffContent)

Aggregations

SimpleDiffRequest (com.intellij.diff.requests.SimpleDiffRequest)16 DiffContent (com.intellij.diff.contents.DiffContent)13 NotNull (org.jetbrains.annotations.NotNull)7 DiffRequest (com.intellij.diff.requests.DiffRequest)5 DocumentContent (com.intellij.diff.contents.DocumentContent)4 Nullable (org.jetbrains.annotations.Nullable)4 FileType (com.intellij.openapi.fileTypes.FileType)3 Project (com.intellij.openapi.project.Project)3 IOException (java.io.IOException)3 DiffContentFactory (com.intellij.diff.DiffContentFactory)2 Editor (com.intellij.openapi.editor.Editor)2 Ref (com.intellij.openapi.util.Ref)2 FilePath (com.intellij.openapi.vcs.FilePath)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ArrayList (java.util.ArrayList)2 JsonReader (com.google.gson.stream.JsonReader)1 DiffRequestPanel (com.intellij.diff.DiffRequestPanel)1 DiffRequestProducerException (com.intellij.diff.chains.DiffRequestProducerException)1 ErrorDiffRequest (com.intellij.diff.requests.ErrorDiffRequest)1 LoadingDiffRequest (com.intellij.diff.requests.LoadingDiffRequest)1