Search in sources :

Example 16 with DiffContent

use of com.intellij.diff.contents.DiffContent in project intellij-community by JetBrains.

the class TwosideDiffViewer method canShowRequest.

public static <T extends EditorHolder> boolean canShowRequest(@NotNull DiffContext context, @NotNull DiffRequest request, @NotNull EditorHolderFactory<T> factory) {
    if (!(request instanceof ContentDiffRequest))
        return false;
    List<DiffContent> contents = ((ContentDiffRequest) request).getContents();
    if (contents.size() != 2)
        return false;
    boolean canShow = true;
    boolean wantShow = false;
    for (DiffContent content : contents) {
        canShow &= factory.canShowContent(content, context);
        wantShow |= factory.wantShowContent(content, context);
    }
    return canShow && wantShow;
}
Also used : ContentDiffRequest(com.intellij.diff.requests.ContentDiffRequest) DiffContent(com.intellij.diff.contents.DiffContent)

Example 17 with DiffContent

use of com.intellij.diff.contents.DiffContent in project intellij-community by JetBrains.

the class TwosideDiffViewer method createEditorHolders.

//
// Editors
//
@NotNull
protected List<T> createEditorHolders(@NotNull EditorHolderFactory<T> factory) {
    List<DiffContent> contents = myRequest.getContents();
    List<T> holders = new ArrayList<>(2);
    for (int i = 0; i < 2; i++) {
        DiffContent content = contents.get(i);
        holders.add(factory.create(content, myContext));
    }
    return holders;
}
Also used : ArrayList(java.util.ArrayList) DiffContent(com.intellij.diff.contents.DiffContent) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with DiffContent

use of com.intellij.diff.contents.DiffContent in project intellij-community by JetBrains.

the class ShowLineStatusRangeDiffAction method createDiffData.

@NotNull
private DiffRequest createDiffData() {
    Range range = expand(myRange, myLineStatusTracker.getDocument(), myLineStatusTracker.getVcsDocument());
    DiffContent vcsContent = createDiffContent(myLineStatusTracker.getVcsDocument(), myLineStatusTracker.getVcsTextRange(range));
    DiffContent currentContent = createDiffContent(myLineStatusTracker.getDocument(), myLineStatusTracker.getCurrentTextRange(range));
    return new SimpleDiffRequest(VcsBundle.message("dialog.title.diff.for.range"), vcsContent, currentContent, VcsBundle.message("diff.content.title.up.to.date"), VcsBundle.message("diff.content.title.current.range"));
}
Also used : SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) TextRange(com.intellij.openapi.util.TextRange) DiffContent(com.intellij.diff.contents.DiffContent) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with DiffContent

use of com.intellij.diff.contents.DiffContent 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 20 with DiffContent

use of com.intellij.diff.contents.DiffContent 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)

Aggregations

DiffContent (com.intellij.diff.contents.DiffContent)37 SimpleDiffRequest (com.intellij.diff.requests.SimpleDiffRequest)14 NotNull (org.jetbrains.annotations.NotNull)12 Nullable (org.jetbrains.annotations.Nullable)10 ContentDiffRequest (com.intellij.diff.requests.ContentDiffRequest)7 ArrayList (java.util.ArrayList)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 IOException (java.io.IOException)6 DiffRequest (com.intellij.diff.requests.DiffRequest)5 DocumentContent (com.intellij.diff.contents.DocumentContent)3 FileContent (com.intellij.diff.contents.FileContent)3 Project (com.intellij.openapi.project.Project)3 FilePath (com.intellij.openapi.vcs.FilePath)3 DiffIgnoredRangeProvider (com.intellij.diff.lang.DiffIgnoredRangeProvider)2 BinaryMergeRequestImpl (com.intellij.diff.requests.BinaryMergeRequestImpl)2 NullRevisionsProgress (com.intellij.history.integration.ui.models.NullRevisionsProgress)2 Editor (com.intellij.openapi.editor.Editor)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 Ref (com.intellij.openapi.util.Ref)2 VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)2