Skip to content

Commit

Permalink
Use FileStatusListener to refresh ProjectView when foldIgnoredFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
hsz committed Jul 29, 2021
1 parent 2db1f7e commit e78bb06
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ 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 ski.chrzanow.foldableprojectview.settings.FoldableProjectSettings
Expand All @@ -23,18 +25,25 @@ class FoldableTreeStructureProvider(project: Project) : TreeStructureProvider {
private val settings = project.service<FoldableProjectSettings>()
private val patternCache = PatternCache.getInstance(project)
private var previewState: FoldableProjectState? = null
private val projectView = ProjectView.getInstance(project)
private val state get() = previewState ?: settings

init {
val view = ProjectView.getInstance(project)

project.messageBus
.connect(project)
.subscribe(FoldableProjectSettingsListener.TOPIC, object : FoldableProjectSettingsListener {
override fun settingsChanged(settings: FoldableProjectSettings) {
view.currentProjectViewPane?.updateFromRoot(true)
refreshProjectView()
}
})

FileStatusManager.getInstance(project).addFileStatusListener(object : FileStatusListener {
override fun fileStatusesChanged() {
if (settings.foldIgnoredFiles) {
refreshProjectView()
}
}
}, project)
}

override fun modify(
Expand All @@ -58,6 +67,10 @@ class FoldableTreeStructureProvider(project: Project) : TreeStructureProvider {
}
}

fun withState(state: FoldableProjectState) {
previewState = state
}

private fun isModule(node: PsiDirectoryNode, project: Project) = node.virtualFile?.let {
ModuleUtil.findModuleForFile(it, project)?.guessModuleDir() == it
} ?: false
Expand Down Expand Up @@ -88,7 +101,5 @@ class FoldableTreeStructureProvider(project: Project) : TreeStructureProvider {
else -> this
}

fun withState(state: FoldableProjectState) {
previewState = state
}
private fun refreshProjectView() = projectView.currentProjectViewPane?.updateFromRoot(true)
}
6 changes: 0 additions & 6 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
implementation="ski.chrzanow.foldableprojectview.projectView.FoldableTreeStructureProvider"/>
</extensions>

<projectListeners>
<listener
class="ski.chrzanow.foldableprojectview.projectView.FoldableChangeListListener"
topic="com.intellij.openapi.vcs.changes.ChangeListListener"/>
</projectListeners>

<actions>
<action id="ProjectView.FoldRootFiles"
class="ski.chrzanow.foldableprojectview.actionSystem.FoldRootFilesAction"
Expand Down

0 comments on commit e78bb06

Please sign in to comment.