diff --git a/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/popup/GitBranchesPopup.kt b/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/popup/GitBranchesPopup.kt index 9e5f4bfeb636..6743c3edc4d7 100644 --- a/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/popup/GitBranchesPopup.kt +++ b/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/popup/GitBranchesPopup.kt @@ -13,7 +13,7 @@ import org.jetbrains.concurrency.Promise interface GitBranchesPopup: TreePopup { val userResized: Boolean - var groupByPrefix: Boolean + var groupByDirectory: Boolean fun restoreDefaultSize() diff --git a/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/popup/GitBranchesPopupBase.kt b/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/popup/GitBranchesPopupBase.kt index 03d616e9d26d..22fda24a0d9c 100644 --- a/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/popup/GitBranchesPopupBase.kt +++ b/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/popup/GitBranchesPopupBase.kt @@ -136,10 +136,10 @@ abstract class GitBranchesPopupBase( final override var userResized: Boolean private set - final override var groupByPrefix: Boolean - get() = treeStep.treeModel.isPrefixGrouping + final override var groupByDirectory: Boolean + get() = treeStep.treeModel.isDirectoryGrouping set(value) { - treeStep.treeModel.isPrefixGrouping = value + treeStep.treeModel.isDirectoryGrouping = value } private val expandedPaths = HashSet() diff --git a/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/popup/GitBranchesPopupStepBase.kt b/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/popup/GitBranchesPopupStepBase.kt index 32e3da3c2f96..2cb3dbee3c97 100644 --- a/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/popup/GitBranchesPopupStepBase.kt +++ b/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/popup/GitBranchesPopupStepBase.kt @@ -109,8 +109,8 @@ abstract class GitBranchesPopupStepBase( } is GitBranchesTreeModel.BranchesPrefixGroup -> value.prefix.last() is GitBranchesTreeModel.RefTypeUnderRepository -> value.type.getText() - is RefUnderRepository -> getRefText(value.ref, treeModel.isPrefixGrouping) - is GitReference -> getRefText(value, treeModel.isPrefixGrouping) + is RefUnderRepository -> getRefText(value.ref, treeModel.isDirectoryGrouping) + is GitReference -> getRefText(value, treeModel.isDirectoryGrouping) is PopupFactoryImpl.ActionItem -> value.text is GitBranchesTreeModel.PresentableNode -> value.presentableText else -> null diff --git a/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeModel.kt b/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeModel.kt index c3ddaad1c5e8..b9c02614efaa 100644 --- a/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeModel.kt +++ b/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeModel.kt @@ -39,7 +39,7 @@ abstract class GitBranchesTreeModel( protected var nameMatcher: MinusculeMatcher? = null private set - var isPrefixGrouping: Boolean by observable(GitVcsSettings.getInstance(project).branchSettings.isGroupingEnabled(GROUPING_BY_DIRECTORY)) { _, oldValue, newValue -> + var isDirectoryGrouping: Boolean by observable(GitVcsSettings.getInstance(project).branchSettings.isGroupingEnabled(GROUPING_BY_DIRECTORY)) { _, oldValue, newValue -> if (oldValue != newValue) { applyFilterAndRebuild(null) } @@ -63,13 +63,18 @@ abstract class GitBranchesTreeModel( val recentBranches = getRecentBranches() actionsTree = LazyActionsHolder(project, actions, matcher) localBranchesTree = LazyRefsSubtreeHolder( - localBranches, - matcher, - ::isPrefixGrouping, - { recentBranches?.contains(it) ?: false }, - refComparatorGetter = ::getRefComparator + unsortedRefs = localBranches, + matcher = matcher, + isDirectoryGrouping = ::isDirectoryGrouping, + exceptRefFilter = { recentBranches?.contains(it) ?: false }, + refComparatorGetter = ::getRefComparator, + ) + remoteBranchesTree = LazyRefsSubtreeHolder( + unsortedRefs = remoteBranches, + matcher = matcher, + isDirectoryGrouping = ::isDirectoryGrouping, + refComparatorGetter = ::getRefComparator, ) - remoteBranchesTree = LazyRefsSubtreeHolder(remoteBranches, matcher, ::isPrefixGrouping, refComparatorGetter = ::getRefComparator) rebuildTags(matcher) } @@ -119,9 +124,17 @@ abstract class GitBranchesTreeModel( private fun rebuildTags(matcher: MinusculeMatcher?) { tagsTree = - if (GitVcsSettings.getInstance(project).showTags()) - LazyRefsSubtreeHolder(getTags(), matcher, ::isPrefixGrouping, refComparatorGetter = ::getRefComparator) - else LazyRefsSubtreeHolder.emptyHolder() + if (GitVcsSettings.getInstance(project).showTags()) { + LazyRefsSubtreeHolder( + unsortedRefs = getTags(), + matcher = matcher, + isDirectoryGrouping = ::isDirectoryGrouping, + refComparatorGetter = ::getRefComparator, + ) + } + else { + LazyRefsSubtreeHolder.emptyHolder() + } } protected fun getRefComparator(affectedRepositories: List = repositories): Comparator { @@ -130,7 +143,7 @@ abstract class GitBranchesTreeModel( } then compareBy { !it.isFavoriteInAll(affectedRepositories) } then compareBy { - !(isPrefixGrouping && it.name.contains('/')) + !(isDirectoryGrouping && it.name.contains('/')) } then compareBy(GitReference.REFS_NAMES_COMPARATOR) { it.name } } diff --git a/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeModelUtil.kt b/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeModelUtil.kt index 699c7b276c1c..bb08ac038a92 100644 --- a/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeModelUtil.kt +++ b/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeModelUtil.kt @@ -89,7 +89,7 @@ fun createTreePathFor(model: GitBranchesTreeModel, value: Any): TreePath? { add(refType) } } - val nameParts = if (model.isPrefixGrouping) reference.name.split('/') else listOf(reference.name) + val nameParts = if (model.isDirectoryGrouping) reference.name.split('/') else listOf(reference.name) val currentPrefix = mutableListOf() for (prefixPart in nameParts.init()) { currentPrefix.add(prefixPart) @@ -238,7 +238,7 @@ open class LazyHolder(nodes: List, class LazyRefsSubtreeHolder( unsortedRefs: Collection, matcher: MinusculeMatcher?, - isPrefixGrouping: () -> Boolean, + isDirectoryGrouping: () -> Boolean, exceptRefFilter: (T) -> Boolean = { false }, refComparatorGetter: () -> Comparator, ) { @@ -255,7 +255,7 @@ class LazyRefsSubtreeHolder( val tree: Map by lazy { val infoList = matchingResult.matchedNodes TelemetryManager.getInstance().getTracer(VcsScope).spanBuilder(GitBranchesPopupSpan.BuildingTree.getName()).use { span -> - buildSubTree(infoList.map { (if (isPrefixGrouping()) it.name.split('/') else listOf(it.name)) to it }) + buildSubTree(infoList.map { (if (isDirectoryGrouping()) it.name.split('/') else listOf(it.name)) to it }) } } diff --git a/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeMultiRepoFilteringModel.kt b/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeMultiRepoFilteringModel.kt index 5521f8f06c08..91c342837f19 100644 --- a/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeMultiRepoFilteringModel.kt +++ b/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeMultiRepoFilteringModel.kt @@ -152,24 +152,24 @@ internal class GitBranchesTreeMultiRepoFilteringModel( private inner class LazyRepositoryBranchesSubtreeHolder(private val repository: GitRepositoryModel) { val localBranches by lazy { LazyRefsSubtreeHolder( - repository.state.localBranchesOrCurrent, - nameMatcher, - ::isPrefixGrouping, + unsortedRefs = repository.state.localBranchesOrCurrent, + matcher = nameMatcher, + isDirectoryGrouping = ::isDirectoryGrouping, refComparatorGetter = { getRefComparator(listOf(repository)) }) } val remoteBranches by lazy { LazyRefsSubtreeHolder( - repository.state.remoteBranches, - nameMatcher, - ::isPrefixGrouping, + unsortedRefs = repository.state.remoteBranches, + matcher = nameMatcher, + isDirectoryGrouping = ::isDirectoryGrouping, refComparatorGetter = { getRefComparator(listOf(repository)) }) } val tags by lazy { LazyRefsSubtreeHolder( - repository.state.tags, - nameMatcher, - ::isPrefixGrouping, + unsortedRefs = repository.state.tags, + matcher = nameMatcher, + isDirectoryGrouping = ::isDirectoryGrouping, refComparatorGetter = { getRefComparator(listOf(repository)) }) } } diff --git a/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeSingleRepoModel.kt b/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeSingleRepoModel.kt index 3b42e3fd3cbb..cc4be02ad4c8 100644 --- a/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeSingleRepoModel.kt +++ b/plugins/git4idea/shared/src/com/intellij/vcs/git/branch/tree/GitBranchesTreeSingleRepoModel.kt @@ -25,9 +25,11 @@ open class GitBranchesTreeSingleRepoModel( override fun rebuild(matcher: MinusculeMatcher?) { super.rebuild(matcher) val recentCheckoutBranches = getRecentBranches() - recentCheckoutBranchesTree = LazyRefsSubtreeHolder(recentCheckoutBranches, matcher, - ::isPrefixGrouping, - refComparatorGetter = ::emptyBranchComparator) + recentCheckoutBranchesTree = LazyRefsSubtreeHolder( + unsortedRefs = recentCheckoutBranches, matcher = matcher, + isDirectoryGrouping = ::isDirectoryGrouping, + refComparatorGetter = ::emptyBranchComparator, + ) } override fun getLocalBranches(): Collection = repository.state.localBranchesOrCurrent