[vcs]: Branch Popup - show all git local branches by default for 1 level

* add default expand value as a more parameter;
* for the second level popup - use collapsed state as a default for all;
This commit is contained in:
Nadya Zabrodina
2017-02-13 17:18:23 +03:00
parent e24d26211e
commit 82ec776d1a
3 changed files with 16 additions and 6 deletions
@@ -388,18 +388,21 @@ public class BranchActionGroupPopup extends FlatSpeedSearchPopup {
@NotNull private final Project myProject;
@Nullable private final String mySettingName;
private final boolean myDefaultExpandValue;
private boolean myIsExpanded;
@NotNull private final String myToCollapseText;
@NotNull private final String myToExpandText;
public MoreAction(@NotNull Project project, int numberOfHiddenNodes, @Nullable String settingName) {
public MoreAction(@NotNull Project project, int numberOfHiddenNodes, @Nullable String settingName, boolean defaultExpandValue) {
super();
myProject = project;
mySettingName = settingName;
myDefaultExpandValue = defaultExpandValue;
assert numberOfHiddenNodes > 0;
myToExpandText = "Show " + numberOfHiddenNodes + " More...";
myToCollapseText = "Show Only Favorites";
setExpanded(settingName != null && PropertiesComponent.getInstance(project).getBoolean(settingName, false));
setExpanded(
settingName != null ? PropertiesComponent.getInstance(project).getBoolean(settingName, defaultExpandValue) : defaultExpandValue);
}
@Override
@@ -430,7 +433,7 @@ public class BranchActionGroupPopup extends FlatSpeedSearchPopup {
public void saveState() {
if (mySettingName != null) {
PropertiesComponent.getInstance(myProject).setValue(mySettingName, myIsExpanded);
PropertiesComponent.getInstance(myProject).setValue(mySettingName, myIsExpanded, myDefaultExpandValue);
}
}
}
@@ -456,8 +459,14 @@ public class BranchActionGroupPopup extends FlatSpeedSearchPopup {
public static void wrapWithMoreActionIfNeeded(@NotNull Project project,
@NotNull DefaultActionGroup parentGroup, @NotNull List<? extends ActionGroup> actionList,
int maxIndex, @Nullable String settingName) {
wrapWithMoreActionIfNeeded(project, parentGroup, actionList, maxIndex, settingName, false);
}
public static void wrapWithMoreActionIfNeeded(@NotNull Project project,
@NotNull DefaultActionGroup parentGroup, @NotNull List<? extends ActionGroup> actionList,
int maxIndex, @Nullable String settingName, boolean defaultExpandValue) {
if (actionList.size() > maxIndex) {
MoreAction moreAction = new MoreAction(project, actionList.size() - maxIndex, settingName);
MoreAction moreAction = new MoreAction(project, actionList.size() - maxIndex, settingName, defaultExpandValue);
for (int i = 0; i < actionList.size(); i++) {
parentGroup.add(i < maxIndex ? actionList.get(i) : new HideableActionGroup(actionList.get(i), moreAction));
}
@@ -124,7 +124,7 @@ class GitBranchPopup extends DvcsBranchPopup<GitRepository> {
myMultiRootBranchConfig.getLocalBranchNames().stream().map(l -> createLocalBranchActions(allRepositories, l)).filter(Objects::nonNull)
.collect(toList());
wrapWithMoreActionIfNeeded(myProject, popupGroup, ContainerUtil.sorted(localBranchActions, FAVORITE_BRANCH_COMPARATOR),
getNumOfTopShownBranches(localBranchActions), SHOW_ALL_LOCALS_KEY);
getNumOfTopShownBranches(localBranchActions), SHOW_ALL_LOCALS_KEY, true);
popupGroup.addSeparator("Common Remote Branches");
List<BranchActionGroup> remoteBranchActions = map(((GitMultiRootBranchConfig)myMultiRootBranchConfig).getRemoteBranches(),
@@ -78,7 +78,8 @@ class GitBranchPopupActions {
.collect(toList());
// if there are only a few local favorites -> show all; for remotes it's better to show only favorites;
wrapWithMoreActionIfNeeded(myProject, popupGroup, ContainerUtil.sorted(localBranchActions, FAVORITE_BRANCH_COMPARATOR),
getNumOfTopShownBranches(localBranchActions), firstLevelGroup ? GitBranchPopup.SHOW_ALL_LOCALS_KEY : null);
getNumOfTopShownBranches(localBranchActions), firstLevelGroup ? GitBranchPopup.SHOW_ALL_LOCALS_KEY : null,
firstLevelGroup);
popupGroup.addSeparator("Remote Branches" + repoInfo);
List<BranchActionGroup> remoteBranchActions =