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