From 4116cc338b2ca00c28ba4b08cd3507731404d78a Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Sun, 4 Jun 2017 13:39:50 +0300 Subject: [PATCH] Improve Update Project notification: oneline & with filter info Mention just the whole number of affected files, no matter whether they were added, modified or deleted. This information is not critical in this place and, if needed, can be achieved from the update project tree. This makes the notification oneline: IDEA-172375 If there is a scope filter, calculate the number of files under this filter, to let user know if he needs to view updated files at all: IDEA-172015. --- .../update/AbstractCommonUpdateAction.java | 39 +++++++++---------- .../openapi/vcs/update/FileTreeNode.java | 5 ++- .../openapi/vcs/update/UpdateInfoTree.java | 31 +++++++++++++-- 3 files changed, 50 insertions(+), 25 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 ea54a74e9994..7abbdb034a57 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 @@ -41,6 +41,7 @@ import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.psi.search.scope.packageSet.NamedScope; import com.intellij.util.WaitForProgressToShow; import com.intellij.util.containers.MultiMap; import com.intellij.util.ui.OptionsDialog; @@ -54,7 +55,6 @@ import java.io.File; import java.util.*; import static com.intellij.openapi.util.text.StringUtil.pluralize; -import static com.intellij.openapi.util.text.StringUtil.toLowerCase; import static com.intellij.openapi.vcs.VcsNotifier.STANDARD_NOTIFICATION; import static com.intellij.util.ObjectUtils.notNull; @@ -416,25 +416,24 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction { }); } - private String prepareNotificationWithUpdateInfo() { - StringBuffer text = new StringBuffer(); - final List groups = myUpdatedFiles.getTopLevelGroups(); - for (FileGroup group : groups) { - appendGroup(text, group); - } - return text.toString(); - } - - private void appendGroup(final StringBuffer text, final FileGroup group) { - final int s = group.getFiles().size(); - if (s > 0) { - text.append(s).append(" ").append(pluralize("File", s)).append(" ").append(toLowerCase(group.getUpdateName())).append("
"); + @NotNull + private String prepareNotificationWithUpdateInfo(@NotNull UpdateInfoTree tree) { + String scopeText = ""; + NamedScope scopeFilter = tree.getFilterScope(); + if (scopeFilter != null) { + int filteredFiles = tree.getFilesCount(true); + String filterName = scopeFilter.getName(); + if (filteredFiles == 0) { + scopeText = filterName + " wasn't modified"; + } + else { + scopeText = "In " + filterName + ": " + filteredFiles + " " + pluralize("file", filteredFiles) + " modified"; + } + scopeText += "
In all scopes: "; } - final List list = group.getChildren(); - for (FileGroup g : list) { - appendGroup(text, g); - } + int allFiles = tree.getFilesCount(false); + return scopeText + allFiles + " " + pluralize("file", allFiles) + " modified"; } @Override @@ -533,8 +532,8 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction { title = "Project Updated"; type = NotificationType.INFORMATION; } - - Notification notification = STANDARD_NOTIFICATION.createNotification(title, prepareNotificationWithUpdateInfo(), type, null); + + Notification notification = STANDARD_NOTIFICATION.createNotification(title, prepareNotificationWithUpdateInfo(tree), type, null); notification.addAction(new ViewUpdateInfoNotification(myProject, tree, "View")); VcsNotifier.getInstance(myProject).notify(notification); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/FileTreeNode.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/FileTreeNode.java index 90634ef70d16..98b4aabc00ee 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/FileTreeNode.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/FileTreeNode.java @@ -25,6 +25,7 @@ import com.intellij.psi.search.scope.packageSet.PackageSetBase; import com.intellij.ui.SimpleTextAttributes; import com.intellij.util.PlatformIcons; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.io.File; @@ -55,14 +56,14 @@ public class FileTreeNode extends FileOrDirectoryTreeNode { } @Override - protected boolean acceptFilter(Pair filter, boolean showOnlyFilteredItems) { + protected boolean acceptFilter(@Nullable Pair filter, boolean showOnlyFilteredItems) { try { VirtualFilePointer filePointer = getFilePointer(); if (!filePointer.isValid()) { return false; } VirtualFile file = filePointer.getFile(); - if (file != null && file.isValid() && filter.first.contains(file, getProject(), filter.second)) { + if (file != null && file.isValid() && filter != null && filter.first.contains(file, getProject(), filter.second)) { applyFilter(true); return true; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateInfoTree.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateInfoTree.java index d9a376af61a4..5d00679731b2 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateInfoTree.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateInfoTree.java @@ -114,7 +114,7 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton { myProject = project; myUpdatedFiles = updatedFiles; myRootName = rootName; - + myShowOnlyFilteredItems = VcsConfiguration.getInstance(myProject).UPDATE_FILTER_BY_SCOPE; myFileStatusManager = FileStatusManager.getInstance(myProject); @@ -358,6 +358,20 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton { return result.toArray(new File[result.size()]); } + int getFilesCount(boolean filtered) { + Pair scopeFilter = getScopeFilter(); + int[] result = new int[1]; + TreeUtil.traverse(myRoot, node -> { + if (node instanceof FileTreeNode) { + if (!filtered || ((FileTreeNode)node).acceptFilter(scopeFilter, true)) { + result[0]++; + } + } + return true; + }); + return result[0]; + } + public void expandRootChildren() { TreeNode root = (TreeNode)myTreeModel.getRoot(); @@ -449,7 +463,7 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton { @Nullable private Pair getScopeFilter() { - String scopeName = VcsConfiguration.getInstance(myProject).UPDATE_FILTER_SCOPE_NAME; + String scopeName = getFilterScopeName(); if (scopeName != null) { for (NamedScopesHolder holder : NamedScopesHolder.getAllNamedScopeHolders(myProject)) { NamedScope scope = holder.getScope(scopeName); @@ -464,6 +478,17 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton { return null; } + @Nullable + private String getFilterScopeName() { + return VcsConfiguration.getInstance(myProject).UPDATE_FILTER_SCOPE_NAME; + } + + @Nullable + NamedScope getFilterScope() { + Pair filter = getScopeFilter(); + return filter == null ? null : filter.second.getScope(getFilterScopeName()); + } + private class FilterAction extends ToggleAction implements DumbAware { public FilterAction() { super("Scope Filter", VcsBundle.getString("settings.filter.update.project.info.by.scope"), AllIcons.General.Filter); @@ -483,7 +508,7 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton { public void update(AnActionEvent e) { super.update(e); - e.getPresentation().setEnabled(!myGroupByChangeList && VcsConfiguration.getInstance(myProject).UPDATE_FILTER_SCOPE_NAME != null); + e.getPresentation().setEnabled(!myGroupByChangeList && getFilterScopeName() != null); } }