Search in sources :

Example 1 with DocumentContent

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

the class FileHistoryDialogTest method testContentForCurrentRevision.

public void testContentForCurrentRevision() throws IOException {
    VirtualFile f = createChildData(myRoot, "f.txt");
    setBinaryContent(f, "old".getBytes());
    setBinaryContent(f, "current".getBytes());
    FileHistoryDialogModel m = createFileModelAndSelectRevisions(f, 0, 0);
    assertDiffContents("old", "current", m);
    assertTrue(getRightDiffContent(m) instanceof DocumentContent);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DocumentContent(com.intellij.diff.contents.DocumentContent) EntireFileHistoryDialogModel(com.intellij.history.integration.ui.models.EntireFileHistoryDialogModel) FileHistoryDialogModel(com.intellij.history.integration.ui.models.FileHistoryDialogModel)

Example 2 with DocumentContent

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

the class PsiDiffContentFactory method fromPsiElement.

@Nullable
private static DiffContent fromPsiElement(@NotNull PsiElement psiElement) {
    DiffContentFactory factory = DiffContentFactory.getInstance();
    if (psiElement instanceof PsiFile) {
        return factory.create(psiElement.getProject(), ((PsiFile) psiElement).getVirtualFile());
    } else if (psiElement instanceof PsiDirectory) {
        return factory.create(psiElement.getProject(), ((PsiDirectory) psiElement).getVirtualFile());
    }
    PsiFile containingFile = psiElement.getContainingFile();
    if (containingFile == null) {
        String text = psiElement.getText();
        if (text == null)
            return null;
        return factory.create(psiElement.getProject(), text, psiElement.getLanguage().getAssociatedFileType(), false);
    }
    DocumentContent wholeFileContent = factory.createDocument(psiElement.getProject(), containingFile.getVirtualFile());
    if (wholeFileContent == null)
        return null;
    return factory.createFragment(psiElement.getProject(), wholeFileContent, psiElement.getTextRange());
}
Also used : DiffContentFactory(com.intellij.diff.DiffContentFactory) PsiDirectory(com.intellij.psi.PsiDirectory) DocumentContent(com.intellij.diff.contents.DocumentContent) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with DocumentContent

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

the class LangDiffIgnoredRangeProvider method getLanguage.

@Nullable
private static Language getLanguage(@NotNull Project project, @NotNull DiffContent content) {
    Language language = content.getUserData(DiffUserDataKeys.LANGUAGE);
    if (language != null)
        return language;
    FileType type = content.getContentType();
    if (type instanceof LanguageFileType)
        language = ((LanguageFileType) type).getLanguage();
    if (language != null && content instanceof DocumentContent) {
        VirtualFile highlightFile = ((DocumentContent) content).getHighlightFile();
        if (highlightFile != null)
            language = LanguageSubstitutors.INSTANCE.substituteLanguage(language, highlightFile, project);
    }
    return language;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) DocumentContent(com.intellij.diff.contents.DocumentContent) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with DocumentContent

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

the class ListenerDiffViewerBase method onInit.

@Override
protected void onInit() {
    super.onInit();
    VirtualFileListener fileListener = createFileListener(myRequest);
    if (fileListener != null)
        VirtualFileManager.getInstance().addVirtualFileListener(fileListener, this);
    DocumentListener documentListener = createDocumentListener();
    List<Document> documents = ContainerUtil.mapNotNull(myRequest.getContents(), (content) -> {
        return content instanceof DocumentContent ? ((DocumentContent) content).getDocument() : null;
    });
    TextDiffViewerUtil.installDocumentListeners(documentListener, documents, this);
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) DocumentContent(com.intellij.diff.contents.DocumentContent) Document(com.intellij.openapi.editor.Document)

Example 5 with DocumentContent

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

the class UnifiedDiffViewer method performRediff.

@Override
@NotNull
protected Runnable performRediff(@NotNull final ProgressIndicator indicator) {
    try {
        indicator.checkCanceled();
        final Document document1 = getContent1().getDocument();
        final Document document2 = getContent2().getDocument();
        final CharSequence[] texts = ReadAction.compute(() -> {
            return new CharSequence[] { document1.getImmutableCharSequence(), document2.getImmutableCharSequence() };
        });
        final List<LineFragment> fragments = myTextDiffProvider.compare(texts[0], texts[1], indicator);
        final DocumentContent content1 = getContent1();
        final DocumentContent content2 = getContent2();
        indicator.checkCanceled();
        TwosideDocumentData data = ReadAction.compute(() -> {
            indicator.checkCanceled();
            UnifiedFragmentBuilder builder = new UnifiedFragmentBuilder(fragments, document1, document2, myMasterSide);
            builder.exec();
            indicator.checkCanceled();
            EditorHighlighter highlighter = buildHighlighter(myProject, content1, content2, texts[0], texts[1], builder.getRanges(), builder.getText().length());
            UnifiedEditorRangeHighlighter rangeHighlighter = new UnifiedEditorRangeHighlighter(myProject, document1, document2, builder.getRanges());
            return new TwosideDocumentData(builder, highlighter, rangeHighlighter);
        });
        UnifiedFragmentBuilder builder = data.getBuilder();
        FileType fileType = content2.getContentType() == null ? content1.getContentType() : content2.getContentType();
        LineNumberConvertor convertor1 = builder.getConvertor1();
        LineNumberConvertor convertor2 = builder.getConvertor2();
        List<LineRange> changedLines = builder.getChangedLines();
        boolean isContentsEqual = builder.isEqual();
        CombinedEditorData editorData = new CombinedEditorData(builder.getText(), data.getHighlighter(), data.getRangeHighlighter(), fileType, convertor1.createConvertor(), convertor2.createConvertor());
        return apply(editorData, builder.getBlocks(), convertor1, convertor2, changedLines, isContentsEqual);
    } catch (DiffTooBigException e) {
        return () -> {
            clearDiffPresentation();
            myPanel.setTooBigContent();
        };
    } catch (ProcessCanceledException e) {
        throw e;
    } catch (Throwable e) {
        LOG.error(e);
        return () -> {
            clearDiffPresentation();
            myPanel.setErrorContent();
        };
    }
}
Also used : LineFragment(com.intellij.diff.fragments.LineFragment) FileType(com.intellij.openapi.fileTypes.FileType) DocumentContent(com.intellij.diff.contents.DocumentContent) DiffTooBigException(com.intellij.diff.comparison.DiffTooBigException) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

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