Search in sources :

Example 6 with DocumentContent

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

the class DiffRequestFactoryImpl method createTextMergeRequest.

@NotNull
@Override
public TextMergeRequest createTextMergeRequest(@Nullable Project project, @NotNull VirtualFile output, @NotNull List<byte[]> byteContents, @Nullable String title, @NotNull List<String> contentTitles, @Nullable Consumer<MergeResult> applyCallback) throws InvalidDiffRequestException {
    if (byteContents.size() != 3)
        throw new IllegalArgumentException();
    if (contentTitles.size() != 3)
        throw new IllegalArgumentException();
    final Document outputDocument = FileDocumentManager.getInstance().getDocument(output);
    if (outputDocument == null)
        throw new InvalidDiffRequestException("Can't get output document: " + output.getPresentableUrl());
    if (!DiffUtil.canMakeWritable(outputDocument))
        throw new InvalidDiffRequestException("Output is read only: " + output.getPresentableUrl());
    DocumentContent outputContent = myContentFactory.create(project, outputDocument);
    CharSequence originalContent = outputDocument.getImmutableCharSequence();
    List<DocumentContent> contents = new ArrayList<>(3);
    for (byte[] bytes : byteContents) {
        contents.add(myContentFactory.createDocumentFromBytes(project, bytes, output));
    }
    return new TextMergeRequestImpl(project, outputContent, originalContent, contents, title, contentTitles, applyCallback);
}
Also used : TextMergeRequestImpl(com.intellij.diff.requests.TextMergeRequestImpl) DocumentContent(com.intellij.diff.contents.DocumentContent) ArrayList(java.util.ArrayList) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with DocumentContent

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

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

the class DiffRequestFactoryImpl method createMergeRequest.

//
// Merge
//
@NotNull
@Override
public MergeRequest createMergeRequest(@Nullable Project project, @Nullable FileType fileType, @NotNull Document outputDocument, @NotNull List<String> textContents, @Nullable String title, @NotNull List<String> titles, @Nullable Consumer<MergeResult> applyCallback) throws InvalidDiffRequestException {
    if (textContents.size() != 3)
        throw new IllegalArgumentException();
    if (titles.size() != 3)
        throw new IllegalArgumentException();
    if (!DiffUtil.canMakeWritable(outputDocument))
        throw new InvalidDiffRequestException("Output is read only");
    DocumentContent outputContent = myContentFactory.create(project, outputDocument, fileType);
    CharSequence originalContent = outputDocument.getImmutableCharSequence();
    List<DocumentContent> contents = new ArrayList<>(3);
    for (String text : textContents) {
        contents.add(myContentFactory.create(project, text, fileType));
    }
    return new TextMergeRequestImpl(project, outputContent, originalContent, contents, title, titles, applyCallback);
}
Also used : TextMergeRequestImpl(com.intellij.diff.requests.TextMergeRequestImpl) DocumentContent(com.intellij.diff.contents.DocumentContent) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with DocumentContent

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

the class ShowLineStatusRangeDiffAction method createDiffContent.

@NotNull
private DiffContent createDiffContent(@NotNull Document document, @NotNull TextRange textRange) {
    final Project project = myLineStatusTracker.getProject();
    DocumentContent content = DiffContentFactory.getInstance().create(project, document);
    return DiffContentFactory.getInstance().createFragment(project, content, textRange);
}
Also used : Project(com.intellij.openapi.project.Project) DocumentContent(com.intellij.diff.contents.DocumentContent) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with DocumentContent

use of com.intellij.diff.contents.DocumentContent in project intellij-postfix-templates by xylo.

the class CptPluginSettingsForm method showDiff.

private void showDiff() {
    Project project = CptUtil.getActiveProject();
    CptUtil.getTemplateFile(getSelectedLang().getLanguage()).ifPresent(file -> {
        VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(file);
        DocumentContent content1 = DiffContentFactory.getInstance().create(getTemplateText());
        DocumentContent content2 = DiffContentFactory.getInstance().createDocument(project, vFile);
        DiffManager.getInstance().showDiff(project, new SimpleDiffRequest("Templates Diff", content1, content2, "Predefined plugin templates", "Your templates"));
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) DocumentContent(com.intellij.diff.contents.DocumentContent)

Aggregations

DocumentContent (com.intellij.diff.contents.DocumentContent)18 NotNull (org.jetbrains.annotations.NotNull)6 SimpleDiffRequest (com.intellij.diff.requests.SimpleDiffRequest)5 FileType (com.intellij.openapi.fileTypes.FileType)5 Project (com.intellij.openapi.project.Project)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Nullable (org.jetbrains.annotations.Nullable)4 DiffContent (com.intellij.diff.contents.DiffContent)3 Editor (com.intellij.openapi.editor.Editor)3 DiffContentFactory (com.intellij.diff.DiffContentFactory)2 DiffRequest (com.intellij.diff.requests.DiffRequest)2 TextMergeRequestImpl (com.intellij.diff.requests.TextMergeRequestImpl)2 Document (com.intellij.openapi.editor.Document)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 ArrayList (java.util.ArrayList)2 DiffRequestPanel (com.intellij.diff.DiffRequestPanel)1 DiffTooBigException (com.intellij.diff.comparison.DiffTooBigException)1 EmptyContent (com.intellij.diff.contents.EmptyContent)1 LineFragment (com.intellij.diff.fragments.LineFragment)1 ContentDiffRequest (com.intellij.diff.requests.ContentDiffRequest)1