From 0ea26bb8481b2c0ce861cb72d61c351ec0377a4e Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 25 Feb 2016 19:37:51 +0300 Subject: [PATCH] vcs: IDEA-151547: display commit result in notification instead of modal error Unify reporting errors/warnings & number of committed files into a single notification. --- .../com/intellij/openapi/vcs/VcsNotifier.java | 6 +- .../openapi/vcs/changes/ui/CommitHelper.java | 114 +++++++++--------- 2 files changed, 57 insertions(+), 63 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/VcsNotifier.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/VcsNotifier.java index ff2b490bf26c..edec9d48a2d1 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/VcsNotifier.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/VcsNotifier.java @@ -46,9 +46,9 @@ public class VcsNotifier { } @NotNull - private static Notification createNotification(@NotNull NotificationGroup notificationGroup, - @NotNull String title, @NotNull String message, @NotNull NotificationType type, - @Nullable NotificationListener listener) { + public static Notification createNotification(@NotNull NotificationGroup notificationGroup, + @NotNull String title, @NotNull String message, @NotNull NotificationType type, + @Nullable NotificationListener listener) { // title can be empty; message can't be neither null, nor empty if (StringUtil.isEmptyOrSpaces(message)) { message = title; diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitHelper.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitHelper.java index c8c93c86bca6..8c570d85d086 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitHelper.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitHelper.java @@ -40,7 +40,6 @@ import com.intellij.openapi.vcs.changes.actions.MoveChangesToAnotherListAction; import com.intellij.openapi.vcs.changes.committed.CommittedChangesCache; import com.intellij.openapi.vcs.checkin.CheckinEnvironment; import com.intellij.openapi.vcs.checkin.CheckinHandler; -import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier; import com.intellij.openapi.vcs.update.RefreshVFsSynchronously; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Consumer; @@ -57,6 +56,8 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; +import static com.intellij.openapi.vcs.VcsNotifier.IMPORTANT_ERROR_NOTIFICATION; + public class CommitHelper { public static final Key DOCUMENT_BEING_COMMITTED_KEY = new Key("DOCUMENT_BEING_COMMITTED"); @@ -144,15 +145,6 @@ public class CommitHelper { vcsManager.stopBackgroundVcsOperation(); } } - - @Override - public NotificationInfo notifyFinished() { - if (myCustomResultHandler == null) { - String text = reportResult(processor); - return new NotificationInfo("VCS Commit", "VCS Commit Finished", text, true); - } - return null; - } }; ProgressManager.getInstance().run(task); return false; @@ -190,31 +182,57 @@ public class CommitHelper { } } - private String reportResult(GeneralCommitProcessor processor) { - final List changesFailedToCommit = processor.getChangesFailedToCommit(); + private void reportResult(@NotNull GeneralCommitProcessor processor) { + List errors = collectErrors(processor.getVcsExceptions()); + int errorsSize = errors.size(); + int warningsSize = processor.getVcsExceptions().size() - errorsSize; - int failed = changesFailedToCommit.size(); - int committed = myIncludedChanges.size() - failed; - - String text = committed + " " + StringUtil.pluralize("file", committed) + " committed"; - if (failed > 0) { - text += ", " + failed + " " + StringUtil.pluralize("file", failed) + " failed to commit"; + String title; + NotificationType type; + if (errorsSize > 0) { + title = StringUtil.pluralize(VcsBundle.message("message.text.commit.failed.with.error"), errorsSize); + type = NotificationType.ERROR; } - StringBuilder content = new StringBuilder(StringUtil.isEmpty(myCommitMessage) ? text : text + ": " + escape(myCommitMessage)); - for (String s : myFeedback) { - content.append("\n"); - content.append(s); + else if (warningsSize > 0) { + title = StringUtil.pluralize(VcsBundle.message("message.text.commit.finished.with.warning"), warningsSize); + type = NotificationType.WARNING; } - NotificationType notificationType = resolveNotificationType(processor); - VcsBalloonProblemNotifier.NOTIFICATION_GROUP.createNotification(content.toString(), notificationType).notify(myProject); - return text; + else { + title = "Committed Successfully"; + type = NotificationType.INFORMATION; + } + VcsNotifier.createNotification(IMPORTANT_ERROR_NOTIFICATION, title, getCommitSummary(processor), type, null).notify(myProject); } - private static NotificationType resolveNotificationType(@NotNull GeneralCommitProcessor processor) { - boolean hasExceptions = !processor.getVcsExceptions().isEmpty(); - boolean hasOnlyWarnings = doesntContainErrors(processor.getVcsExceptions()); + @NotNull + private String getCommitSummary(@NotNull GeneralCommitProcessor processor) { + StringBuilder content = new StringBuilder(getFileSummaryReport(processor.getChangesFailedToCommit())); + if (!myFeedback.isEmpty()) { + content.append("
"); + content.append(StringUtil.join(myFeedback, "
")); + } + List exceptions = processor.getVcsExceptions(); + if (!doesntContainErrors(exceptions)) { + content.append("
"); + content.append(StringUtil.join(exceptions, new Function() { + @Override + public String fun(VcsException e) { + return e.getMessage(); + } + }, "
")); + } + return content.toString(); + } - return hasExceptions ? (hasOnlyWarnings ? NotificationType.WARNING : NotificationType.ERROR) : NotificationType.INFORMATION; + @NotNull + private String getFileSummaryReport(@NotNull List changesFailedToCommit) { + int failed = changesFailedToCommit.size(); + int committed = myIncludedChanges.size() - failed; + String fileSummary = committed + " " + StringUtil.pluralize("file", committed) + " committed"; + if (failed > 0) { + fileSummary += ", " + failed + " " + StringUtil.pluralize("file", failed) + " failed to commit"; + } + return fileSummary; } /* @@ -591,6 +609,10 @@ public class CommitHelper { } } + if (myCustomResultHandler == null) { + reportResult(processor); + } + if ((errorsSize == 0) && (warningsSize == 0)) { final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); if (indicator != null) { @@ -599,7 +621,9 @@ public class CommitHelper { } else { if (myCustomResultHandler == null) { - showErrorDialogAndMoveToAnotherList(processor, errorsSize, warningsSize, errors); + if (errorsSize > 0) { + processor.afterFailedCheckIn(); + } } else { myCustomResultHandler.onFailure(); @@ -607,36 +631,6 @@ public class CommitHelper { } } - private void showErrorDialogAndMoveToAnotherList(final GeneralCommitProcessor processor, final int errorsSize, final int warningsSize, - @NotNull final List errors) { - WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() { - public void run() { - String message; - if (errorsSize > 0 && warningsSize > 0) { - message = VcsBundle.message("message.text.commit.failed.with.errors.and.warnings"); - } - else if (errorsSize > 0) { - message = StringUtil.pluralize(VcsBundle.message("message.text.commit.failed.with.error"), errorsSize); - } - else { - message = StringUtil.pluralize(VcsBundle.message("message.text.commit.finished.with.warning"), warningsSize); - } - message += ":\n" + StringUtil.join(errors, new Function() { - @Override - public String fun(VcsException e) { - return e.getMessage(); - } - }, "\n"); - //new VcsBalloonProblemNotifier(myProject, message, MessageType.ERROR).run(); - Messages.showErrorDialog(message, VcsBundle.message("message.title.commit")); - - if (errorsSize > 0) { - processor.afterFailedCheckIn(); - } - } - }, null, myProject); - } - public static void moveToFailedList(final ChangeList changeList, final String commitMessage, final List failedChanges,