Search in sources :

Example 1 with TextMergeRequestImpl

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

use of com.intellij.diff.requests.TextMergeRequestImpl 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)

Aggregations

DocumentContent (com.intellij.diff.contents.DocumentContent)2 TextMergeRequestImpl (com.intellij.diff.requests.TextMergeRequestImpl)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 Document (com.intellij.openapi.editor.Document)1