-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPicoCodeConfigurable.kt
More file actions
68 lines (52 loc) · 2.26 KB
/
PicoCodeConfigurable.kt
File metadata and controls
68 lines (52 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.picocode
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.project.Project
import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBTextField
import com.intellij.util.ui.FormBuilder
import javax.swing.JComponent
import javax.swing.JPanel
/**
* Project settings configurable for PicoCode plugin
* Provides UI to configure backend server host and port
*/
class PicoCodeConfigurable(private val project: Project) : Configurable {
private val hostField = JBTextField(20)
private val portField = JBTextField(10)
private var settingsPanel: JPanel? = null
override fun getDisplayName(): String = "PicoCode"
override fun createComponent(): JComponent {
val settings = PicoCodeSettings.getInstance(project)
val state = settings.state
// Initialize fields with current settings
hostField.text = state.serverHost
portField.text = state.serverPort.toString()
// Create the settings panel with form layout
settingsPanel = FormBuilder.createFormBuilder()
.addLabeledComponent(JBLabel("Backend Host:"), hostField, 1, false)
.addLabeledComponent(JBLabel("Backend Port:"), portField, 1, false)
.addComponentFillVertically(JPanel(), 0)
.panel
return settingsPanel!!
}
override fun isModified(): Boolean {
val settings = PicoCodeSettings.getInstance(project)
val state = settings.state
val hostModified = hostField.text != state.serverHost
val portModified = portField.text.toIntOrNull() != state.serverPort
return hostModified || portModified
}
override fun apply() {
val settings = PicoCodeSettings.getInstance(project)
val state = settings.state
state.serverHost = hostField.text.trim().ifEmpty { "localhost" }
state.serverPort = portField.text.trim().toIntOrNull() ?: 8000
settings.loadState(state)
}
override fun reset() {
val settings = PicoCodeSettings.getInstance(project)
val state = settings.state
hostField.text = state.serverHost
portField.text = state.serverPort.toString()
}
}