Search in sources :

Example 26 with DiffContent

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

the class OnesideDiffViewer 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;
    DiffContent content1 = contents.get(0);
    DiffContent content2 = contents.get(1);
    if (content1 instanceof EmptyContent) {
        return factory.canShowContent(content2, context) && factory.wantShowContent(content2, context);
    }
    if (content2 instanceof EmptyContent) {
        return factory.canShowContent(content1, context) && factory.wantShowContent(content1, context);
    }
    return false;
}
Also used : ContentDiffRequest(com.intellij.diff.requests.ContentDiffRequest) DiffContent(com.intellij.diff.contents.DiffContent) EmptyContent(com.intellij.diff.contents.EmptyContent)

Example 27 with DiffContent

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

the class ThreesideDiffViewer 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() != 3)
        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 28 with DiffContent

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

the class ThreesideDiffViewer method createEditorHolders.

@NotNull
protected List<T> createEditorHolders(@NotNull EditorHolderFactory<T> factory) {
    List<DiffContent> contents = myRequest.getContents();
    List<T> holders = new ArrayList<>(3);
    for (int i = 0; i < 3; 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 29 with DiffContent

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

the class TextDiffViewerUtil method checkDifferentDocuments.

public static void checkDifferentDocuments(@NotNull ContentDiffRequest request) {
    // Actually, this should be a valid case. But it has little practical sense and will require explicit checks everywhere.
    // Some listeners will be processed once instead of 2 times, some listeners will cause illegal document modifications.
    List<DiffContent> contents = request.getContents();
    boolean sameDocuments = false;
    for (int i = 0; i < contents.size(); i++) {
        for (int j = i + 1; j < contents.size(); j++) {
            DiffContent content1 = contents.get(i);
            DiffContent content2 = contents.get(j);
            if (!(content1 instanceof DocumentContent))
                continue;
            if (!(content2 instanceof DocumentContent))
                continue;
            sameDocuments |= ((DocumentContent) content1).getDocument() == ((DocumentContent) content2).getDocument();
        }
    }
    if (sameDocuments) {
        StringBuilder message = new StringBuilder();
        message.append("DiffRequest with same documents detected\n");
        message.append(request.toString()).append("\n");
        for (DiffContent content : contents) {
            message.append(content.toString()).append("\n");
        }
        LOG.warn(new Throwable(message.toString()));
    }
}
Also used : DocumentContent(com.intellij.diff.contents.DocumentContent) DiffContent(com.intellij.diff.contents.DiffContent)

Example 30 with DiffContent

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

the class MergeUtil method putRevisionInfo.

private static void putRevisionInfo(@NotNull List<? extends DiffContent> contents, @NotNull MergeData data) {
    for (ThreeSide side : ThreeSide.values()) {
        DiffContent content = side.select(contents);
        FilePath filePath = side.select(data.CURRENT_FILE_PATH, data.ORIGINAL_FILE_PATH, data.LAST_FILE_PATH);
        VcsRevisionNumber revision = side.select(data.CURRENT_REVISION_NUMBER, data.ORIGINAL_REVISION_NUMBER, data.LAST_REVISION_NUMBER);
        if (filePath != null && revision != null) {
            content.putUserData(DiffUserDataKeysEx.REVISION_INFO, Pair.create(filePath, revision));
        }
    }
}
Also used : ThreeSide(com.intellij.diff.util.ThreeSide) FilePath(com.intellij.openapi.vcs.FilePath) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) DiffContent(com.intellij.diff.contents.DiffContent)

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