Search in sources :

Example 1 with DiffRequestFactory

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UIUtil(com.intellij.util.ui.UIUtil) InvalidDiffRequestException(com.intellij.diff.InvalidDiffRequestException) MergeUtil(com.intellij.diff.merge.MergeUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) DiffManager(com.intellij.diff.DiffManager) ColumnInfo(com.intellij.util.ui.ColumnInfo) TableCellRenderer(javax.swing.table.TableCellRenderer) JBLabel(com.intellij.ui.components.JBLabel) SmartList(com.intellij.util.SmartList) DiffUtil(com.intellij.diff.util.DiffUtil) VcsDirtyScopeManager(com.intellij.openapi.vcs.changes.VcsDirtyScopeManager) SpeedSearchUtil(com.intellij.ui.speedSearch.SpeedSearchUtil) Messages(com.intellij.openapi.ui.Messages) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) VcsException(com.intellij.openapi.vcs.VcsException) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) ListSelectionEvent(javax.swing.event.ListSelectionEvent) VirtualFilePresentation(com.intellij.ide.presentation.VirtualFilePresentation) TableView(com.intellij.ui.table.TableView) MergeRequest(com.intellij.diff.merge.MergeRequest) DoubleClickListener(com.intellij.ui.DoubleClickListener) MergeVersion(com.intellij.openapi.diff.impl.mergeTool.MergeVersion) Nullable(org.jetbrains.annotations.Nullable) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) DiffRequestFactory(com.intellij.diff.DiffRequestFactory) Ref(com.intellij.openapi.util.Ref) Consumer(com.intellij.util.Consumer) java.util(java.util) ActionListener(java.awt.event.ActionListener) ColoredTableCellRenderer(com.intellij.ui.ColoredTableCellRenderer) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) CommonBundle(com.intellij.CommonBundle) Project(com.intellij.openapi.project.Project) ListTableModel(com.intellij.util.ui.ListTableModel) TableSpeedSearch(com.intellij.ui.TableSpeedSearch) StringUtil(com.intellij.openapi.util.text.StringUtil) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) Convertor(com.intellij.util.containers.Convertor) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) VcsBundle(com.intellij.openapi.vcs.VcsBundle) MergeResult(com.intellij.diff.merge.MergeResult) CommandProcessor(com.intellij.openapi.command.CommandProcessor) ListSelectionListener(javax.swing.event.ListSelectionListener) javax.swing(javax.swing) DiffRequestFactory(com.intellij.diff.DiffRequestFactory) InvalidDiffRequestException(com.intellij.diff.InvalidDiffRequestException) MergeResult(com.intellij.diff.merge.MergeResult) Document(com.intellij.openapi.editor.Document) MergeRequest(com.intellij.diff.merge.MergeRequest) VcsException(com.intellij.openapi.vcs.VcsException)

Example 2 with DiffRequestFactory

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"));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) MergeRequest(com.intellij.diff.merge.MergeRequest) DiffRequestFactory(com.intellij.diff.DiffRequestFactory) InvalidDiffRequestException(com.intellij.diff.InvalidDiffRequestException)

Aggregations

DiffRequestFactory (com.intellij.diff.DiffRequestFactory)2 InvalidDiffRequestException (com.intellij.diff.InvalidDiffRequestException)2 MergeRequest (com.intellij.diff.merge.MergeRequest)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 CommonBundle (com.intellij.CommonBundle)1 DiffManager (com.intellij.diff.DiffManager)1 MergeResult (com.intellij.diff.merge.MergeResult)1 MergeUtil (com.intellij.diff.merge.MergeUtil)1 DiffUtil (com.intellij.diff.util.DiffUtil)1 VirtualFilePresentation (com.intellij.ide.presentation.VirtualFilePresentation)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 CommandProcessor (com.intellij.openapi.command.CommandProcessor)1 Logger (com.intellij.openapi.diagnostic.Logger)1 MergeVersion (com.intellij.openapi.diff.impl.mergeTool.MergeVersion)1 Document (com.intellij.openapi.editor.Document)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 ProjectManagerEx (com.intellij.openapi.project.ex.ProjectManagerEx)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1