Skip to content

Commit

Permalink
feat: adds support for IDEA version 2024.2.x (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavankjadda authored Jul 14, 2024
2 parents 9b49b57 + b698ad4 commit 731802f
Show file tree
Hide file tree
Showing 20 changed files with 135 additions and 98 deletions.
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repositories {
mavenCentral()
}

// Set the JVM language level used to build the project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+.
// Set the JVM language level used to build the project. Use Java 21 for 2024.2+
kotlin {
jvmToolchain(17)
}
Expand Down Expand Up @@ -74,7 +74,7 @@ tasks {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"

with (it.lines()) {
with(it.lines()) {
if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
Expand Down Expand Up @@ -117,6 +117,7 @@ tasks {
// The pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3
// Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more:
// https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel
channels = properties("pluginVersion").map { listOf(it.split('-').getOrElse(1) { "default" }.split('.').first()) }
channels =
properties("pluginVersion").map { listOf(it.split('-').getOrElse(1) { "default" }.split('.').first()) }
}
}
10 changes: 6 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html
pluginGroup=ski.chrzanow.foldableprojectview
pluginGroup=com.pj.foldableprojectview
pluginName=Foldable Project View
pluginRepositoryUrl=https://github.com/pavankjadda/intellij-foldable-projectview
# SemVer format -> https://semver.org
pluginVersion=3.0.0
pluginVersion=4.0.0
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild=223
pluginUntilBuild=241.*
pluginSinceBuild=241
pluginUntilBuild=242.*
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType=IC
platformVersion=2023.3.3
Expand All @@ -24,3 +24,5 @@ org.gradle.configuration-cache=true
org.gradle.caching=true
# Enable Gradle Kotlin DSL Lazy Property Assignment -> https://docs.gradle.org/current/userguide/kotlin_dsl.html#kotdsl:assignment
systemProp.org.gradle.unsafe.kotlin.assignment=true
# Enable Kotlin Official Code Style -> https://kotlinlang.org/docs/coding-conventions.html
kotlin.code.style=official
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ski.chrzanow.foldableprojectview
package com.pj.foldableprojectview

import com.intellij.AbstractBundle
import org.jetbrains.annotations.NonNls
Expand All @@ -12,8 +12,7 @@ object FoldableProjectViewBundle : AbstractBundle("messages.FoldableProjectView"

@Suppress("SpreadOperator")
@JvmStatic
fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
getMessage(key, *params)
fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = getMessage(key, *params)

@Suppress("SpreadOperator")
@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.pj.foldableprojectview

object FoldableProjectViewConstants {
const val DEFAULT_RULE_NAME = "Rule name"
const val DEFAULT_RULE_PATTERN = "*.md"
const val COLOR_COLUMN_TEXT = "Aa"
const val STORAGE_FILE = "FoldableProjectView.xml"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ski.chrzanow.foldableprojectview.actionSystem
package com.pj.foldableprojectview.actionSystem

import com.intellij.ide.projectView.ProjectView
import com.intellij.openapi.actionSystem.ToggleOptionAction
import com.intellij.openapi.components.service
import com.intellij.openapi.project.DumbAware
import ski.chrzanow.foldableprojectview.settings.FoldableProjectSettings
import com.pj.foldableprojectview.settings.FoldableProjectSettings
import java.util.function.Function

class FoldIgnoredFilesAction : DumbAware, ToggleOptionAction(Function {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ski.chrzanow.foldableprojectview.actionSystem
package com.pj.foldableprojectview.actionSystem

import com.intellij.ide.projectView.ProjectView
import com.intellij.openapi.actionSystem.ToggleOptionAction
import com.intellij.openapi.components.service
import com.intellij.openapi.project.DumbAware
import ski.chrzanow.foldableprojectview.settings.FoldableProjectSettings
import com.pj.foldableprojectview.settings.FoldableProjectSettings
import java.util.function.Function

class FoldRootFilesAction : DumbAware, ToggleOptionAction(Function {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ski.chrzanow.foldableprojectview.projectView
package com.pj.foldableprojectview.projectView

import com.intellij.icons.AllIcons.General.CollapseComponent
import com.intellij.ide.projectView.PresentationData
Expand All @@ -15,17 +15,18 @@ import com.intellij.psi.PsiFileSystemItem
import com.intellij.psi.search.PsiElementProcessor
import com.intellij.ui.SimpleTextAttributes
import com.intellij.ui.SimpleTextAttributes.STYLE_PLAIN
import ski.chrzanow.foldableprojectview.psi.search.FoldableProjectSearchScope
import ski.chrzanow.foldableprojectview.settings.FoldableProjectSettings
import ski.chrzanow.foldableprojectview.settings.Rule
import com.pj.foldableprojectview.psi.search.FoldableProjectSearchScope
import com.pj.foldableprojectview.settings.FoldableProjectSettings
import com.pj.foldableprojectview.settings.Rule

class FoldableProjectViewNode(
project: Project,
private val viewSettings: ViewSettings?,
private val settings: FoldableProjectSettings,
private val rule: Rule,
private val parent: PsiDirectoryNode,
) : ProjectViewNode<String>(project, rule.name, viewSettings), PsiFileSystemItemFilter, PsiElementProcessor<PsiFileSystemItem> {
) : ProjectViewNode<String>(project, rule.name, viewSettings), PsiFileSystemItemFilter,
PsiElementProcessor<PsiFileSystemItem> {

val containsMatchedChildKey: Key<Boolean> = Key.create("FOLDABLE_PROJECT_VIEW_CONTAINS_MATCHED_CHILD")
val ruleScope = FoldableProjectSearchScope(project, rule.pattern, settings)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ski.chrzanow.foldableprojectview.projectView
package com.pj.foldableprojectview.projectView

import com.intellij.ide.projectView.ProjectView
import com.intellij.ide.projectView.ProjectViewNode
Expand All @@ -18,9 +18,9 @@ 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 ski.chrzanow.foldableprojectview.or
import ski.chrzanow.foldableprojectview.settings.FoldableProjectSettings
import ski.chrzanow.foldableprojectview.settings.FoldableProjectSettingsListener
import com.pj.foldableprojectview.or
import com.pj.foldableprojectview.settings.FoldableProjectSettings
import com.pj.foldableprojectview.settings.FoldableProjectSettingsListener

class FoldableTreeStructureProvider(private val project: Project) : TreeStructureProvider {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ski.chrzanow.foldableprojectview.psi.search
package com.pj.foldableprojectview.psi.search

import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.psi.search.SearchScope
import com.intellij.psi.search.SearchScopeProvider
import ski.chrzanow.foldableprojectview.FoldableProjectViewBundle
import ski.chrzanow.foldableprojectview.settings.FoldableProjectSettings
import com.pj.foldableprojectview.FoldableProjectViewBundle
import com.pj.foldableprojectview.settings.FoldableProjectSettings

class FoldableProjectScopesProvider : SearchScopeProvider {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ski.chrzanow.foldableprojectview.psi.search
package com.pj.foldableprojectview.psi.search

import com.intellij.openapi.components.service
import com.intellij.openapi.module.Module
Expand All @@ -8,7 +8,7 @@ import com.intellij.openapi.vcs.changes.ignore.cache.PatternCache
import com.intellij.openapi.vcs.changes.ignore.lang.Syntax
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.search.GlobalSearchScope
import ski.chrzanow.foldableprojectview.settings.FoldableProjectSettings
import com.pj.foldableprojectview.settings.FoldableProjectSettings
import kotlin.io.path.relativeToOrNull

class FoldableProjectSearchScope(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package ski.chrzanow.foldableprojectview.settings
package com.pj.foldableprojectview.settings

import com.intellij.openapi.components.*
import com.intellij.openapi.project.Project
import com.intellij.util.xmlb.annotations.OptionTag
import ski.chrzanow.foldableprojectview.FoldableProjectViewConstants
import com.pj.foldableprojectview.FoldableProjectViewConstants
import java.io.File

@Service(Service.Level.PROJECT)
@State(name = "FoldableProjectSettings", storages = [Storage(FoldableProjectViewConstants.STORAGE_FILE)])
class FoldableProjectSettings : FoldableProjectState, BaseState(), PersistentStateComponent<FoldableProjectSettings> {

@get:OptionTag("FOLDING_ENABLED")
override var foldingEnabled by property(true)

@get:OptionTag("MATCH_DIRECTORIES")
override var matchDirectories by property(true)

@get:OptionTag("HIDE_EMPTY_GROUPS")
override var hideEmptyGroups by property(true)
override var hideEmptyGroups by property(false)

@get:OptionTag("HIDE_ALL_GROUPS")
override var hideAllGroups by property(false)
Expand All @@ -29,6 +30,22 @@ class FoldableProjectSettings : FoldableProjectState, BaseState(), PersistentSta
@get:OptionTag("RULES")
override var rules by list<Rule>()

init {
val tempRules = mutableListOf<Rule>()
tempRules.add(Rule("Ignored Files", getGitIgnorePatterns().joinToString(" "), null, null))
rules = tempRules
}

private fun getGitIgnorePatterns(): List<String> {
val currentPath = System.getProperty("user.dir")
val gitIgnoreFile = File("$currentPath/.gitignore")
return if (gitIgnoreFile.exists()) {
gitIgnoreFile.readLines().filter { it.isNotBlank() && !it.startsWith("#") }
} else {
emptyList()
}
}

override fun getState() = this

override fun loadState(state: FoldableProjectSettings) = copyFrom(state)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ski.chrzanow.foldableprojectview.settings
package com.pj.foldableprojectview.settings

import com.intellij.util.messages.Topic
import java.util.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package ski.chrzanow.foldableprojectview.settings
package com.pj.foldableprojectview.settings

import com.intellij.ui.JBColor
import com.intellij.util.xmlb.Converter
import com.intellij.util.xmlb.annotations.OptionTag
import ski.chrzanow.foldableprojectview.FoldableProjectViewConstants.DEFAULT_RULE_NAME
import ski.chrzanow.foldableprojectview.FoldableProjectViewConstants.DEFAULT_RULE_PATTERN
import com.pj.foldableprojectview.FoldableProjectViewConstants.DEFAULT_RULE_NAME
import com.pj.foldableprojectview.FoldableProjectViewConstants.DEFAULT_RULE_PATTERN
import java.awt.Color

interface FoldableProjectState {

val foldingEnabled: Boolean
val matchDirectories: Boolean
val foldIgnoredFiles: Boolean
Expand All @@ -31,8 +30,6 @@ data class Rule(
)

private class ColorConverter : Converter<Color>() {

override fun toString(value: Color) = value.rgb.toString()

override fun fromString(value: String) = runCatching { JBColor.decode(value) }.getOrNull()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ski.chrzanow.foldableprojectview.settings
package com.pj.foldableprojectview.settings

import com.intellij.ide.projectView.impl.AbstractProjectTreeStructure
import com.intellij.ide.projectView.impl.ProjectViewPane
Expand All @@ -16,21 +16,21 @@ import com.intellij.ui.dsl.builder.RightGap
import com.intellij.ui.dsl.builder.panel
import com.intellij.ui.layout.not
import com.intellij.util.ui.tree.TreeUtil
import ski.chrzanow.foldableprojectview.FoldableProjectViewBundle.message
import ski.chrzanow.foldableprojectview.bindSelected
import ski.chrzanow.foldableprojectview.createPredicate
import ski.chrzanow.foldableprojectview.projectView.FoldableTreeStructureProvider
import com.pj.foldableprojectview.FoldableProjectViewBundle.message
import com.pj.foldableprojectview.bindSelected
import com.pj.foldableprojectview.createPredicate
import com.pj.foldableprojectview.projectView.FoldableTreeStructureProvider
import java.awt.Dimension
import javax.swing.BorderFactory.createEmptyBorder

class FoldableProjectViewConfigurable(project: Project) : BoundSearchableConfigurable(
helpTopic = "FoldableProjectView",
_id = "FoldableProjectView",
displayName = "FOOO", // TODO: ???
displayName = "FoldableProjectView",
), NoScroll {

companion object {
const val ID = "ski.chrzanow.foldableprojectview.options.FoldableProjectViewConfigurable"
const val ID = "com.pj.foldableprojectview.options.FoldableProjectViewConfigurable"
}

private val settings = project.service<FoldableProjectSettings>()
Expand Down Expand Up @@ -74,17 +74,23 @@ class FoldableProjectViewConfigurable(project: Project) : BoundSearchableConfigu
row {
checkBox(message("foldableProjectView.settings.matchDirectories"))
.bindSelected(settingsProperty, FoldableProjectSettings::matchDirectories)
.comment(message("foldableProjectView.settings.matchDirectories.comment"), MAX_LINE_LENGTH_WORD_WRAP)
.comment(
message("foldableProjectView.settings.matchDirectories.comment"),
MAX_LINE_LENGTH_WORD_WRAP
)
.applyToComponent { setMnemonic('d') }
}

row {
checkBox(message("foldableProjectView.settings.foldIgnoredFiles"))
.bindSelected(settingsProperty, FoldableProjectSettings::foldIgnoredFiles)
.comment(message("foldableProjectView.settings.foldIgnoredFiles.comment"), MAX_LINE_LENGTH_WORD_WRAP)
.comment(
message("foldableProjectView.settings.foldIgnoredFiles.comment"),
MAX_LINE_LENGTH_WORD_WRAP
)
.applyToComponent { setMnemonic('h') }

visible(false)
visible(true)
}

row {
Expand All @@ -101,7 +107,7 @@ class FoldableProjectViewConfigurable(project: Project) : BoundSearchableConfigu
)
.let(::cell)

visible(false)
visible(true)
}

row {
Expand All @@ -111,7 +117,7 @@ class FoldableProjectViewConfigurable(project: Project) : BoundSearchableConfigu
.applyToComponent { setMnemonic('h') }
.enabledIf(hideAllGroupsPredicate.not())

visible(false)
visible(true)
}
}.enabledIf(foldingEnabledPredicate)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ski.chrzanow.foldableprojectview.settings
package com.pj.foldableprojectview.settings

import com.intellij.openapi.observable.properties.ObservableMutableProperty
import com.intellij.openapi.observable.util.isNotNull
Expand All @@ -13,10 +13,10 @@ import com.intellij.ui.dsl.builder.Cell
import com.intellij.ui.dsl.builder.Panel
import com.intellij.ui.dsl.builder.selected
import com.intellij.ui.layout.ComponentPredicate
import ski.chrzanow.foldableprojectview.FoldableProjectViewBundle.message
import ski.chrzanow.foldableprojectview.bindColor
import ski.chrzanow.foldableprojectview.bindColorControl
import ski.chrzanow.foldableprojectview.bindText
import com.pj.foldableprojectview.FoldableProjectViewBundle.message
import com.pj.foldableprojectview.bindColor
import com.pj.foldableprojectview.bindColorControl
import com.pj.foldableprojectview.bindText

class FoldableRulesEditor(val ruleProperty: ObservableMutableProperty<Rule?>) : UiDslUnnamedConfigurable.Simple() {

Expand Down
Loading

0 comments on commit 731802f

Please sign in to comment.