Search in sources :

Example 6 with DiffContent

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

the class PsiDiffContentFactory method comparePsiElements.

@Nullable
public static DiffRequest comparePsiElements(@NotNull PsiElement psiElement1, @NotNull PsiElement psiElement2) {
    if (!psiElement1.isValid() || !psiElement2.isValid())
        return null;
    Project project = psiElement1.getProject();
    LOG.assertTrue(project == psiElement2.getProject());
    DiffContent content1 = fromPsiElement(psiElement1);
    DiffContent content2 = fromPsiElement(psiElement2);
    if (content1 == null || content2 == null)
        return null;
    final ElementPresentation presentation1 = ElementPresentation.forElement(psiElement1);
    final ElementPresentation presentation2 = ElementPresentation.forElement(psiElement2);
    String title = DiffBundle.message("diff.element.qualified.name.vs.element.qualified.name.dialog.title", presentation1.getQualifiedName(), presentation2.getQualifiedName());
    return new SimpleDiffRequest(title, content1, content2, presentation1.getQualifiedName(), presentation2.getQualifiedName());
}
Also used : Project(com.intellij.openapi.project.Project) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) ElementPresentation(com.intellij.util.text.ElementPresentation) DiffContent(com.intellij.diff.contents.DiffContent) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with DiffContent

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

the class TwosideBinaryDiffViewer method performRediff.

@Override
@NotNull
protected Runnable performRediff(@NotNull final ProgressIndicator indicator) {
    try {
        indicator.checkCanceled();
        List<DiffContent> contents = myRequest.getContents();
        if (!(contents.get(0) instanceof FileContent) || !(contents.get(1) instanceof FileContent)) {
            return applyNotification(null);
        }
        final VirtualFile file1 = ((FileContent) contents.get(0)).getFile();
        final VirtualFile file2 = ((FileContent) contents.get(1)).getFile();
        final JComponent notification = ReadAction.compute(() -> {
            if (!file1.isValid() || !file2.isValid()) {
                return DiffNotifications.createError();
            }
            try {
                // we can't use getInputStream() here because we can't restore BOM marker
                // (getBom() can return null for binary files, while getInputStream() strips BOM for all files).
                // It can be made for files from VFS that implements FileSystemInterface though.
                byte[] bytes1 = file1.contentsToByteArray();
                byte[] bytes2 = file2.contentsToByteArray();
                return Arrays.equals(bytes1, bytes2) ? DiffNotifications.createEqualContents() : null;
            } catch (IOException e) {
                LOG.warn(e);
                return null;
            }
        });
        return applyNotification(notification);
    } catch (ProcessCanceledException e) {
        throw e;
    } catch (Throwable e) {
        LOG.error(e);
        return applyNotification(DiffNotifications.createError());
    }
}
Also used : FileContent(com.intellij.diff.contents.FileContent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) DiffContent(com.intellij.diff.contents.DiffContent) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with DiffContent

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

the class DiffRequestFactoryImpl method createFromFiles.

//
// Diff
//
@NotNull
@Override
public ContentDiffRequest createFromFiles(@Nullable Project project, @NotNull VirtualFile file1, @NotNull VirtualFile file2) {
    DiffContent content1 = myContentFactory.create(project, file1);
    DiffContent content2 = myContentFactory.create(project, file2);
    String title1 = getContentTitle(file1);
    String title2 = getContentTitle(file2);
    String title = getTitle(file1, file2);
    return new SimpleDiffRequest(title, content1, content2, title1, title2);
}
Also used : SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) DiffContent(com.intellij.diff.contents.DiffContent) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with DiffContent

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

the class DiffRequestFactoryImpl method createClipboardVsValue.

@NotNull
@Override
public ContentDiffRequest createClipboardVsValue(@NotNull String value) {
    DiffContent content1 = myContentFactory.createClipboardContent();
    DiffContent content2 = myContentFactory.create(value);
    String title1 = DiffBundle.message("diff.content.clipboard.content.title");
    String title2 = DiffBundle.message("diff.content.selected.value");
    String title = DiffBundle.message("diff.clipboard.vs.value.dialog.title");
    return new SimpleDiffRequest(title, content1, content2, title1, title2);
}
Also used : SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) DiffContent(com.intellij.diff.contents.DiffContent) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with DiffContent

use of com.intellij.diff.contents.DiffContent 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)

Aggregations

DiffContent (com.intellij.diff.contents.DiffContent)37 SimpleDiffRequest (com.intellij.diff.requests.SimpleDiffRequest)14 NotNull (org.jetbrains.annotations.NotNull)12 Nullable (org.jetbrains.annotations.Nullable)10 ContentDiffRequest (com.intellij.diff.requests.ContentDiffRequest)7 ArrayList (java.util.ArrayList)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 IOException (java.io.IOException)6 DiffRequest (com.intellij.diff.requests.DiffRequest)5 DocumentContent (com.intellij.diff.contents.DocumentContent)3 FileContent (com.intellij.diff.contents.FileContent)3 Project (com.intellij.openapi.project.Project)3 FilePath (com.intellij.openapi.vcs.FilePath)3 DiffIgnoredRangeProvider (com.intellij.diff.lang.DiffIgnoredRangeProvider)2 BinaryMergeRequestImpl (com.intellij.diff.requests.BinaryMergeRequestImpl)2 NullRevisionsProgress (com.intellij.history.integration.ui.models.NullRevisionsProgress)2 Editor (com.intellij.openapi.editor.Editor)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 Ref (com.intellij.openapi.util.Ref)2 VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)2