IDEA-195646 vcs: do not show modules in VCS tree if grouping by module is disabled

We no longer replace `ChangesBrowserFilePathNode` with `ChangesBrowserModuleNode`.
This also fixes node ordering regression after 6fe6d97f5a,
as TreeBuilder no longer tolerates transitivity violators.
This commit is contained in:
Aleksey Pivovarov
2019-01-09 14:43:57 +03:00
parent d8e88c31b0
commit 270b32f3c6
6 changed files with 15 additions and 69 deletions
@@ -53,7 +53,7 @@ public class ChangesBrowserModuleNode extends ChangesBrowserNode<Module> {
@Override
public int getSortWeight() {
return DIRECTORY_PATH_SORT_WEIGHT;
return MODULE_SORT_WEIGHT;
}
@Override
@@ -47,8 +47,9 @@ public class ChangesBrowserNode<T> extends DefaultMutableTreeNode implements Use
protected static final int DEFAULT_CHANGE_LIST_SORT_WEIGHT = 1;
protected static final int CHANGE_LIST_SORT_WEIGHT = 2;
protected static final int REPOSITORY_SORT_WEIGHT = 3;
protected static final int DIRECTORY_PATH_SORT_WEIGHT = 4;
protected static final int FILE_PATH_SORT_WEIGHT = 5;
protected static final int MODULE_SORT_WEIGHT = 4;
protected static final int DIRECTORY_PATH_SORT_WEIGHT = 5;
protected static final int FILE_PATH_SORT_WEIGHT = 6;
protected static final int CHANGE_SORT_WEIGHT = 7;
protected static final int VIRTUAL_FILE_SORT_WEIGHT = 8;
protected static final int UNVERSIONED_SORT_WEIGHT = 9;
@@ -2,72 +2,12 @@
package com.intellij.openapi.vcs.changes.ui
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.openapi.util.NotNullLazyKey
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.vcs.changes.ui.DirectoryChangesGroupingPolicy.Companion.DIRECTORY_POLICY
import com.intellij.openapi.vcs.changes.ui.DirectoryChangesGroupingPolicy.Companion.GRAND_PARENT_CANDIDATE
import com.intellij.openapi.vcs.changes.ui.DirectoryChangesGroupingPolicy.Companion.HIERARCHY_UPPER_BOUND
import com.intellij.openapi.vcs.changes.ui.DirectoryChangesGroupingPolicy.Companion.getCachingRoot
import com.intellij.openapi.vcs.changes.ui.TreeModelBuilder.DIRECTORY_CACHE
import com.intellij.openapi.vfs.VirtualFile
import javax.swing.tree.DefaultTreeModel
private const val PROJECT_ROOT_TAG = "<Project Root>"
@Deprecated("Use ChangesGroupingPolicyFactory instead")
open class ChangesModuleGroupingPolicy(val myProject: Project, val myModel: DefaultTreeModel) : ChangesGroupingPolicy {
private val myIndex = ProjectFileIndex.getInstance(myProject)
override fun getParentNodeFor(nodePath: StaticFilePath, subtreeRoot: ChangesBrowserNode<*>): ChangesBrowserNode<*>? {
if (myProject.isDefault) return null
val vFile = nodePath.resolve() ?: return null
val contentRoot = myIndex.getContentRootForFile(vFile, HIDE_EXCLUDED_FILES)
if (vFile == contentRoot) {
val module = myIndex.getModuleForFile(vFile, HIDE_EXCLUDED_FILES)
return getNodeForModule(module, vFile, nodePath, subtreeRoot)
}
return null
}
private fun getNodeForModule(module: Module?,
vFile: VirtualFile,
nodePath: StaticFilePath,
subtreeRoot: ChangesBrowserNode<*>): ChangesBrowserNode<*> {
val cachingRoot = getCachingRoot(subtreeRoot)
MODULE_CACHE.getValue(cachingRoot)[module]?.let { return it }
val policy = DIRECTORY_POLICY.get(subtreeRoot)
val parent = GRAND_PARENT_CANDIDATE.get(subtreeRoot)
?: if (policy != null && !isTopLevel(vFile))
policy.getParentNodeInternal(nodePath, subtreeRoot)
else
HIERARCHY_UPPER_BOUND.getRequired(subtreeRoot)
val node = if (module == null) ChangesBrowserNode.createObject(PROJECT_ROOT_TAG) else ChangesBrowserModuleNode(module)
myModel.insertNodeInto(node, parent, parent.childCount)
MODULE_CACHE.getValue(cachingRoot)[module] = node
DIRECTORY_CACHE.getValue(cachingRoot)[nodePath.key] = node
return node
}
private fun isTopLevel(vFile: VirtualFile): Boolean {
val parentFile = vFile.parent ?: return true
return myIndex.getContentRootForFile(parentFile, HIDE_EXCLUDED_FILES) == null
}
class Factory(val project: Project) : ChangesGroupingPolicyFactory() {
override fun createGroupingPolicy(model: DefaultTreeModel): ChangesGroupingPolicy = ChangesModuleGroupingPolicy(project, model)
}
companion object {
val MODULE_CACHE: NotNullLazyKey<MutableMap<Module?, ChangesBrowserNode<*>>, ChangesBrowserNode<*>> = NotNullLazyKey.create<MutableMap<Module?, ChangesBrowserNode<*>>, ChangesBrowserNode<*>>(
"ChangesTree.ModuleCache") { mutableMapOf() }
val HIDE_EXCLUDED_FILES: Boolean = Registry.`is`("ide.hide.excluded.files")
}
}
@@ -8,7 +8,7 @@ import com.intellij.openapi.vcs.changes.ui.TreeModelBuilder.PATH_NODE_BUILDER
import javax.swing.tree.DefaultTreeModel
class DirectoryChangesGroupingPolicy(val project: Project, val model: DefaultTreeModel) : BaseChangesGroupingPolicy() {
private val innerPolicy = ChangesGroupingPolicyFactory.getInstance(project)?.createGroupingPolicy(model)
private val innerPolicy: ChangesGroupingPolicy? = ChangesGroupingPolicyFactory.getInstance(project)?.createGroupingPolicy(model)
override fun getParentNodeFor(nodePath: StaticFilePath, subtreeRoot: ChangesBrowserNode<*>): ChangesBrowserNode<*> {
DIRECTORY_POLICY.set(subtreeRoot, this)
@@ -1,10 +1,11 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.vcs.changes.ui
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.openapi.vcs.changes.ui.ChangesModuleGroupingPolicy.Companion.HIDE_EXCLUDED_FILES
import com.intellij.openapi.vcs.changes.ui.ChangesModuleGroupingPolicy.Companion.MODULE_CACHE
import com.intellij.openapi.util.NotNullLazyKey
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.vcs.changes.ui.TreeModelBuilder.*
import javax.swing.tree.DefaultTreeModel
@@ -41,4 +42,10 @@ class ModuleChangesGroupingPolicy(val project: Project, val model: DefaultTreeMo
class Factory(val project: Project) : ChangesGroupingPolicyFactory() {
override fun createGroupingPolicy(model: DefaultTreeModel): ModuleChangesGroupingPolicy = ModuleChangesGroupingPolicy(project, model)
}
companion object {
private val MODULE_CACHE: NotNullLazyKey<MutableMap<Module?, ChangesBrowserNode<*>>, ChangesBrowserNode<*>> =
NotNullLazyKey.create("ChangesTree.ModuleCache") { mutableMapOf() }
private val HIDE_EXCLUDED_FILES: Boolean = Registry.`is`("ide.hide.excluded.files")
}
}
@@ -183,8 +183,6 @@
<projectService serviceInterface="com.intellij.compiler.CompilerWorkspaceConfiguration"
serviceImplementation="com.intellij.compiler.CompilerWorkspaceConfiguration"/>
<projectService serviceInterface="com.intellij.openapi.vcs.changes.ui.ChangesGroupingPolicyFactory"
serviceImplementation="com.intellij.openapi.vcs.changes.ui.ChangesModuleGroupingPolicy$Factory"/>
<changesGroupingPolicy key="module" id="module"
implementationClass="com.intellij.openapi.vcs.changes.ui.ModuleChangesGroupingPolicy$Factory"/>