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);
}
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;
}
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);
}
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);
}
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"));
});
}
Aggregations