1
1
package de.tschallacka.phpstormxdebugskip.settings
2
2
3
+ import com.intellij.openapi.fileChooser.FileChooser
4
+ import com.intellij.openapi.fileChooser.FileChooserDescriptor
3
5
import com.intellij.openapi.options.Configurable
4
- import javax.swing.JComponent
6
+ import com.intellij.openapi.project.Project
7
+ import com.intellij.openapi.ui.TextFieldWithBrowseButton
8
+ import com.intellij.ui.ColoredListCellRenderer
9
+ import com.intellij.ui.ToolbarDecorator
10
+ import com.intellij.ui.components.JBList
11
+ import com.jetbrains.php.config.PhpTreeClassChooserDialog
12
+ import java.awt.BorderLayout
13
+ import javax.swing.*
5
14
6
- class SettingsConfigurable : Configurable {
15
+ class SettingsConfigurable ( private val project : Project ) : Configurable {
7
16
8
- private var settingsDialog : SettingsDialog ? = null
17
+ private val settings = Settings .getInstance()
9
18
10
- override fun createComponent (): JComponent ? {
11
- settingsDialog = SettingsDialog ()
12
- return settingsDialog?.createCenterPanel()
19
+ private val modified = false
20
+
21
+ private val filePathModel = DefaultListModel <String >().apply { addAll(settings.settingsState.filepaths) }
22
+ private val namespaceModel = DefaultListModel <String >().apply { addAll(settings.settingsState.namespaces) }
23
+
24
+ private val filePathList = JBList <String >(filePathModel)
25
+ private val namespaceList = JBList <String >(namespaceModel)
26
+
27
+ override fun createComponent (): JComponent {
28
+ val panel = JPanel ()
29
+ panel.layout = BoxLayout (panel, BoxLayout .Y_AXIS )
30
+ JLabel (" Don't halt the debugger in these file paths" ).also { panel.add(it) }
31
+ // Create a decorator for file paths
32
+ val filePathDecorator = ToolbarDecorator .createDecorator(filePathList)
33
+ filePathDecorator.setAddAction { addButton ->
34
+ FileChooser .chooseFiles(
35
+ FileChooserDescriptor (true , true , false , false , false , true ),
36
+ project,
37
+ null
38
+ ) { selectedFiles ->
39
+ // Assuming you want to add all selected files to the list
40
+ selectedFiles.forEach { file ->
41
+ filePathModel.addElement(file.path)
42
+ }
43
+ }
44
+ }.setRemoveAction { removeButton ->
45
+ val selectedFiles = filePathList.selectedValuesList
46
+ selectedFiles.forEach { filePath ->
47
+ filePathModel.removeElement(filePath)
48
+ }
49
+ }
50
+ panel.add(filePathDecorator.createPanel())
51
+ JLabel (" Don't halt the debugger in these namespaces" ).also { panel.add(it) }
52
+ JLabel (" Click the + twice to activate the selector. It doesn't display the panel on first click." ).also { panel.add(it) }
53
+ // Create a decorator for namespaces
54
+ val namespaceDecorator = ToolbarDecorator .createDecorator(namespaceList)
55
+ namespaceDecorator.setAddAction { addButton ->
56
+ namespaceDecorator.setAddAction { addButton ->
57
+ val dialog = PhpTreeClassChooserDialog (" Select PHP namespaces" , project, null )
58
+ dialog.showDialog()
59
+ val selectedPhpClass = dialog.selected
60
+ if (selectedPhpClass != null ) {
61
+ var selectedNamespace = selectedPhpClass.namespaceName
62
+ if (selectedNamespace != null ) {
63
+ namespaceModel.addElement(selectedNamespace)
64
+ }
65
+ }
66
+ }
67
+ }.setRemoveAction { removeButton ->
68
+ val selectedNamespaces = namespaceList.selectedValuesList
69
+ selectedNamespaces.forEach { namespace ->
70
+ namespaceModel.removeElement(namespace)
71
+ }
72
+ }
73
+ panel.add(namespaceDecorator.createPanel())
74
+
75
+ return panel
13
76
}
14
77
15
78
override fun isModified (): Boolean {
16
- // Here you can implement a check to see if settings have been modified
17
- return false
79
+ val filePaths = (0 until filePathModel.size()).map { i -> filePathModel.getElementAt(i) }
80
+ val namespaces = (0 until namespaceModel.size()).map { i -> namespaceModel.getElementAt(i) }
81
+ return filePaths != settings.settingsState.filepaths || namespaces != settings.settingsState.namespaces
18
82
}
19
83
20
84
override fun apply () {
21
- // Here you should implement applying the settings
85
+ val filePathModel = filePathList.model as ? DefaultListModel <String >
86
+ val namespaceModel = namespaceList.model as ? DefaultListModel <String >
87
+
88
+ settings?.settingsState?.filepaths =
89
+ filePathModel?.let { (0 until it.size()).map { i -> it.getElementAt(i) } }?.let { ArrayList (it) }!!
90
+ settings?.settingsState?.namespaces =
91
+ namespaceModel?.let { (0 until it.size()).map { i -> it.getElementAt(i) } }?.let { ArrayList (it) }!!
22
92
}
23
93
24
94
override fun reset () {
25
- // Here you can implement resetting your settings UI to the stored state
95
+ filePathModel.clear()
96
+ filePathModel.addAll(settings.settingsState.filepaths)
97
+ namespaceModel.clear()
98
+ namespaceModel.addAll(settings.settingsState.namespaces)
26
99
}
27
100
28
- override fun getDisplayName (): String {
29
- // The display name for the settings component
30
- return " PHPStorm Xdebug Skip"
101
+ override fun getDisplayName (): String = " PHPStorm Xdebug Skip"
102
+
103
+ private fun createListRenderer (): ColoredListCellRenderer <String > {
104
+ return object : ColoredListCellRenderer <String >() {
105
+ override fun customizeCellRenderer (list : JList <out String >, value : String? , index : Int , selected : Boolean , hasFocus : Boolean ) {
106
+ append(value ? : " " )
107
+ }
108
+ }
31
109
}
32
110
}
0 commit comments