IDEA-361647 Spring Structure for application.properties: collapse/expand all action

GitOrigin-RevId: 4424075431cdf7841b7aa23a3f1a90ffeecacd9c
This commit is contained in:
Anton Kozub
2025-06-26 18:03:16 +00:00
committed by intellij-monorepo-bot
parent 3bbc30089e
commit 4ff2864629
3 changed files with 68 additions and 3 deletions
@@ -54,7 +54,6 @@ import com.intellij.ui.content.ContentManagerEvent.ContentOperation
import com.intellij.ui.content.ContentManagerListener
import com.intellij.ui.switcher.QuickActionProvider
import com.intellij.util.PlatformUtils
import com.intellij.util.cancelOnDispose
import com.intellij.util.concurrency.AppExecutorUtil
import com.intellij.util.messages.Topic
import com.intellij.util.ui.JBUI
@@ -552,6 +551,11 @@ class StructureViewWrapperImpl(
}
}
@ApiStatus.Internal
fun getStructureView(): StructureView? {
return myStructureView
}
private suspend fun updateHeaderActions(structureView: StructureView?) {
myActionGroup.removeAll()
val titleActions: List<AnAction> = if (structureView is StructureViewComponent) {
@@ -422,8 +422,9 @@ public class StructureViewComponent extends SimpleToolWindowPanel implements Tre
public final @NotNull List<AnAction> addExpandCollapseActions() {
List<AnAction> result = new ArrayList<>();
CommonActionsManager commonActionManager = CommonActionsManager.getInstance();
result.add(commonActionManager.createExpandAllHeaderAction(getTree()));
result.add(commonActionManager.createCollapseAllHeaderAction(getTree()));
var expander = new StructureViewExpander(myProject);
result.add(commonActionManager.createExpandAllHeaderAction(expander, getTree()));
result.add(commonActionManager.createCollapseAllHeaderAction(expander, getTree()));
return result;
}
@@ -0,0 +1,60 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.structureView.newStructureView
import com.intellij.ide.TreeExpander
import com.intellij.ide.impl.StructureViewWrapperImpl
import com.intellij.ide.structureView.StructureViewFactory
import com.intellij.ide.structureView.StructureViewFactoryEx
import com.intellij.ide.structureView.impl.StructureViewComposite
import com.intellij.ide.structureView.logical.ExternalElementsProvider
import com.intellij.ide.structureView.logical.LogicalStructureElementsProvider
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiTarget
import com.intellij.util.ui.tree.TreeUtil
import javax.swing.JTree
internal class StructureViewExpander(val project: Project): TreeExpander {
override fun canCollapse(): Boolean {
return getActualTree() != null
}
override fun canExpand(): Boolean {
return getActualTree() != null
}
override fun collapseAll() {
val tree = getActualTree() ?: return
TreeUtil.collapseAll(tree, true, 1)
}
override fun expandAll() {
val tree = getActualTree() ?: return
val rootFile = (StructureViewComponent.unwrapValue(tree.model.root) as? PsiElement)?.containingFile?.virtualFile
TreeUtil.promiseExpand(tree, Int.Companion.MAX_VALUE) { path ->
val pathObject = StructureViewComponent.unwrapValue(path.lastPathComponent)
when (pathObject) {
is LogicalStructureElementsProvider<*, *> -> pathObject !is ExternalElementsProvider<*, *>
is PsiElement -> rootFile == null || pathObject.containingFile?.virtualFile == rootFile
is PsiTarget if rootFile != null && pathObject.isValid -> pathObject.navigationElement.containingFile?.virtualFile == rootFile
else -> true
}
}
}
private fun getActualTree(): JTree? {
val wrapper = (StructureViewFactory.getInstance(project) as? StructureViewFactoryEx)
?.structureViewWrapper as? StructureViewWrapperImpl ?: return null
val structureView = wrapper.getStructureView() ?: return null
if (structureView is StructureViewComponent) return structureView.tree
if (structureView is StructureViewComposite) {
for (descriptor in structureView.structureViews) {
val oneOfViews = descriptor.structureView as? StructureViewComponent ?: continue
val tree = oneOfViews.tree
if (tree.isShowing) return tree
}
}
return null
}
}