[branchPopup]: show git current branch with other branches

* (IDEA-171718) Not possible make current (checked out) branch favorite
This commit is contained in:
Nadya Zabrodina
2017-06-05 19:49:53 +03:00
parent 9dce175c95
commit f4fec35664
2 changed files with 46 additions and 16 deletions
@@ -122,11 +122,19 @@ class GitBranchPopup extends DvcsBranchPopup<GitRepository> {
popupGroup.addAll(createRepositoriesActions());
popupGroup.addSeparator("Common Local Branches");
List<BranchActionGroup> localBranchActions =
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, true);
List<BranchActionGroup> localBranchActions = myMultiRootBranchConfig.getLocalBranchNames().stream()
.map(l -> createLocalBranchActions(allRepositories, l))
.filter(Objects::nonNull)
.sorted(FAVORITE_BRANCH_COMPARATOR)
.collect(toList());
int topShownBranches = getNumOfTopShownBranches(localBranchActions);
String currentBranch = myMultiRootBranchConfig.getCurrentBranch();
if (currentBranch != null) {
localBranchActions
.add(0, new GitBranchPopupActions.CurrentBranchActions(myProject, allRepositories, currentBranch, myCurrentRepository));
topShownBranches++;
}
wrapWithMoreActionIfNeeded(myProject, popupGroup, localBranchActions, topShownBranches, SHOW_ALL_LOCALS_KEY, true);
popupGroup.addSeparator("Common Remote Branches");
List<BranchActionGroup> remoteBranchActions = map(((GitMultiRootBranchConfig)myMultiRootBranchConfig).getRemoteBranches(),
@@ -27,6 +27,7 @@ import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.util.containers.ContainerUtil;
import git4idea.GitLocalBranch;
import git4idea.branch.GitBranchUtil;
import git4idea.branch.GitBrancher;
import git4idea.branch.GitNewBranchOptions;
@@ -74,15 +75,21 @@ class GitBranchPopupActions {
}
popupGroup.addSeparator("Local Branches" + repoInfo);
List<BranchActionGroup> localBranchActions =
myRepository.getBranches().getLocalBranches().stream()
.sorted()
.filter(branch -> !branch.equals(myRepository.getCurrentBranch()))
.map(branch -> new LocalBranchActions(myProject, repositoryList, branch.getName(), myRepository))
.collect(toList());
GitLocalBranch currentBranch = myRepository.getCurrentBranch();
List<BranchActionGroup> localBranchActions = myRepository.getBranches().getLocalBranches().stream()
.sorted()
.filter(branch -> !branch.equals(currentBranch))
.map(branch -> new LocalBranchActions(myProject, repositoryList, branch.getName(), myRepository))
.sorted(FAVORITE_BRANCH_COMPARATOR)
.collect(toList());
int topShownBranches = getNumOfTopShownBranches(localBranchActions);
if (currentBranch != null) {
localBranchActions.add(0, new CurrentBranchActions(myProject, repositoryList, currentBranch.getName(), myRepository));
topShownBranches++;
}
// 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,
wrapWithMoreActionIfNeeded(myProject, popupGroup, localBranchActions,
topShownBranches, firstLevelGroup ? GitBranchPopup.SHOW_ALL_LOCALS_KEY : null,
firstLevelGroup);
popupGroup.addSeparator("Remote Branches" + repoInfo);
@@ -160,9 +167,9 @@ class GitBranchPopupActions {
*/
static class LocalBranchActions extends BranchActionGroup implements PopupElementWithAdditionalInfo {
private final Project myProject;
private final List<GitRepository> myRepositories;
private final String myBranchName;
protected final Project myProject;
protected final List<GitRepository> myRepositories;
protected final String myBranchName;
@NotNull private final GitRepository mySelectedRepository;
private final GitBranchManager myGitBranchManager;
@@ -310,6 +317,21 @@ class GitBranchPopupActions {
}
}
static class CurrentBranchActions extends LocalBranchActions {
CurrentBranchActions(@NotNull Project project,
@NotNull List<GitRepository> repositories,
@NotNull String branchName,
@NotNull GitRepository selectedRepository) {
super(project, repositories, branchName, selectedRepository);
}
@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
return new AnAction[]{new LocalBranchActions.RenameBranchAction(myProject, myRepositories, myBranchName)};
}
}
/**
* Actions available for remote branches
*/