1
0
mirror of https://github.com/chylex/Rider-VCS-Group-By-Project.git synced 2024-11-25 16:42:45 +01:00

Compare commits

..

No commits in common. "2493fd01f1ec82dcffef3af19f77c3fd32b9985c" and "b523fa46d8705261f284e1d28e5b3566dacebb45" have entirely different histories.

3 changed files with 3 additions and 50 deletions

View File

@ -6,7 +6,7 @@ plugins {
}
group = "com.chylex.intellij.rider.vcsgroupbyproject"
version = "1.0.1"
version = "1.0.0"
repositories {
mavenCentral()

View File

@ -8,20 +8,14 @@ import com.intellij.openapi.vcs.changes.ui.ChangesBrowserNode
import com.intellij.openapi.vcs.changes.ui.ChangesGroupingPolicyFactory
import com.intellij.openapi.vcs.changes.ui.StaticFilePath
import com.intellij.openapi.vcs.changes.ui.TreeModelBuilder
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.vcsUtil.VcsUtil
import com.intellij.workspaceModel.ide.WorkspaceModel
import com.jetbrains.rider.model.RdCustomLocation
import com.jetbrains.rider.model.RdProjectDescriptor
import com.jetbrains.rider.model.RdProjectModelItemDescriptor
import com.jetbrains.rider.model.RdUnloadProjectDescriptor
import com.jetbrains.rider.projectView.workspace.ProjectModelEntity
import com.jetbrains.rider.projectView.workspace.containingEntity
import com.jetbrains.rider.projectView.workspace.containingProjectEntity
import com.jetbrains.rider.projectView.workspace.getProjectModelEntities
import com.jetbrains.rider.projectView.workspace.isProject
import com.jetbrains.rider.projectView.workspace.isProjectFile
import com.jetbrains.rider.projectView.workspace.isProjectFolder
import com.jetbrains.rider.projectView.workspace.isUnloadedProject
import java.io.File
import javax.swing.tree.DefaultTreeModel
@ -34,7 +28,7 @@ class ProjectChangesGroupingPolicy(private val project: Project, private val mod
return nextPolicyParent
}
val descriptor = getSingleProjectEntity(file, project)?.descriptor
val descriptor = file.containingEntity(project)?.let(ProjectModelEntity::containingProjectEntity)?.descriptor
if (descriptor !is RdProjectDescriptor && descriptor !is RdUnloadProjectDescriptor) {
return nextPolicyParent
}
@ -68,41 +62,6 @@ class ProjectChangesGroupingPolicy(private val project: Project, private val mod
mutableMapOf()
}
@Suppress("UnstableApiUsage")
private fun getSingleProjectEntity(file: VirtualFile, project: Project): ProjectModelEntity? {
val workspaceModel = WorkspaceModel.getInstance(project)
val entities = walkFileParentsUntilResultIsNotEmpty(file) { workspaceModel.getProjectModelEntities(it, project) }
if (entities == null) {
return null
}
return entities
.filter(::isProjectOrProjectFile)
.map(ProjectModelEntity::containingProjectEntity)
.toSet()
.singleOrNull()
}
private inline fun <T> walkFileParentsUntilResultIsNotEmpty(leafFile: VirtualFile, getValue: (VirtualFile) -> List<T>?): List<T>? {
var file: VirtualFile? = leafFile
while (file != null) {
val value = getValue(file)
if (value.isNullOrEmpty()) {
file = file.parent
}
else {
return value
}
}
return null
}
private fun isProjectOrProjectFile(entity: ProjectModelEntity): Boolean {
return entity.isProjectFile() || entity.isProjectFolder() || entity.isProject() || entity.isUnloadedProject()
}
private fun getFolder(descriptor: RdProjectModelItemDescriptor): FilePath? {
val location = descriptor.location
if (location !is RdCustomLocation) {

View File

@ -11,12 +11,6 @@
Click the 'Group By' icon in the panel's toolbar and select 'Project' to group files by project, or both 'Project' and 'Directory' to first group by project and then by directory.
]]></description>
<change-notes><![CDATA[
<ul>
<li>Fixed grouping files belonging to multiple projects under a random project.</li>
</ul>
]]></change-notes>
<depends>com.intellij.modules.rider</depends>
<extensions defaultExtensionNs="com.intellij">