Search in sources :

Example 31 with DiffContent

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

the class DiffUtil method createSimpleTitles.

//
// Titles
//
@NotNull
public static List<JComponent> createSimpleTitles(@NotNull ContentDiffRequest request) {
    List<DiffContent> contents = request.getContents();
    List<String> titles = request.getContentTitles();
    if (!ContainerUtil.exists(titles, Condition.NOT_NULL)) {
        return Collections.nCopies(titles.size(), null);
    }
    List<JComponent> components = new ArrayList<>(titles.size());
    for (int i = 0; i < contents.size(); i++) {
        JComponent title = createTitle(StringUtil.notNullize(titles.get(i)));
        title = createTitleWithNotifications(title, contents.get(i));
        components.add(title);
    }
    return components;
}
Also used : DiffContent(com.intellij.diff.contents.DiffContent) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 32 with DiffContent

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

the class DiffRequestFactoryImpl method createBinaryMergeRequest.

@NotNull
@Override
public MergeRequest createBinaryMergeRequest(@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();
    try {
        FileContent outputContent = myContentFactory.createFile(project, output);
        if (outputContent == null)
            throw new InvalidDiffRequestException("Can't process file: " + output);
        byte[] originalContent = output.contentsToByteArray();
        List<DiffContent> contents = new ArrayList<>(3);
        for (byte[] bytes : byteContents) {
            contents.add(myContentFactory.createFromBytes(project, bytes, output));
        }
        return new BinaryMergeRequestImpl(project, outputContent, originalContent, contents, byteContents, title, contentTitles, applyCallback);
    } catch (IOException e) {
        throw new InvalidDiffRequestException("Can't read from file", e);
    }
}
Also used : FileContent(com.intellij.diff.contents.FileContent) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BinaryMergeRequestImpl(com.intellij.diff.requests.BinaryMergeRequestImpl) DiffContent(com.intellij.diff.contents.DiffContent) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with DiffContent

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

the class DiffRequestFactoryImpl method createBinaryMergeRequestFromFiles.

@NotNull
public MergeRequest createBinaryMergeRequestFromFiles(@Nullable Project project, @NotNull VirtualFile output, @NotNull List<VirtualFile> fileContents, @Nullable String title, @NotNull List<String> contentTitles, @Nullable Consumer<MergeResult> applyCallback) throws InvalidDiffRequestException {
    if (fileContents.size() != 3)
        throw new IllegalArgumentException();
    if (contentTitles.size() != 3)
        throw new IllegalArgumentException();
    try {
        FileContent outputContent = myContentFactory.createFile(project, output);
        if (outputContent == null)
            throw new InvalidDiffRequestException("Can't process file: " + output.getPresentableUrl());
        byte[] originalContent = output.contentsToByteArray();
        List<DiffContent> contents = new ArrayList<>(3);
        List<byte[]> byteContents = new ArrayList<>(3);
        for (VirtualFile file : fileContents) {
            FileContent content = myContentFactory.createFile(project, file);
            if (content == null)
                throw new InvalidDiffRequestException("Can't process file: " + file.getPresentableUrl());
            contents.add(content);
            // TODO: we can read contents from file when needed
            byteContents.add(file.contentsToByteArray());
        }
        return new BinaryMergeRequestImpl(project, outputContent, originalContent, contents, byteContents, title, contentTitles, applyCallback);
    } catch (IOException e) {
        throw new InvalidDiffRequestException("Can't read from file", e);
    }
}
Also used : FileContent(com.intellij.diff.contents.FileContent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BinaryMergeRequestImpl(com.intellij.diff.requests.BinaryMergeRequestImpl) DiffContent(com.intellij.diff.contents.DiffContent) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with DiffContent

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

the class VcsHistoryUtil method showDiff.

/**
   * Invokes {@link com.intellij.openapi.diff.DiffManager#getDiffTool()} to show difference between the given revisions of the given file.
   * @param project   project under vcs control.
   * @param path  file which revisions are compared.
   * @param revision1 first revision - 'before', to the left.
   * @param revision2 second revision - 'after', to the right.
   * @throws VcsException
   * @throws IOException
   */
public static void showDiff(@NotNull final Project project, @NotNull FilePath path, @NotNull VcsFileRevision revision1, @NotNull VcsFileRevision revision2, @NotNull String title1, @NotNull String title2) throws VcsException, IOException {
    final byte[] content1 = loadRevisionContent(revision1);
    final byte[] content2 = loadRevisionContent(revision2);
    FilePath path1 = getRevisionPath(revision1);
    FilePath path2 = getRevisionPath(revision2);
    String title;
    if (path1 != null && path2 != null) {
        title = DiffRequestFactoryImpl.getTitle(path1, path2, " -> ");
    } else {
        title = DiffRequestFactoryImpl.getContentTitle(path);
    }
    DiffContent diffContent1 = createContent(project, content1, revision1, path);
    DiffContent diffContent2 = createContent(project, content2, revision2, path);
    final DiffRequest request = new SimpleDiffRequest(title, diffContent1, diffContent2, title1, title2);
    diffContent1.putUserData(DiffUserDataKeysEx.REVISION_INFO, getRevisionInfo(revision1));
    diffContent2.putUserData(DiffUserDataKeysEx.REVISION_INFO, getRevisionInfo(revision2));
    WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() {

        public void run() {
            DiffManager.getInstance().showDiff(project, request);
        }
    }, null, project);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) DiffRequest(com.intellij.diff.requests.DiffRequest) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) DiffContent(com.intellij.diff.contents.DiffContent)

Example 35 with DiffContent

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

the class SvnPropertiesDiffViewer method collectRecords.

@NotNull
private static List<PropertyRecord> collectRecords(@NotNull SvnPropertiesDiffRequest request) {
    List<DiffContent> originalContents = request.getContents();
    List<PropertyData> properties1 = getProperties(originalContents.get(0));
    List<PropertyData> properties2 = getProperties(originalContents.get(1));
    Map<String, PropertyValue> before = new HashMap<>();
    Map<String, PropertyValue> after = new HashMap<>();
    if (properties1 != null) {
        for (PropertyData data : properties1) {
            before.put(data.getName(), data.getValue());
        }
    }
    if (properties2 != null) {
        for (PropertyData data : properties2) {
            after.put(data.getName(), data.getValue());
        }
    }
    List<PropertyRecord> records = new ArrayList<>();
    for (String name : ContainerUtil.union(before.keySet(), after.keySet())) {
        records.add(createRecord(name, before.get(name), after.get(name)));
    }
    ContainerUtil.sort(records, (o1, o2) -> StringUtil.naturalCompare(o1.getName(), o2.getName()));
    return records;
}
Also used : PropertyData(org.jetbrains.idea.svn.properties.PropertyData) HashMap(com.intellij.util.containers.hash.HashMap) ArrayList(java.util.ArrayList) PropertyValue(org.jetbrains.idea.svn.properties.PropertyValue) DiffContent(com.intellij.diff.contents.DiffContent) NotNull(org.jetbrains.annotations.NotNull)

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