mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: IDEA-151547: display commit result in notification instead of modal error
Unify reporting errors/warnings & number of committed files into a single notification.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<Object> DOCUMENT_BEING_COMMITTED_KEY = new Key<Object>("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<Change> changesFailedToCommit = processor.getChangesFailedToCommit();
|
||||
private void reportResult(@NotNull GeneralCommitProcessor processor) {
|
||||
List<VcsException> 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("<br/>");
|
||||
content.append(StringUtil.join(myFeedback, "<br/>"));
|
||||
}
|
||||
List<VcsException> exceptions = processor.getVcsExceptions();
|
||||
if (!doesntContainErrors(exceptions)) {
|
||||
content.append("<br/>");
|
||||
content.append(StringUtil.join(exceptions, new Function<VcsException, String>() {
|
||||
@Override
|
||||
public String fun(VcsException e) {
|
||||
return e.getMessage();
|
||||
}
|
||||
}, "<br/>"));
|
||||
}
|
||||
return content.toString();
|
||||
}
|
||||
|
||||
return hasExceptions ? (hasOnlyWarnings ? NotificationType.WARNING : NotificationType.ERROR) : NotificationType.INFORMATION;
|
||||
@NotNull
|
||||
private String getFileSummaryReport(@NotNull List<Change> 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<VcsException> 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<VcsException, String>() {
|
||||
@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<Change> failedChanges,
|
||||
|
||||
Reference in New Issue
Block a user