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