use of com.intellij.diff.contents.DiffContent in project intellij-community by JetBrains.
the class TwosideDiffViewer method canShowRequest.
public static <T extends EditorHolder> boolean canShowRequest(@NotNull DiffContext context, @NotNull DiffRequest request, @NotNull EditorHolderFactory<T> factory) {
if (!(request instanceof ContentDiffRequest))
return false;
List<DiffContent> contents = ((ContentDiffRequest) request).getContents();
if (contents.size() != 2)
return false;
boolean canShow = true;
boolean wantShow = false;
for (DiffContent content : contents) {
canShow &= factory.canShowContent(content, context);
wantShow |= factory.wantShowContent(content, context);
}
return canShow && wantShow;
}
use of com.intellij.diff.contents.DiffContent in project intellij-community by JetBrains.
the class TwosideDiffViewer method createEditorHolders.
//
// Editors
//
@NotNull
protected List<T> createEditorHolders(@NotNull EditorHolderFactory<T> factory) {
List<DiffContent> contents = myRequest.getContents();
List<T> holders = new ArrayList<>(2);
for (int i = 0; i < 2; i++) {
DiffContent content = contents.get(i);
holders.add(factory.create(content, myContext));
}
return holders;
}
use of com.intellij.diff.contents.DiffContent in project intellij-community by JetBrains.
the class ShowLineStatusRangeDiffAction method createDiffData.
@NotNull
private DiffRequest createDiffData() {
Range range = expand(myRange, myLineStatusTracker.getDocument(), myLineStatusTracker.getVcsDocument());
DiffContent vcsContent = createDiffContent(myLineStatusTracker.getVcsDocument(), myLineStatusTracker.getVcsTextRange(range));
DiffContent currentContent = createDiffContent(myLineStatusTracker.getDocument(), myLineStatusTracker.getCurrentTextRange(range));
return new SimpleDiffRequest(VcsBundle.message("dialog.title.diff.for.range"), vcsContent, currentContent, VcsBundle.message("diff.content.title.up.to.date"), VcsBundle.message("diff.content.title.current.range"));
}
use of com.intellij.diff.contents.DiffContent 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.contents.DiffContent 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);
}
Aggregations