Skip to content

Commit c0e6980

Browse files
committed
chore: reduce boilerplate
1 parent 9eb7a97 commit c0e6980

23 files changed

Lines changed: 193 additions & 252 deletions

src/main/kotlin/com/github/xepozz/php_dump/CompositeWindowFactory.kt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.github.xepozz.php_dump
33
import com.github.xepozz.php_dump.panel.OpcacheSettingsPanel
44
import com.github.xepozz.php_dump.panel.OpcodesTerminalPanel
55
import com.github.xepozz.php_dump.panel.TokenTreePanel
6-
import com.github.xepozz.php_dump.panel.TokensObjectTerminalPanel
76
import com.github.xepozz.php_dump.panel.TokensTerminalPanel
87
import com.intellij.openapi.project.DumbAware
98
import com.intellij.openapi.project.Project
@@ -19,43 +18,34 @@ open class CompositeWindowFactory : ToolWindowFactory, DumbAware {
1918
val opcodesTerminalLayout = OpcodesTerminalPanel(project)
2019
val opcodesSettingsLayout = OpcacheSettingsPanel(project)
2120
val tokensTerminalLayout = TokensTerminalPanel(project)
22-
val tokensObjectTerminalLayout = TokensObjectTerminalPanel(project)
2321
val tokenTreeLayout = TokenTreePanel(project)
2422

2523
contentFactory.apply {
26-
this.createContent(opcodesTerminalLayout, "OpCodes", false).apply {
24+
this.createContent(opcodesTerminalLayout, "Opcodes", false).apply {
2725
contentManager.addContent(
2826
this.apply {
2927
this.isPinnable = true
3028
this.isCloseable = false
3129
}
3230
)
3331
}
34-
this.createContent(opcodesSettingsLayout, "OpCache Settings", false).apply {
32+
this.createContent(opcodesSettingsLayout, "Opcache", false).apply {
3533
contentManager.addContent(
3634
this.apply {
3735
this.isPinnable = true
3836
this.isCloseable = false
3937
}
4038
)
4139
}
42-
this.createContent(tokensTerminalLayout, "Tokens", false).apply {
40+
this.createContent(tokensTerminalLayout, "Plain Tokens", false).apply {
4341
contentManager.addContent(
4442
this.apply {
4543
this.isPinnable = true
4644
this.isCloseable = false
4745
}
4846
)
4947
}
50-
this.createContent(tokensObjectTerminalLayout, "Tokens Object", false).apply {
51-
contentManager.addContent(
52-
this.apply {
53-
this.isPinnable = true
54-
this.isCloseable = false
55-
}
56-
)
57-
}
58-
this.createContent(tokenTreeLayout.component, "Tree panel", false).apply {
48+
this.createContent(tokenTreeLayout.component, "Tokens Tree", false).apply {
5949
contentManager.addContent(
6050
this.apply {
6151
this.isPinnable = true

src/main/kotlin/com/github/xepozz/php_dump/PhpDumpIcons.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ object PhpDumpIcons {
1111
val RERUN_AUTOMATICALLY = IconLoader.getIcon("/icons/rerunAutomatically/rerunAutomatically.svg", PhpDumpIcons::class.java)
1212
@JvmStatic
1313
val RESTART_STOP = IconLoader.getIcon("/icons/restartStop/restartStop.svg", PhpDumpIcons::class.java)
14+
@JvmStatic
15+
val SHOW_AS_TREE = IconLoader.getIcon("/icons/showAsTree/showAsTree.svg", PhpDumpIcons::class.java)
16+
@JvmStatic
17+
val TEXT = IconLoader.getIcon("/icons/text/text.svg", PhpDumpIcons::class.java)
1418
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.github.xepozz.php_dump.actions
2+
3+
import com.intellij.execution.ui.ConsoleView
4+
import com.intellij.icons.AllIcons
5+
import com.intellij.openapi.actionSystem.AnAction
6+
import com.intellij.openapi.actionSystem.AnActionEvent
7+
8+
class ClearConsoleViewAction(val consoleView: ConsoleView) : AnAction("Clear", "Clear console", AllIcons.Actions.GC) {
9+
override fun actionPerformed(e: AnActionEvent) {
10+
consoleView.clear()
11+
}
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.github.xepozz.php_dump.actions
2+
3+
import com.intellij.icons.AllIcons
4+
import com.intellij.openapi.actionSystem.AnAction
5+
import com.intellij.openapi.actionSystem.AnActionEvent
6+
import com.intellij.util.ui.tree.TreeUtil
7+
import javax.swing.JTree
8+
9+
class CollapseTreeAction(private val tree: JTree) :
10+
AnAction("Collapse All", "Collapse all", AllIcons.Actions.Collapseall) {
11+
override fun actionPerformed(event: AnActionEvent) {
12+
TreeUtil.collapseAll(tree, 2)
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.github.xepozz.php_dump.actions
2+
3+
import com.intellij.icons.AllIcons
4+
import com.intellij.openapi.actionSystem.AnAction
5+
import com.intellij.openapi.actionSystem.AnActionEvent
6+
import com.intellij.util.ui.tree.TreeUtil
7+
import javax.swing.JTree
8+
9+
class ExpandTreeAction(private val tree: JTree) :
10+
AnAction("Expand All", "Expand all", AllIcons.Actions.Expandall) {
11+
override fun actionPerformed(event: AnActionEvent) {
12+
TreeUtil.expandAll(tree)
13+
}
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.github.xepozz.php_dump.actions
2+
3+
import com.intellij.icons.AllIcons
4+
import com.intellij.openapi.actionSystem.AnAction
5+
import com.intellij.openapi.actionSystem.AnActionEvent
6+
7+
class RefreshAction(private val callback: () -> Unit) :
8+
AnAction("Refresh", "Refresh", AllIcons.Actions.Refresh) {
9+
override fun actionPerformed(event: AnActionEvent) {
10+
callback()
11+
}
12+
}

src/main/kotlin/com/github/xepozz/php_dump/services/PhpCommandExecutor.kt renamed to src/main/kotlin/com/github/xepozz/php_dump/command/PhpCommandExecutor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.xepozz.php_dump.services
1+
package com.github.xepozz.php_dump.command
22

33
import com.intellij.execution.configurations.GeneralCommandLine
44
import com.intellij.execution.process.KillableColoredProcessHandler
@@ -39,7 +39,7 @@ object PhpCommandExecutor {
3939
val command = GeneralCommandLine(commandArgs)
4040
command.withRedirectErrorStream(false)
4141

42-
println("running command ${command.commandLineString}")
42+
// println("running command ${command.commandLineString}")
4343
val processHandler = KillableColoredProcessHandler.Silent(command)
4444
processHandler.setShouldKillProcessSoftly(false)
4545
processHandler.setShouldDestroyProcessRecursively(true)

src/main/kotlin/com/github/xepozz/php_dump/services/DebugLevelState.kt renamed to src/main/kotlin/com/github/xepozz/php_dump/configuration/PhpDumpSettingsService.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.xepozz.php_dump.services
1+
package com.github.xepozz.php_dump.configuration
22

33
import com.intellij.openapi.components.BaseState
44
import com.intellij.openapi.components.Service
@@ -9,23 +9,26 @@ import com.intellij.openapi.project.Project
99

1010
@Service(Service.Level.PROJECT)
1111
@State(
12-
name = "com.github.xepozz.php_dump.services.DebugLevelState",
12+
name = "com.github.xepozz.php_dump.services.PhpDumpSettingsService",
1313
storages = [Storage("PhpDump.xml")]
1414
)
15-
class DebugLevelState : SimplePersistentStateComponent<DebugLevelState.State>(State()) {
15+
class PhpDumpSettingsService : SimplePersistentStateComponent<PhpDumpSettingsService.State>(State()) {
1616
class State : BaseState() {
1717
var debugLevel: Int by property(1)
1818
var preloadFile: String? by string(null)
1919
var autoRefresh: Boolean by property(true)
20+
var tokensObject: Boolean by property(true)
2021
}
2122

2223
var debugLevel: Int by state::debugLevel
2324
var preloadFile: String? by state::preloadFile
2425
var autoRefresh: Boolean by state::autoRefresh
2526

27+
var tokensObject: Boolean by state::autoRefresh
28+
2629
companion object {
27-
fun getInstance(project: Project): DebugLevelState {
28-
return project.getService(DebugLevelState::class.java)
30+
fun getInstance(project: Project): PhpDumpSettingsService {
31+
return project.getService(PhpDumpSettingsService::class.java)
2932
}
3033
}
3134
}

src/main/kotlin/com/github/xepozz/php_dump/panel/OpcacheSettingsPanel.kt

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.github.xepozz.php_dump.panel
22

3-
import com.github.xepozz.php_dump.actions.RunDumpTokensCommandAction
3+
import com.github.xepozz.php_dump.actions.CollapseTreeAction
4+
import com.github.xepozz.php_dump.actions.ExpandTreeAction
5+
import com.github.xepozz.php_dump.actions.RefreshAction
46
import com.github.xepozz.php_dump.nonBlocking
57
import com.github.xepozz.php_dump.services.OpcacheSettingsTreeDumperService
68
import com.github.xepozz.php_dump.stubs.any_tree.AnyNodeList
@@ -23,8 +25,8 @@ import com.intellij.ui.tree.StructureTreeModel
2325
import com.intellij.ui.treeStructure.Tree
2426
import com.intellij.util.ui.tree.TreeUtil
2527
import kotlinx.coroutines.runBlocking
26-
import org.jdesktop.swingx.VerticalLayout
2728
import java.awt.BorderLayout
29+
import java.awt.GridLayout
2830
import javax.swing.JPanel
2931
import javax.swing.JProgressBar
3032
import javax.swing.SwingUtilities
@@ -64,33 +66,25 @@ class OpcacheSettingsPanel(private val project: Project) :
6466

6567
fun createToolbar() {
6668
val actionGroup = DefaultActionGroup().apply {
67-
add(RunDumpTokensCommandAction(service, "Dump Tree"))
69+
add(RefreshAction { refreshData() })
6870
addSeparator()
71+
add(ExpandTreeAction(tree))
72+
add(CollapseTreeAction(tree))
6973
}
7074

71-
val actionToolbar = ActionManager.getInstance().createActionToolbar("Tree Toolbar", actionGroup, false)
75+
val actionToolbar = ActionManager.getInstance().createActionToolbar("Opcache Toolbar", actionGroup, false)
7276
actionToolbar.targetComponent = this
7377

74-
val toolBarPanel = JPanel(VerticalLayout()).apply {
75-
add(
76-
JPanel(VerticalLayout()).apply {
77-
add(createRefreshButton { refreshData() })
78-
add(createExpandsAll(tree))
79-
add(createCollapseAll(tree))
80-
}
81-
)
82-
83-
add(actionToolbar.component)
84-
}
85-
// searchTextField.addDocumentListener(this)
78+
val toolBarPanel = JPanel(GridLayout())
79+
toolBarPanel.add(actionToolbar.component)
8680

8781
toolbar = toolBarPanel
8882
}
8983

9084
private fun createContent() {
9185
val responsivePanel = JPanel(BorderLayout())
9286
responsivePanel.add(progressBar, BorderLayout.NORTH)
93-
responsivePanel.add(JBScrollPane(tree))
87+
responsivePanel.add(JBScrollPane(tree), BorderLayout.CENTER)
9488

9589
setContent(responsivePanel)
9690
}

src/main/kotlin/com/github/xepozz/php_dump/panel/OpcodesTerminalPanel.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.github.xepozz.php_dump.panel
22

33
import com.github.xepozz.php_dump.PhpDumpIcons
4+
import com.github.xepozz.php_dump.actions.ClearConsoleViewAction
45
import com.github.xepozz.php_dump.actions.RunDumpTokensCommandAction
5-
import com.github.xepozz.php_dump.services.DebugLevelState
6+
import com.github.xepozz.php_dump.configuration.PhpDumpSettingsService
67
import com.github.xepozz.php_dump.services.OpcodesDumperService
78
import com.intellij.execution.filters.TextConsoleBuilderFactory
89
import com.intellij.icons.AllIcons
10+
import com.intellij.openapi.Disposable
911
import com.intellij.openapi.actionSystem.ActionManager
1012
import com.intellij.openapi.actionSystem.AnAction
1113
import com.intellij.openapi.actionSystem.AnActionEvent
@@ -26,10 +28,10 @@ import javax.swing.JPanel
2628

2729
class OpcodesTerminalPanel(
2830
val project: Project,
29-
) : SimpleToolWindowPanel(false, false), RefreshablePanel {
31+
) : SimpleToolWindowPanel(false, false), RefreshablePanel, Disposable {
3032
val viewComponent: JComponent
3133
val service: OpcodesDumperService
32-
val state = DebugLevelState.getInstance(project)
34+
val state = PhpDumpSettingsService.getInstance(project)
3335
val consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(project).console
3436

3537
init {
@@ -45,11 +47,7 @@ class OpcodesTerminalPanel(
4547
private fun createToolBar() {
4648
val actionGroup = DefaultActionGroup().apply {
4749
add(RunDumpTokensCommandAction(service, "Dump Opcodes"))
48-
add(object : AnAction("Clear", "Clear console", AllIcons.Actions.GC) {
49-
override fun actionPerformed(e: AnActionEvent) {
50-
consoleView.clear()
51-
}
52-
})
50+
add(ClearConsoleViewAction(consoleView))
5351
add(object : AnAction(
5452
"Enable Auto Refresh", "Turns on or off auto refresh of panel context",
5553
if (state.autoRefresh) PhpDumpIcons.RESTART_STOP else PhpDumpIcons.RERUN_AUTOMATICALLY
@@ -148,4 +146,8 @@ class OpcodesTerminalPanel(
148146

149147
runBlocking { service.dump(virtualFile) }
150148
}
149+
150+
override fun dispose() {
151+
}
151152
}
153+

0 commit comments

Comments
 (0)