use of com.intellij.diff.requests.SimpleDiffRequest in project intellij-plugins by JetBrains.
the class DiffWindowOpener method showDiff.
public void showDiff() {
String title = "Diff for " + myVFile.getDisplayName();
String title1 = "My Version";
String title2 = myRemoteUser.getDisplayName() + "'s Version";
DiffContent content1 = DiffContentFactory.getInstance().create(myProject, myVirtualFile);
DiffContent content2 = DiffContentFactory.getInstance().create(myRemoteText, myVirtualFile.getFileType());
DiffRequest request = new SimpleDiffRequest(title, content1, content2, title1, title2);
DiffManagerEx.getInstance().showDiff(myProject, request, DiffDialogHints.NON_MODAL);
}
use of com.intellij.diff.requests.SimpleDiffRequest in project intellij-community by JetBrains.
the class CompareClipboardWithSelectionAction method getDiffRequest.
@Nullable
@Override
protected DiffRequest getDiffRequest(@NotNull AnActionEvent e) {
Project project = e.getRequiredData(CommonDataKeys.PROJECT);
Editor editor = getEditor(e);
FileType editorFileType = getEditorFileType(e);
assert editor != null;
DocumentContent content2 = createContent(project, editor, editorFileType);
DocumentContent content1 = DiffContentFactory.getInstance().createClipboardContent(project, content2);
String title1 = DiffBundle.message("diff.content.clipboard.content.title");
String title2 = createContentTitle(editor);
String title = DiffBundle.message("diff.clipboard.vs.editor.dialog.title");
SimpleDiffRequest request = new SimpleDiffRequest(title, content1, content2, title1, title2);
if (editor.isViewer()) {
request.putUserData(DiffUserDataKeys.FORCE_READ_ONLY_CONTENTS, new boolean[] { false, true });
}
return request;
}
use of com.intellij.diff.requests.SimpleDiffRequest 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.requests.SimpleDiffRequest 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.requests.SimpleDiffRequest 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);
}
Aggregations