Search in sources :

Example 1 with ContentDiffRequest

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

the class AnnotateDiffViewerAction method createTwosideAnnotationsLoader.

@Nullable
private static FileAnnotationLoader createTwosideAnnotationsLoader(@NotNull Project project, @NotNull DiffRequest request, @NotNull Side side) {
    Change change = request.getUserData(ChangeDiffRequestProducer.CHANGE_KEY);
    if (change != null) {
        ContentRevision revision = side.select(change.getBeforeRevision(), change.getAfterRevision());
        if (revision != null) {
            AbstractVcs vcs = ChangesUtil.getVcsForChange(change, project);
            if (revision instanceof CurrentContentRevision) {
                VirtualFile file = ((CurrentContentRevision) revision).getVirtualFile();
                FileAnnotationLoader loader = doCreateAnnotationsLoader(project, vcs, file);
                if (loader != null)
                    return loader;
            } else {
                FileAnnotationLoader loader = doCreateAnnotationsLoader(vcs, revision.getFile(), revision.getRevisionNumber());
                if (loader != null)
                    return loader;
            }
        }
    }
    if (request instanceof ContentDiffRequest) {
        ContentDiffRequest requestEx = (ContentDiffRequest) request;
        if (requestEx.getContents().size() == 2) {
            DiffContent content = side.select(requestEx.getContents());
            return createAnnotationsLoader(project, content);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentDiffRequest(com.intellij.diff.requests.ContentDiffRequest) DiffContent(com.intellij.diff.contents.DiffContent) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ContentDiffRequest

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

the class CompareClipboardWithSelectionAction method getEditorFileType.

@Nullable
private static FileType getEditorFileType(@NotNull AnActionEvent e) {
    DiffContent content = e.getData(DiffDataKeys.CURRENT_CONTENT);
    if (content != null && content.getContentType() != null)
        return content.getContentType();
    DiffRequest request = e.getData(DiffDataKeys.DIFF_REQUEST);
    if (request instanceof ContentDiffRequest) {
        for (DiffContent diffContent : ((ContentDiffRequest) request).getContents()) {
            FileType type = diffContent.getContentType();
            if (type != null && type != UnknownFileType.INSTANCE)
                return type;
        }
    }
    return null;
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType) UnknownFileType(com.intellij.openapi.fileTypes.UnknownFileType) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) ContentDiffRequest(com.intellij.diff.requests.ContentDiffRequest) DiffRequest(com.intellij.diff.requests.DiffRequest) ContentDiffRequest(com.intellij.diff.requests.ContentDiffRequest) DiffContent(com.intellij.diff.contents.DiffContent) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ContentDiffRequest

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

the class CompareFileWithEditorAction method getDiffRequest.

@Nullable
@Override
protected DiffRequest getDiffRequest(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    VirtualFile selectedFile = getSelectedFile(e);
    VirtualFile currentFile = getEditingFile(e);
    assert selectedFile != null && currentFile != null;
    ContentDiffRequest request = DiffRequestFactory.getInstance().createFromFiles(project, selectedFile, currentFile);
    DiffContent editorContent = request.getContents().get(1);
    if (editorContent instanceof DocumentContent) {
        Editor[] editors = EditorFactory.getInstance().getEditors(((DocumentContent) editorContent).getDocument());
        if (editors.length != 0) {
            request.putUserData(DiffUserDataKeys.SCROLL_TO_LINE, Pair.create(Side.RIGHT, editors[0].getCaretModel().getLogicalPosition().line));
        }
    }
    return request;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DocumentContent(com.intellij.diff.contents.DocumentContent) ContentDiffRequest(com.intellij.diff.requests.ContentDiffRequest) Editor(com.intellij.openapi.editor.Editor) DiffContent(com.intellij.diff.contents.DiffContent) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ContentDiffRequest

use of com.intellij.diff.requests.ContentDiffRequest 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 5 with ContentDiffRequest

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

the class AnnotateDiffViewerAction method createThreesideAnnotationsLoader.

@Nullable
private static FileAnnotationLoader createThreesideAnnotationsLoader(@NotNull Project project, @NotNull DiffRequest request, @NotNull ThreeSide side) {
    if (request instanceof ContentDiffRequest) {
        ContentDiffRequest requestEx = (ContentDiffRequest) request;
        if (requestEx.getContents().size() == 3) {
            DiffContent content = side.select(requestEx.getContents());
            FileAnnotationLoader loader = createAnnotationsLoader(project, content);
            if (loader != null)
                return loader;
        }
    }
    return null;
}
Also used : ContentDiffRequest(com.intellij.diff.requests.ContentDiffRequest) DiffContent(com.intellij.diff.contents.DiffContent) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DiffContent (com.intellij.diff.contents.DiffContent)7 ContentDiffRequest (com.intellij.diff.requests.ContentDiffRequest)7 Nullable (org.jetbrains.annotations.Nullable)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 DocumentContent (com.intellij.diff.contents.DocumentContent)1 EmptyContent (com.intellij.diff.contents.EmptyContent)1 DiffRequest (com.intellij.diff.requests.DiffRequest)1 SimpleDiffRequest (com.intellij.diff.requests.SimpleDiffRequest)1 Editor (com.intellij.openapi.editor.Editor)1 FileType (com.intellij.openapi.fileTypes.FileType)1 UnknownFileType (com.intellij.openapi.fileTypes.UnknownFileType)1 Project (com.intellij.openapi.project.Project)1