Search in sources :

Example 6 with CheckinHandler

use of com.intellij.openapi.vcs.checkin.CheckinHandler in project intellij-community by JetBrains.

the class CommitHelper method commitCompleted.

private void commitCompleted(final List<VcsException> allExceptions, final GeneralCommitProcessor processor) {
    final List<VcsException> errors = collectErrors(allExceptions);
    boolean noErrors = errors.isEmpty();
    boolean noWarnings = allExceptions.isEmpty();
    if (noErrors) {
        for (CheckinHandler handler : myHandlers) {
            handler.checkinSuccessful();
        }
        processor.afterSuccessfulCheckIn();
        if (myCustomResultHandler != null) {
            myCustomResultHandler.onSuccess(myCommitMessage);
        } else {
            reportResult(processor);
        }
        if (noWarnings) {
            final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
            if (indicator != null) {
                indicator.setText(VcsBundle.message("commit.dialog.completed.successfully"));
            }
        }
    } else {
        for (CheckinHandler handler : myHandlers) {
            handler.checkinFailed(errors);
        }
        processor.afterFailedCheckIn();
        if (myCustomResultHandler != null) {
            myCustomResultHandler.onFailure();
        } else {
            reportResult(processor);
        }
    }
}
Also used : DelegatingProgressIndicator(com.intellij.ide.util.DelegatingProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler)

Example 7 with CheckinHandler

use of com.intellij.openapi.vcs.checkin.CheckinHandler in project intellij-community by JetBrains.

the class UpdateCopyrightCheckinHandlerFactory method createHandler.

@NotNull
public CheckinHandler createHandler(@NotNull final CheckinProjectPanel panel, @NotNull CommitContext commitContext) {
    return new CheckinHandler() {

        @Override
        public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
            final JCheckBox updateCopyrightCb = new JCheckBox("Update copyright");
            return new RefreshableOnComponent() {

                public JComponent getComponent() {
                    return JBUI.Panels.simplePanel().addToLeft(updateCopyrightCb);
                }

                public void refresh() {
                }

                public void saveState() {
                    UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT = updateCopyrightCb.isSelected();
                }

                public void restoreState() {
                    updateCopyrightCb.setSelected(UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT);
                }
            };
        }

        @Override
        public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
            if (UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT) {
                new UpdateCopyrightProcessor(panel.getProject(), null, getPsiFiles()).run();
                FileDocumentManager.getInstance().saveAllDocuments();
            }
            return super.beforeCheckin();
        }

        private PsiFile[] getPsiFiles() {
            final Collection<VirtualFile> files = panel.getVirtualFiles();
            final List<PsiFile> psiFiles = new ArrayList<>();
            final PsiManager manager = PsiManager.getInstance(panel.getProject());
            for (final VirtualFile file : files) {
                final PsiFile psiFile = manager.findFile(file);
                if (psiFile != null) {
                    psiFiles.add(psiFile);
                }
            }
            return PsiUtilCore.toPsiFileArray(psiFiles);
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) PsiManager(com.intellij.psi.PsiManager) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) CommitExecutor(com.intellij.openapi.vcs.changes.CommitExecutor) PairConsumer(com.intellij.util.PairConsumer) RefreshableOnComponent(com.intellij.openapi.vcs.ui.RefreshableOnComponent) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CheckinHandler (com.intellij.openapi.vcs.checkin.CheckinHandler)7 NotNull (org.jetbrains.annotations.NotNull)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Project (com.intellij.openapi.project.Project)3 CommitExecutor (com.intellij.openapi.vcs.changes.CommitExecutor)3 RefreshableOnComponent (com.intellij.openapi.vcs.ui.RefreshableOnComponent)3 PairConsumer (com.intellij.util.PairConsumer)3 Nullable (org.jetbrains.annotations.Nullable)3 Disposable (com.intellij.openapi.Disposable)2 FilePath (com.intellij.openapi.vcs.FilePath)2 PsiFile (com.intellij.psi.PsiFile)2 PsiManager (com.intellij.psi.PsiManager)2 ArrayList (java.util.ArrayList)2 GoFile (com.goide.psi.GoFile)1 AdditionalOptionsPanel (com.intellij.cvsSupport2.checkinProject.AdditionalOptionsPanel)1 DelegatingProgressIndicator (com.intellij.ide.util.DelegatingProgressIndicator)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProjectLevelVcsManager (com.intellij.openapi.vcs.ProjectLevelVcsManager)1 VcsRoot (com.intellij.openapi.vcs.VcsRoot)1