Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrections for the build and work with ignore plugin, distinct fold for ignored files #23

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ tasks {
gradleVersion = properties("gradleVersion")
}

withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "11"
}
}

patchPluginXml {
version.set(properties("pluginVersion"))
sinceBuild.set(properties("pluginSinceBuild"))
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = ski.chrzanow.foldableprojectview
pluginName = Foldable ProjectView
pluginRepositoryUrl = https://github.com/hsz/intellij-foldable-projectview
# SemVer format -> https://semver.org
pluginVersion = 1.1.4
pluginVersion = 1.1.5-snapshot

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 221
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ class FoldableProjectViewNode(
project: Project,
settings: ViewSettings?,
private val children: Set<AbstractTreeNode<*>>,
) : ProjectViewNode<String>(project, FoldableProjectViewBundle.message("foldableProjectView.name"), settings) {
private val foldName: String,
private val textAttributes: SimpleTextAttributes,
) : ProjectViewNode<String>(project, FoldableProjectViewBundle.message("foldableProjectView.name") + foldName, settings) {

override fun update(presentation: PresentationData) {
presentation.apply {
val text = FoldableProjectViewBundle.message("foldableProjectView.node", children.size)
val text = FoldableProjectViewBundle.message("foldableProjectView.node", foldName, children.size)
val toolTip = children.mapNotNull { it.name }.joinToString(", ")
val textAttributes = SimpleTextAttributes.GRAY_SMALL_ATTRIBUTES
addText(ColoredFragment(text, toolTip, textAttributes))
setIcon(CollapseComponent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode
import com.intellij.ide.projectView.impl.nodes.PsiFileNode
import com.intellij.ide.util.treeView.AbstractTreeNode
import com.intellij.openapi.components.service
import com.intellij.openapi.module.ModuleUtil
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessModuleDir
import com.intellij.openapi.vcs.FileStatus
import com.intellij.openapi.vcs.FileStatusListener
import com.intellij.openapi.vcs.FileStatusManager
import com.intellij.openapi.vcs.changes.ignore.cache.PatternCache
import com.intellij.openapi.vcs.changes.ignore.lang.Syntax
import com.intellij.ui.SimpleTextAttributes
import ski.chrzanow.foldableprojectview.FoldableProjectViewBundle
import ski.chrzanow.foldableprojectview.settings.FoldableProjectSettings
import ski.chrzanow.foldableprojectview.settings.FoldableProjectSettingsListener
import ski.chrzanow.foldableprojectview.settings.FoldableProjectState
Expand All @@ -27,6 +27,7 @@ class FoldableTreeStructureProvider(project: Project) : TreeStructureProvider {
private var previewState: FoldableProjectState? = null
private val projectView = ProjectView.getInstance(project)
private val state get() = previewState ?: settings
private val ignoredStatuses = listOf(FileStatus.IGNORED.id, "IGNORE.PROJECT_VIEW.IGNORED")

init {
project.messageBus
Expand Down Expand Up @@ -56,12 +57,31 @@ class FoldableTreeStructureProvider(project: Project) : TreeStructureProvider {
return when {
!state.foldingEnabled -> children
parent !is PsiDirectoryNode -> children
!isModule(parent, project) -> children
else -> children.match().toSet().let { matched ->
else -> children.match().run {
val matchedByPattern = first.toSet()
val matchedByIgnore = second.toSet()

when {
state.hideAllGroups -> children - matched
state.hideEmptyGroups && matched.isEmpty() -> children
else -> children - matched + FoldableProjectViewNode(project, viewSettings, matched)
state.hideAllGroups -> children - matchedByPattern - matchedByIgnore
else -> {
children -= matchedByPattern
if (matchedByPattern.isNotEmpty() || !state.hideEmptyGroups) children += FoldableProjectViewNode(
project,
viewSettings,
matchedByPattern,
FoldableProjectViewBundle.message("foldableProjectView.node.byPattern"),
SimpleTextAttributes.REGULAR_ATTRIBUTES
)
children -= matchedByIgnore
if (matchedByIgnore.isNotEmpty()) children += FoldableProjectViewNode(
project,
viewSettings,
matchedByIgnore,
FoldableProjectViewBundle.message("foldableProjectView.node.byIgnored"),
SimpleTextAttributes.GRAY_SMALL_ATTRIBUTES
)
children
}
}
}
}
Expand All @@ -71,29 +91,32 @@ class FoldableTreeStructureProvider(project: Project) : TreeStructureProvider {
previewState = state
}

private fun isModule(node: PsiDirectoryNode, project: Project) = node.virtualFile?.let {
ModuleUtil.findModuleForFile(it, project)?.guessModuleDir() == it
} ?: false

private fun MutableCollection<AbstractTreeNode<*>>.match() = this
.filter {
when (it) {
is PsiDirectoryNode -> state.foldDirectories
is PsiFileNode -> true
else -> false
private fun MutableCollection<AbstractTreeNode<*>>.match() =
this
.filter {
when (it) {
is PsiDirectoryNode -> state.foldDirectories
is PsiFileNode -> true
else -> false
}
}.partition {
when (it) {
is ProjectViewNode -> it.virtualFile?.name ?: it.name
else -> it.name
}.caseInsensitive().let { name ->
state.patterns
.caseInsensitive()
.split(' ')
.any { pattern ->
patternCache?.createPattern(pattern, Syntax.GLOB)?.matcher(name)?.matches() ?: false
}
}
}.apply {
return Pair(
first,
second.filter { state.foldIgnoredFiles && (it.fileStatus.id in ignoredStatuses) }.toMutableList()
)
}
}
.filter {
when (it) {
is ProjectViewNode -> it.virtualFile?.name ?: it.name
else -> it.name
}.caseInsensitive().let { name ->
state.patterns
.caseInsensitive()
.split(' ')
.any { pattern -> patternCache?.createPattern(pattern, Syntax.GLOB)?.matcher(name)?.matches() ?: false }
}.or(state.foldIgnoredFiles and(it.fileStatus.equals(FileStatus.IGNORED)))
}

private fun String?.caseInsensitive() = when {
this == null -> ""
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/messages/FoldableProjectView.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
foldableProjectView.name=Foldable ProjectView
foldableProjectView.node=Folded files: {0}
foldableProjectView.node=[{0}: {1}]
foldableProjectView.node.byPattern=folded by pattern
foldableProjectView.node.byIgnored=ignored
foldableProjectView.settings.foldingEnabled=Enable folding
foldableProjectView.settings.foldingEnabled.comment=Fold matching root elements of the project modules in the Project View.
foldableProjectView.settings.foldDirectories=Fold directories
Expand Down