From a0e53a68ea5dd62fd4bb8b6e3eaf3a88fda55b8c Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 7 Jun 2017 12:57:12 +0300 Subject: [PATCH] Make the Update Project notification more compact Display the total number of files in the notification title, display the number of files under the scope in the content. title + 1 content line make the whole notification text visible without expanding. Follow-up to 4116cc3 IDEA-172015 --- .../update/AbstractCommonUpdateAction.java | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/AbstractCommonUpdateAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/AbstractCommonUpdateAction.java index 7abbdb034a57..446c538bdbc1 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/AbstractCommonUpdateAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/AbstractCommonUpdateAction.java @@ -50,10 +50,12 @@ import com.intellij.vcsUtil.VcsUtil; import gnu.trove.THashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.util.*; +import static com.intellij.openapi.util.text.StringUtil.notNullize; import static com.intellij.openapi.util.text.StringUtil.pluralize; import static com.intellij.openapi.vcs.VcsNotifier.STANDARD_NOTIFICATION; import static com.intellij.util.ObjectUtils.notNull; @@ -417,8 +419,29 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction { } @NotNull - private String prepareNotificationWithUpdateInfo(@NotNull UpdateInfoTree tree) { - String scopeText = ""; + private Notification prepareNotification(@NotNull UpdateInfoTree tree, boolean someSessionWasCancelled) { + int allFiles = tree.getFilesCount(false); + + String title; + String content; + NotificationType type; + if (someSessionWasCancelled) { + title = "Project Partially Updated"; + content = allFiles + " " + pluralize("file", allFiles) + " updated"; + type = NotificationType.WARNING; + } + else { + title = allFiles + " Project " + pluralize("File", allFiles) + " Updated"; + content = notNullize(prepareScopeUpdatedText(tree)); + type = NotificationType.INFORMATION; + } + + return STANDARD_NOTIFICATION.createNotification(title, content, type, null); + } + + @Nullable + private String prepareScopeUpdatedText(@NotNull UpdateInfoTree tree) { + String scopeText = null; NamedScope scopeFilter = tree.getFilterScope(); if (scopeFilter != null) { int filteredFiles = tree.getFilesCount(true); @@ -427,13 +450,10 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction { scopeText = filterName + " wasn't modified"; } else { - scopeText = "In " + filterName + ": " + filteredFiles + " " + pluralize("file", filteredFiles) + " modified"; + scopeText = filteredFiles + " in " + filterName; } - scopeText += "
In all scopes: "; } - - int allFiles = tree.getFilesCount(false); - return scopeText + allFiles + " " + pluralize("file", allFiles) + " modified"; + return scopeText; } @Override @@ -522,18 +542,7 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction { final CommittedChangesCache cache = CommittedChangesCache.getInstance(myProject); cache.processUpdatedFiles(myUpdatedFiles, incomingChangeLists -> tree.setChangeLists(incomingChangeLists)); - NotificationType type; - String title; - if (someSessionWasCancelled) { - title = "Project Partially Updated"; - type = NotificationType.WARNING; - } - else { - title = "Project Updated"; - type = NotificationType.INFORMATION; - } - - Notification notification = STANDARD_NOTIFICATION.createNotification(title, prepareNotificationWithUpdateInfo(tree), type, null); + Notification notification = prepareNotification(tree, someSessionWasCancelled); notification.addAction(new ViewUpdateInfoNotification(myProject, tree, "View")); VcsNotifier.getInstance(myProject).notify(notification); } @@ -553,6 +562,7 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction { }, null, myProject); } + private void showContextInterruptedError() { gatherContextInterruptedMessages(); AbstractVcsHelper.getInstance(myProject).showErrors(myGroupedExceptions,