use of com.intellij.diff.contents.DocumentContent in project intellij-community by JetBrains.
the class DiffActionExecutor method showDiff.
public void showDiff() {
final Ref<VcsException> exceptionRef = new Ref<>();
final Ref<DiffRequest> requestRef = new Ref<>();
final Task.Backgroundable task = new Task.Backgroundable(myProject, VcsBundle.message("show.diff.progress.title.detailed", mySelectedFile.getPresentableUrl()), true) {
public void run(@NotNull ProgressIndicator indicator) {
final VcsRevisionNumber revisionNumber = getRevisionNumber();
try {
if (revisionNumber == null) {
return;
}
DiffContent content1 = createRemote(revisionNumber);
if (content1 == null)
return;
DiffContent content2 = DiffContentFactory.getInstance().create(myProject, mySelectedFile);
String title = DiffRequestFactory.getInstance().getTitle(mySelectedFile);
boolean inverted = false;
String title1;
String title2;
final FileStatus status = FileStatusManager.getInstance(myProject).getStatus(mySelectedFile);
if (status == null || FileStatus.NOT_CHANGED.equals(status) || FileStatus.UNKNOWN.equals(status) || FileStatus.IGNORED.equals(status)) {
final VcsRevisionNumber currentRevision = myDiffProvider.getCurrentRevision(mySelectedFile);
inverted = revisionNumber.compareTo(currentRevision) > 0;
title1 = revisionNumber.asString();
title2 = VcsBundle.message("diff.title.local.with.number", currentRevision.asString());
} else {
title1 = revisionNumber.asString();
title2 = VcsBundle.message("diff.title.local");
}
Integer line = null;
if (content2 instanceof DocumentContent) {
Editor[] editors = EditorFactory.getInstance().getEditors(((DocumentContent) content2).getDocument(), myProject);
if (editors.length != 0)
line = editors[0].getCaretModel().getLogicalPosition().line;
}
if (inverted) {
SimpleDiffRequest request = new SimpleDiffRequest(title, content2, content1, title2, title1);
if (line != null)
request.putUserData(DiffUserDataKeys.SCROLL_TO_LINE, Pair.create(Side.LEFT, line));
request.putUserData(DiffUserDataKeys.MASTER_SIDE, Side.LEFT);
requestRef.set(request);
} else {
SimpleDiffRequest request = new SimpleDiffRequest(title, content1, content2, title1, title2);
if (line != null)
request.putUserData(DiffUserDataKeys.SCROLL_TO_LINE, Pair.create(Side.RIGHT, line));
request.putUserData(DiffUserDataKeys.MASTER_SIDE, Side.RIGHT);
requestRef.set(request);
}
} catch (ProcessCanceledException e) {
//ignore
} catch (VcsException e) {
exceptionRef.set(e);
} catch (IOException e) {
exceptionRef.set(new VcsException(e));
}
}
@Override
public void onCancel() {
onSuccess();
}
@Override
public void onSuccess() {
myHandler.completed(VcsBackgroundableActions.keyFrom(mySelectedFile));
if (!exceptionRef.isNull()) {
AbstractVcsHelper.getInstance(myProject).showError(exceptionRef.get(), VcsBundle.message("message.title.diff"));
return;
}
if (!requestRef.isNull()) {
DiffManager.getInstance().showDiff(myProject, requestRef.get());
}
}
};
myHandler.register(VcsBackgroundableActions.keyFrom(mySelectedFile));
ProgressManager.getInstance().run(task);
}
use of com.intellij.diff.contents.DocumentContent in project intellij-community by JetBrains.
the class PatchDiffRequestFactory method createDiffRequest.
@NotNull
public static DiffRequest createDiffRequest(@Nullable Project project, @Nullable VirtualFile file, @NotNull List<String> contents, @Nullable String windowTitle, @NotNull List<String> titles) {
assert contents.size() == 3;
assert titles.size() == 3;
if (windowTitle == null)
windowTitle = getPatchTitle(file);
String localTitle = StringUtil.notNullize(titles.get(0), VcsBundle.message("patch.apply.conflict.local.version"));
String baseTitle = StringUtil.notNullize(titles.get(1), "Base Version");
String patchedTitle = StringUtil.notNullize(titles.get(2), VcsBundle.message("patch.apply.conflict.patched.version"));
FileType fileType = file != null ? file.getFileType() : null;
DiffContentFactory contentFactory = DiffContentFactory.getInstance();
DocumentContent localContent = file != null ? contentFactory.createDocument(project, file) : null;
if (localContent == null)
localContent = contentFactory.create(project, contents.get(0), fileType);
DocumentContent baseContent = contentFactory.create(project, contents.get(1), fileType);
DocumentContent patchedContent = contentFactory.create(project, contents.get(2), fileType);
return new SimpleDiffRequest(windowTitle, localContent, baseContent, patchedContent, localTitle, baseTitle, patchedTitle);
}
use of com.intellij.diff.contents.DocumentContent in project intellij-community by JetBrains.
the class TextMergeViewer method getDiffContents.
@NotNull
private static List<DiffContent> getDiffContents(@NotNull TextMergeRequest mergeRequest) {
List<DocumentContent> contents = mergeRequest.getContents();
final DocumentContent left = ThreeSide.LEFT.select(contents);
final DocumentContent right = ThreeSide.RIGHT.select(contents);
final DocumentContent output = mergeRequest.getOutputContent();
return ContainerUtil.list(left, output, right);
}
use of com.intellij.diff.contents.DocumentContent in project intellij-community by JetBrains.
the class TextDiffViewerUtil method checkDifferentDocuments.
public static void checkDifferentDocuments(@NotNull ContentDiffRequest request) {
// Actually, this should be a valid case. But it has little practical sense and will require explicit checks everywhere.
// Some listeners will be processed once instead of 2 times, some listeners will cause illegal document modifications.
List<DiffContent> contents = request.getContents();
boolean sameDocuments = false;
for (int i = 0; i < contents.size(); i++) {
for (int j = i + 1; j < contents.size(); j++) {
DiffContent content1 = contents.get(i);
DiffContent content2 = contents.get(j);
if (!(content1 instanceof DocumentContent))
continue;
if (!(content2 instanceof DocumentContent))
continue;
sameDocuments |= ((DocumentContent) content1).getDocument() == ((DocumentContent) content2).getDocument();
}
}
if (sameDocuments) {
StringBuilder message = new StringBuilder();
message.append("DiffRequest with same documents detected\n");
message.append(request.toString()).append("\n");
for (DiffContent content : contents) {
message.append(content.toString()).append("\n");
}
LOG.warn(new Throwable(message.toString()));
}
}
use of com.intellij.diff.contents.DocumentContent in project intellij-community by JetBrains.
the class DiffUtil method createTitle.
@Nullable
private static JComponent createTitle(@NotNull String title, @NotNull DiffContent content, boolean equalCharsets, boolean equalSeparators, @Nullable Editor editor) {
if (content instanceof EmptyContent)
return null;
DocumentContent documentContent = (DocumentContent) content;
Charset charset = equalCharsets ? null : documentContent.getCharset();
Boolean bom = equalCharsets ? null : documentContent.hasBom();
LineSeparator separator = equalSeparators ? null : documentContent.getLineSeparator();
boolean isReadOnly = editor == null || editor.isViewer() || !canMakeWritable(editor.getDocument());
return createTitle(title, separator, charset, bom, isReadOnly);
}
Aggregations