@@ -32,26 +32,31 @@ import com.intellij.util.ui.JBEmptyBorder
32
32
import com.intellij.util.ui.JBUI
33
33
import com.intellij.util.ui.UIUtil
34
34
import com.intellij.util.ui.components.BorderLayoutPanel
35
- import kotlinx.serialization.decodeFromString
36
35
import kotlinx.serialization.json.Json
36
+ import java.awt.CardLayout
37
37
import java.awt.Color
38
38
import java.awt.Dimension
39
39
import java.awt.event.MouseAdapter
40
40
import java.awt.event.MouseEvent
41
41
import java.util.function.Supplier
42
42
import javax.swing.Box
43
43
import javax.swing.JComponent
44
+ import javax.swing.JPanel
44
45
import kotlin.math.max
45
46
import kotlin.math.min
47
+ import kotlinx.serialization.decodeFromString
46
48
47
49
/* *
48
50
*
49
51
*/
50
52
class AutoDevInputSection (private val project : Project , val disposable : Disposable ? ) : BorderLayoutPanel() {
51
53
private val input: AutoDevInput
52
54
private val documentListener: DocumentListener
53
- private val buttonPresentation: Presentation
54
- private val button: ActionButton
55
+ private val sendButtonPresentation: Presentation
56
+ private val stopButtonPresentation: Presentation
57
+ private val sendButton: ActionButton
58
+ private val stopButton: ActionButton
59
+ private val buttonPanel = JPanel (CardLayout ())
55
60
56
61
private val defaultRag: CustomAgentConfig = CustomAgentConfig (" <Select Custom Agent>" , " Normal" )
57
62
private var customRag: ComboBox <CustomAgentConfig > = ComboBox (MutableCollectionComboBoxModel (listOf ()))
@@ -70,18 +75,37 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
70
75
}
71
76
72
77
init {
73
- val presentation = Presentation (AutoDevBundle .message(" chat.panel.send" ))
74
- presentation.setIcon(AutoDevIcons .Send )
75
- buttonPresentation = presentation
76
- button = ActionButton (
78
+ val sendButtonPresentation = Presentation (AutoDevBundle .message(" chat.panel.send" ))
79
+ sendButtonPresentation.setIcon(AutoDevIcons .Send )
80
+ this .sendButtonPresentation = sendButtonPresentation
81
+
82
+ val stopButtonPresentation = Presentation (" Stop" )
83
+ stopButtonPresentation.setIcon(AutoDevIcons .Idea )
84
+ this .stopButtonPresentation = stopButtonPresentation
85
+
86
+ sendButton = ActionButton (
77
87
DumbAwareAction .create {
78
88
object : DumbAwareAction (" " ) {
79
89
override fun actionPerformed (e : AnActionEvent ) {
90
+ showStopButton()
80
91
editorListeners.multicaster.onSubmit(this @AutoDevInputSection, AutoDevInputTrigger .Button )
81
92
}
82
93
}.actionPerformed(it)
83
94
},
84
- buttonPresentation,
95
+ this .sendButtonPresentation,
96
+ " " ,
97
+ Dimension (20 , 20 )
98
+ )
99
+
100
+ stopButton = ActionButton (
101
+ DumbAwareAction .create {
102
+ object : DumbAwareAction (" " ) {
103
+ override fun actionPerformed (e : AnActionEvent ) {
104
+ editorListeners.multicaster.onStop(this @AutoDevInputSection)
105
+ }
106
+ }.actionPerformed(it)
107
+ },
108
+ this .stopButtonPresentation,
85
109
" " ,
86
110
Dimension (20 , 20 )
87
111
)
@@ -125,13 +149,17 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
125
149
layoutPanel.addToLeft(customRag)
126
150
}
127
151
152
+
153
+ buttonPanel.add(sendButton, " Send" )
154
+ buttonPanel.add(stopButton, " Stop" )
155
+
128
156
layoutPanel.addToCenter(horizontalGlue)
129
- layoutPanel.addToRight(button )
157
+ layoutPanel.addToRight(buttonPanel )
130
158
addToBottom(layoutPanel)
131
159
132
160
ComponentValidator (disposable!! ).withValidator(Supplier <ValidationInfo ?> {
133
161
val validationInfo: ValidationInfo ? = this .getInputValidationInfo()
134
- button .setEnabled(validationInfo == null )
162
+ sendButton .setEnabled(validationInfo == null )
135
163
return @Supplier validationInfo
136
164
}).installOn((this as JComponent )).revalidate()
137
165
@@ -144,6 +172,16 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
144
172
tokenizer = TokenizerImpl .INSTANCE
145
173
}
146
174
175
+ fun showStopButton () {
176
+ (buttonPanel.layout as ? CardLayout )?.show(buttonPanel, " Stop" )
177
+ stopButton.isEnabled = true
178
+ }
179
+
180
+ fun showSendButton () {
181
+ (buttonPanel.layout as ? CardLayout )?.show(buttonPanel, " Send" )
182
+ buttonPanel.isEnabled = true
183
+ }
184
+
147
185
private fun loadRagApps (): List <CustomAgentConfig > {
148
186
val ragsJsonConfig = project.customAgentSetting.ragsJsonConfig
149
187
if (ragsJsonConfig.isEmpty()) return listOf (defaultRag)
0 commit comments