use of com.intellij.diff.requests.SimpleDiffRequest in project intellij-community by JetBrains.
the class ChangeDiffRequestProducer method createRequest.
@NotNull
private DiffRequest createRequest(@Nullable Project project, @NotNull Change change, @NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException {
if (ChangesUtil.isTextConflictingChange(change)) {
// three side diff
// FIXME: This part is ugly as a VCS merge subsystem itself.
FilePath path = ChangesUtil.getFilePath(change);
VirtualFile file = path.getVirtualFile();
if (file == null) {
file = LocalFileSystem.getInstance().refreshAndFindFileByPath(path.getPath());
}
if (file == null)
throw new DiffRequestProducerException("Can't show merge conflict - file not found");
if (project == null) {
throw new DiffRequestProducerException("Can't show merge conflict - project is unknown");
}
final AbstractVcs vcs = ChangesUtil.getVcsForChange(change, project);
if (vcs == null || vcs.getMergeProvider() == null) {
throw new DiffRequestProducerException("Can't show merge conflict - operation nos supported");
}
try {
// FIXME: loadRevisions() can call runProcessWithProgressSynchronously() inside
final Ref<Throwable> exceptionRef = new Ref<>();
final Ref<MergeData> mergeDataRef = new Ref<>();
final VirtualFile finalFile = file;
ApplicationManager.getApplication().invokeAndWait(() -> {
try {
mergeDataRef.set(vcs.getMergeProvider().loadRevisions(finalFile));
} catch (VcsException e) {
exceptionRef.set(e);
}
});
if (!exceptionRef.isNull()) {
Throwable e = exceptionRef.get();
if (e instanceof VcsException)
throw (VcsException) e;
if (e instanceof Error)
throw (Error) e;
if (e instanceof RuntimeException)
throw (RuntimeException) e;
throw new RuntimeException(e);
}
MergeData mergeData = mergeDataRef.get();
ContentRevision bRev = change.getBeforeRevision();
ContentRevision aRev = change.getAfterRevision();
String beforeRevisionTitle = getRevisionTitle(bRev, "Your version");
String afterRevisionTitle = getRevisionTitle(aRev, "Server version");
String title = DiffRequestFactory.getInstance().getTitle(file);
List<String> titles = ContainerUtil.list(beforeRevisionTitle, "Base Version", afterRevisionTitle);
DiffContentFactory contentFactory = DiffContentFactory.getInstance();
List<DiffContent> contents = ContainerUtil.list(contentFactory.createFromBytes(project, mergeData.CURRENT, file), contentFactory.createFromBytes(project, mergeData.ORIGINAL, file), contentFactory.createFromBytes(project, mergeData.LAST, file));
SimpleDiffRequest request = new SimpleDiffRequest(title, contents, titles);
MergeUtil.putRevisionInfos(request, mergeData);
return request;
} catch (VcsException | IOException e) {
LOG.info(e);
throw new DiffRequestProducerException(e);
}
} else {
ContentRevision bRev = change.getBeforeRevision();
ContentRevision aRev = change.getAfterRevision();
if (bRev == null && aRev == null) {
LOG.warn("Both revision contents are empty");
throw new DiffRequestProducerException("Bad revisions contents");
}
if (bRev != null)
checkContentRevision(project, bRev, context, indicator);
if (aRev != null)
checkContentRevision(project, aRev, context, indicator);
String title = getRequestTitle(change);
indicator.setIndeterminate(true);
DiffContent content1 = createContent(project, bRev, context, indicator);
DiffContent content2 = createContent(project, aRev, context, indicator);
final String userLeftRevisionTitle = (String) myChangeContext.get(DiffUserDataKeysEx.VCS_DIFF_LEFT_CONTENT_TITLE);
String beforeRevisionTitle = userLeftRevisionTitle != null ? userLeftRevisionTitle : getRevisionTitle(bRev, "Base version");
final String userRightRevisionTitle = (String) myChangeContext.get(DiffUserDataKeysEx.VCS_DIFF_RIGHT_CONTENT_TITLE);
String afterRevisionTitle = userRightRevisionTitle != null ? userRightRevisionTitle : getRevisionTitle(aRev, "Your version");
SimpleDiffRequest request = new SimpleDiffRequest(title, content1, content2, beforeRevisionTitle, afterRevisionTitle);
boolean bRevCurrent = bRev instanceof CurrentContentRevision;
boolean aRevCurrent = aRev instanceof CurrentContentRevision;
if (bRevCurrent && !aRevCurrent)
request.putUserData(DiffUserDataKeys.MASTER_SIDE, Side.LEFT);
if (!bRevCurrent && aRevCurrent)
request.putUserData(DiffUserDataKeys.MASTER_SIDE, Side.RIGHT);
return request;
}
}
use of com.intellij.diff.requests.SimpleDiffRequest in project intellij-community by JetBrains.
the class MigrateToNewDiffUtil method convertRequestFair.
@Nullable
private static DiffRequest convertRequestFair(@NotNull com.intellij.openapi.diff.DiffRequest oldRequest) {
if (oldRequest.getOnOkRunnable() != null)
return null;
//if (oldRequest.getBottomComponent() != null) return null; // TODO: we need EDT to make this check. Let's ignore bottom component.
// TODO: migrate layers
com.intellij.openapi.diff.DiffContent[] contents = oldRequest.getContents();
String[] titles = oldRequest.getContentTitles();
List<DiffContent> newContents = new ArrayList<>(contents.length);
for (int i = 0; i < contents.length; i++) {
DiffContent convertedContent = convertContent(oldRequest.getProject(), contents[i]);
if (convertedContent == null)
return null;
newContents.add(convertedContent);
}
SimpleDiffRequest newRequest = new SimpleDiffRequest(oldRequest.getWindowTitle(), newContents, Arrays.asList(titles));
DiffNavigationContext navigationContext = (DiffNavigationContext) oldRequest.getGenericData().get(DiffTool.SCROLL_TO_LINE.getName());
if (navigationContext != null) {
newRequest.putUserData(DiffUserDataKeysEx.NAVIGATION_CONTEXT, navigationContext);
}
return newRequest;
}
use of com.intellij.diff.requests.SimpleDiffRequest in project intellij-community by JetBrains.
the class TestDiffRequestProcessor method loadRequest.
@NotNull
private DiffRequest loadRequest() {
if (myIndex < 0 || myIndex >= myRequests.size())
return NoDiffRequest.INSTANCE;
DiffHyperlink hyperlink = myRequests.get(myIndex);
try {
String windowTitle = hyperlink.getDiffTitle();
String text1 = hyperlink.getLeft();
String text2 = hyperlink.getRight();
VirtualFile file1 = findFile(hyperlink.getFilePath());
VirtualFile file2 = findFile(hyperlink.getActualFilePath());
DiffContent content1 = createContentWithTitle(getProject(), text1, file1, file2);
DiffContent content2 = createContentWithTitle(getProject(), text2, file2, file1);
String title1 = getContentTitle("diff.content.expected.title", file1);
String title2 = getContentTitle("diff.content.actual.title", file2);
return new SimpleDiffRequest(windowTitle, content1, content2, title1, title2);
} catch (Exception e) {
return new ErrorDiffRequest(e);
}
}
use of com.intellij.diff.requests.SimpleDiffRequest in project intellij-community by JetBrains.
the class VcsSelectionHistoryDialog method updateDiff.
private void updateDiff() {
if (myIsDisposed || myIsDuringUpdate)
return;
if (myList.getSelectedRowCount() == 0) {
myDiffPanel.setRequest(NoDiffRequest.INSTANCE);
return;
}
int count = myRevisions.size();
IntPair range = getSelectedRevisionsRange();
int revIndex1 = range.val2;
int revIndex2 = range.val1;
if (revIndex1 == count && revIndex2 == count) {
myDiffPanel.setRequest(NoDiffRequest.INSTANCE);
return;
}
BlockData blockData = myBlockLoader.getLoadedData();
DiffContent content1 = createDiffContent(revIndex1, blockData);
DiffContent content2 = createDiffContent(revIndex2, blockData);
String title1 = createDiffContentTitle(revIndex1);
String title2 = createDiffContentTitle(revIndex2);
if (content1 != null && content2 != null) {
myDiffPanel.setRequest(new SimpleDiffRequest(null, content1, content2, title1, title2), new IntPair(revIndex1, revIndex2));
return;
}
if (blockData.isLoading()) {
myDiffPanel.setRequest(new LoadingDiffRequest());
} else {
myDiffPanel.setRequest(new MessageDiffRequest(canNoLoadMessage(blockData.getException())));
}
}
use of com.intellij.diff.requests.SimpleDiffRequest 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());
}
Aggregations