mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[branchPopup]: show hg current branch/bookmark with other branches
This commit is contained in:
@@ -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<Repo extends Repository> {
|
||||
@NotNull protected final Collection<Repo> myRepositories;
|
||||
@@ -34,9 +35,14 @@ public abstract class DvcsMultiRootBranchConfig<Repo extends Repository> {
|
||||
|
||||
@Nullable
|
||||
public String getCurrentBranch() {
|
||||
return getCommonName(Repository::getCurrentBranchName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getCommonName(@NotNull Function<Repo, String> nameSupplier) {
|
||||
String commonBranch = null;
|
||||
for (Repo repository : myRepositories) {
|
||||
String branchName = repository.getCurrentBranchName();
|
||||
String branchName = nameSupplier.apply(repository);
|
||||
if (branchName == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -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<HgRepository> {
|
||||
List<HgCommonBranchActions> 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<HgCommonBranchActions> 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
|
||||
|
||||
@@ -87,13 +87,19 @@ public class HgBranchPopupActions {
|
||||
}
|
||||
|
||||
popupGroup.addSeparator("Bookmarks" + repoInfo);
|
||||
String currentBookmark = myRepository.getCurrentBookmark();
|
||||
List<HgCommonBranchActions> 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<HgRepository> 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<HgRepository> 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)};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user