diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/branch/DvcsMultiRootBranchConfig.java b/platform/dvcs-impl/src/com/intellij/dvcs/branch/DvcsMultiRootBranchConfig.java index ee24209167fa..d999bf5334c8 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/branch/DvcsMultiRootBranchConfig.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/branch/DvcsMultiRootBranchConfig.java @@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.function.Function; public abstract class DvcsMultiRootBranchConfig { @NotNull protected final Collection myRepositories; @@ -34,9 +35,14 @@ public abstract class DvcsMultiRootBranchConfig { @Nullable public String getCurrentBranch() { + return getCommonName(Repository::getCurrentBranchName); + } + + @Nullable + public String getCommonName(@NotNull Function nameSupplier) { String commonBranch = null; for (Repo repository : myRepositories) { - String branchName = repository.getCurrentBranchName(); + String branchName = nameSupplier.apply(repository); if (branchName == null) { return null; } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchPopup.java b/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchPopup.java index 67979119747b..cb9ef1f6a3e8 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchPopup.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchPopup.java @@ -26,7 +26,6 @@ import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Conditions; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.HgProjectSettings; @@ -99,16 +98,26 @@ public class HgBranchPopup extends DvcsBranchPopup { List branchActions = myMultiRootBranchConfig.getLocalBranchNames().stream() .map(b -> createLocalBranchActions(allRepositories, b, false)) - .filter(Objects::nonNull).collect(toList()); - wrapWithMoreActionIfNeeded(myProject, popupGroup, ContainerUtil.sorted(branchActions, FAVORITE_BRANCH_COMPARATOR), - getNumOfTopShownBranches(branchActions), SHOW_ALL_BRANCHES_KEY, true); + .filter(Objects::nonNull).sorted(FAVORITE_BRANCH_COMPARATOR).collect(toList()); + int topShownBranches = getNumOfTopShownBranches(branchActions); + String commonBranch = myMultiRootBranchConfig.getCommonName(HgRepository::getCurrentBranch); + if (commonBranch != null) { + branchActions.add(0, new HgBranchPopupActions.CurrentBranch(myProject, allRepositories, commonBranch)); + topShownBranches++; + } + wrapWithMoreActionIfNeeded(myProject, popupGroup, branchActions, topShownBranches, SHOW_ALL_BRANCHES_KEY, true); popupGroup.addSeparator("Common Bookmarks"); List bookmarkActions = ((HgMultiRootBranchConfig)myMultiRootBranchConfig).getBookmarkNames().stream() .map(bm -> createLocalBranchActions(allRepositories, bm, true)) - .filter(Objects::nonNull).collect(toList()); - wrapWithMoreActionIfNeeded(myProject, popupGroup, ContainerUtil.sorted(bookmarkActions, FAVORITE_BRANCH_COMPARATOR), - getNumOfTopShownBranches(bookmarkActions), SHOW_ALL_BOOKMARKS_KEY, true); + .filter(Objects::nonNull).sorted(FAVORITE_BRANCH_COMPARATOR).collect(toList()); + int topShownBookmarks = getNumOfTopShownBranches(bookmarkActions); + String commonBookmark = myMultiRootBranchConfig.getCommonName(HgRepository::getCurrentBookmark); + if (commonBookmark != null) { + bookmarkActions.add(0, new HgBranchPopupActions.CurrentActiveBookmark(myProject, allRepositories, commonBookmark)); + topShownBookmarks++; + } + wrapWithMoreActionIfNeeded(myProject, popupGroup, bookmarkActions, topShownBookmarks, SHOW_ALL_BOOKMARKS_KEY, true); } @Nullable diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchPopupActions.java b/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchPopupActions.java index b80579503082..22413177ab72 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchPopupActions.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/branch/HgBranchPopupActions.java @@ -87,13 +87,19 @@ public class HgBranchPopupActions { } popupGroup.addSeparator("Bookmarks" + repoInfo); + String currentBookmark = myRepository.getCurrentBookmark(); List bookmarkActions = getSortedNamesWithoutHashes(myRepository.getBookmarks()).stream() + .filter(bm -> !bm.equals(currentBookmark)) .map(bm -> new BookmarkActions(myProject, Collections.singletonList(myRepository), bm)) + .sorted(FAVORITE_BRANCH_COMPARATOR) .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(bookmarkActions, FAVORITE_BRANCH_COMPARATOR), - getNumOfTopShownBranches(bookmarkActions), firstLevelGroup ? HgBranchPopup.SHOW_ALL_BOOKMARKS_KEY : null, - firstLevelGroup); + int topShownBookmarks = getNumOfTopShownBranches(bookmarkActions); + if (currentBookmark != null) { + bookmarkActions.add(0, new CurrentActiveBookmark(myProject, Collections.singletonList(myRepository), currentBookmark)); + topShownBookmarks++; + } + wrapWithMoreActionIfNeeded(myProject, popupGroup, bookmarkActions, topShownBookmarks, + firstLevelGroup ? HgBranchPopup.SHOW_ALL_BOOKMARKS_KEY : null, firstLevelGroup); //only opened branches have to be shown popupGroup.addSeparator("Branches" + repoInfo); @@ -102,10 +108,11 @@ public class HgBranchPopupActions { .sorted() .filter(b -> !b.equals(myRepository.getCurrentBranch())) .map(b -> new BranchActions(myProject, Collections.singletonList(myRepository), b)) + .sorted(FAVORITE_BRANCH_COMPARATOR) .collect(toList()); - wrapWithMoreActionIfNeeded(myProject, popupGroup, ContainerUtil.sorted(branchActions, FAVORITE_BRANCH_COMPARATOR), - getNumOfTopShownBranches(branchActions), firstLevelGroup ? HgBranchPopup.SHOW_ALL_BRANCHES_KEY : null, - firstLevelGroup); + branchActions.add(0, new CurrentBranch(myProject, Collections.singletonList(myRepository), myRepository.getCurrentBranch())); + wrapWithMoreActionIfNeeded(myProject, popupGroup, branchActions, getNumOfTopShownBranches(branchActions) + 1, + firstLevelGroup ? HgBranchPopup.SHOW_ALL_BRANCHES_KEY : null, firstLevelGroup); return popupGroup; } @@ -279,6 +286,19 @@ public class HgBranchPopupActions { super(project, repositories, branchName, HgBranchType.BRANCH); } } + + public static class CurrentBranch extends BranchActions{ + + public CurrentBranch(@NotNull Project project, @NotNull List repositories, @NotNull String branchName) { + super(project, repositories, branchName); + } + + @NotNull + @Override + public AnAction[] getChildren(@Nullable AnActionEvent e) { + return AnAction.EMPTY_ARRAY; + } + } /** * Actions available for bookmarks. @@ -314,4 +334,17 @@ public class HgBranchPopupActions { } } } + + public static class CurrentActiveBookmark extends BookmarkActions{ + + public CurrentActiveBookmark(@NotNull Project project, @NotNull List repositories, @NotNull String branchName) { + super(project, repositories, branchName); + } + + @NotNull + @Override + public AnAction[] getChildren(@Nullable AnActionEvent e) { + return new AnAction[]{new BookmarkActions.DeleteBookmarkAction(myProject, myRepositories, myBranchName)}; + } + } }