IDEA-79331 GitUIUtil.notify - wrapper method for notifications: uses title in place of description if the latter is empty.

This commit is contained in:
Kirill Likhodedov
2011-12-27 21:23:18 +03:00
parent 3a2cadd785
commit cef77fc4c0
2 changed files with 17 additions and 9 deletions
@@ -29,6 +29,7 @@ import git4idea.actions.BasicAction;
import git4idea.commands.GitCommandResult;
import git4idea.i18n.GitBundle;
import git4idea.jgit.GitHttpAdapter;
import git4idea.ui.GitUIUtil;
import git4idea.update.GitFetchResult;
import git4idea.update.GitFetcher;
import org.jetbrains.annotations.NotNull;
@@ -119,8 +120,7 @@ public class GitCheckoutProvider implements CheckoutProvider {
if (result.success()) {
return true;
}
GitVcs.IMPORTANT_ERROR_NOTIFICATION.createNotification("Clone failed", result.getErrorOutputAsHtmlString(), NotificationType.ERROR, null)
.notify(project.isDefault() ? null : project);
GitUIUtil.notify(GitVcs.IMPORTANT_ERROR_NOTIFICATION, project, "Clone failed", result.getErrorOutputAsHtmlString(), NotificationType.ERROR, null);
return false;
}
@@ -17,6 +17,7 @@ package git4idea.ui;
import com.intellij.ide.ui.ListCellRendererWrapper;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.NotificationListener;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
@@ -56,21 +57,28 @@ public class GitUIUtil {
* A private constructor for utility class
*/
private GitUIUtil() { }
public static void notifyMessages(Project project, @Nullable String title, @Nullable String description, NotificationType type, boolean important, @Nullable Collection<String> messages) {
public static void notify(@NotNull NotificationGroup group, @NotNull Project project, @Nullable String title, @Nullable String description, @NotNull NotificationType type, @Nullable NotificationListener listener) {
// title can't be null, but can be empty; description can't be neither null, nor empty
if (title == null) {
title = "";
}
if (StringUtil.isEmptyOrSpaces(description)) {
description = title;
title = "";
}
// if both title and description were empty, then it is a problem in the calling code => let assertion notify about that.
assert description != null : "description is null after StringUtil.isEmptyOrSpaces(). title: " + title;
group.createNotification(title, description, type, listener).notify(project.isDefault() ? null : project);
}
public static void notifyMessages(Project project, @Nullable String title, @Nullable String description, NotificationType type, boolean important, @Nullable Collection<String> messages) {
String desc = (description != null ? description.replace("\n", "<br/>") : "");
if (messages != null && !messages.isEmpty()) {
desc += "<hr/>" + StringUtil.join(messages, "<br/>");
}
if (StringUtil.isEmptyOrSpaces(desc)) {
desc = StringUtil.isEmptyOrSpaces(title) ? "Error" : title; // description is not allowed to be empty, title is => moving title text to description
title = "";
}
NotificationGroup group = important ? GitVcs.IMPORTANT_ERROR_NOTIFICATION : GitVcs.NOTIFICATION_GROUP_ID;
group.createNotification(title, desc, type, null).notify(project.isDefault() ? null : project);
notify(group, project, title, desc, type, null);
}
public static void notifyMessage(Project project, @Nullable String title, @Nullable String description, NotificationType type, boolean important, @Nullable Collection<? extends Exception> errors) {