use of com.intellij.diff.DiffRequestFactory in project intellij-community by JetBrains.
the class MultipleFileMergeDialog method showMergeDialog.
private void showMergeDialog() {
DiffRequestFactory requestFactory = DiffRequestFactory.getInstance();
Collection<VirtualFile> files = myTable.getSelection();
if (!beforeResolve(files)) {
return;
}
for (final VirtualFile file : files) {
final MergeData mergeData;
try {
mergeData = myProvider.loadRevisions(file);
} catch (VcsException ex) {
Messages.showErrorDialog(myRootPanel, "Error loading revisions to merge: " + ex.getMessage());
break;
}
if (mergeData.CURRENT == null || mergeData.LAST == null || mergeData.ORIGINAL == null) {
Messages.showErrorDialog(myRootPanel, "Error loading revisions to merge");
break;
}
String leftTitle = myMergeDialogCustomizer.getLeftPanelTitle(file);
String baseTitle = myMergeDialogCustomizer.getCenterPanelTitle(file);
String rightTitle = myMergeDialogCustomizer.getRightPanelTitle(file, mergeData.LAST_REVISION_NUMBER);
String title = myMergeDialogCustomizer.getMergeWindowTitle(file);
final List<byte[]> byteContents = ContainerUtil.list(mergeData.CURRENT, mergeData.ORIGINAL, mergeData.LAST);
List<String> contentTitles = ContainerUtil.list(leftTitle, baseTitle, rightTitle);
Consumer<MergeResult> callback = result -> {
Document document = FileDocumentManager.getInstance().getCachedDocument(file);
if (document != null)
FileDocumentManager.getInstance().saveDocument(document);
checkMarkModifiedProject(file);
if (result != MergeResult.CANCEL) {
ApplicationManager.getApplication().runWriteAction(() -> {
markFileProcessed(file, getSessionResolution(result));
});
}
};
MergeRequest request;
try {
if (myProvider.isBinary(file)) {
// respect MIME-types in svn
request = requestFactory.createBinaryMergeRequest(myProject, file, byteContents, title, contentTitles, callback);
} else {
request = requestFactory.createMergeRequest(myProject, file, byteContents, title, contentTitles, callback);
}
MergeUtil.putRevisionInfos(request, mergeData);
} catch (InvalidDiffRequestException e) {
LOG.error(e);
Messages.showErrorDialog(myRootPanel, "Can't show merge dialog");
break;
}
DiffManager.getInstance().showMerge(myProject, request);
}
updateModelFromFiles();
}
use of com.intellij.diff.DiffRequestFactory in project intellij-community by JetBrains.
the class MergeFilesAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
DataContext context = e.getDataContext();
VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context);
if (files == null || files.length != 3) {
return;
}
DiffRequestFactory diffRequestFactory = DiffRequestFactory.getInstance();
try {
Project project = CommonDataKeys.PROJECT.getData(context);
String title = DiffBundle.message("merge.files.dialog.title");
List<String> titles = ContainerUtil.list(files[0].getPresentableUrl(), files[1].getPresentableUrl(), files[2].getPresentableUrl());
VirtualFile outputFile = files[1];
List<VirtualFile> contents = ContainerUtil.list(files[0], files[1], files[2]);
MergeRequest request = diffRequestFactory.createMergeRequestFromFiles(project, outputFile, contents, title, titles, null);
request.putUserData(DiffUserDataKeys.HELP_ID, "cvs.merge");
DiffManager.getInstance().showMerge(project, request);
} catch (InvalidDiffRequestException err) {
Messages.showErrorDialog(err.getLocalizedMessage(), DiffBundle.message("merge.files.dialog.title"));
}
}
Aggregations