@@ -20,6 +20,8 @@ import com.intellij.openapi.actionSystem.ActionPlaces
20
20
import com.intellij.openapi.actionSystem.ActionToolbar
21
21
import com.intellij.openapi.actionSystem.AnAction
22
22
import com.intellij.openapi.actionSystem.impl.ActionButton
23
+ import com.intellij.openapi.application.ApplicationManager
24
+ import com.intellij.openapi.application.ModalityState
23
25
import com.intellij.openapi.application.runInEdt
24
26
import com.intellij.openapi.editor.Editor
25
27
import com.intellij.openapi.fileTypes.PlainTextLanguage
@@ -51,9 +53,15 @@ interface SketchProcessListener {
51
53
fun onAfter () {}
52
54
}
53
55
54
- open class SketchToolWindow (val project : Project , val editor : Editor ? , private val showInput : Boolean = false ) :
56
+ open class SketchToolWindow (
57
+ val project : Project ,
58
+ val editor : Editor ? ,
59
+ private val showInput : Boolean = false ,
60
+ chatActionType : ChatActionType = ChatActionType .SKETCH
61
+ ) :
55
62
SimpleToolWindowPanel (true , true ), NullableComponent , Disposable {
56
- private val chatCodingService = ChatCodingService (ChatActionType .SKETCH , project)
63
+ open val chatCodingService = ChatCodingService (chatActionType, project)
64
+ open val inputListener = SketchInputListener (project, chatCodingService, this )
57
65
private var progressBar: CustomProgressBar = CustomProgressBar (this )
58
66
private var inputSection: AutoDevInputSection = AutoDevInputSection (project, this , showAgent = false )
59
67
@@ -66,19 +74,19 @@ open class SketchToolWindow(val project: Project, val editor: Editor?, private v
66
74
this .isOpaque = true
67
75
}
68
76
69
- private var isUserScrolling: Boolean = false
77
+ protected var isUserScrolling: Boolean = false
78
+ protected var isInterrupted: Boolean = false
70
79
71
- private var isInterrupted: Boolean = false
72
-
73
- private var systemPrompt: JPanel = JPanel (BorderLayout ())
74
- private var contentPanel = JPanel (BorderLayout ())
80
+ protected var systemPromptPanel: JPanel = JPanel (BorderLayout ())
81
+ protected var contentPanel = JPanel (BorderLayout ())
75
82
76
83
val header = JButton (AllIcons .Actions .Copy ).apply {
77
84
this @apply.preferredSize = Dimension (32 , 32 )
78
85
79
86
addMouseListener(object : MouseAdapter () {
80
87
override fun mouseClicked (e : MouseEvent ? ) {
81
- var allText = historyPanel.components.filterIsInstance<LangSketch >().joinToString(" \n " ) { it.getViewText() }
88
+ var allText =
89
+ historyPanel.components.filterIsInstance<LangSketch >().joinToString(" \n " ) { it.getViewText() }
82
90
allText + = myList.components.filterIsInstance<LangSketch >().joinToString(" \n " ) { it.getViewText() }
83
91
84
92
val selection = StringSelection (allText)
@@ -88,8 +96,8 @@ open class SketchToolWindow(val project: Project, val editor: Editor?, private v
88
96
})
89
97
}
90
98
91
- private var panelContent: DialogPanel = panel {
92
- row { cell(systemPrompt ).fullWidth().fullHeight() }
99
+ protected var panelContent: DialogPanel = panel {
100
+ row { cell(systemPromptPanel ).fullWidth().fullHeight() }
93
101
row { cell(header).alignRight() }
94
102
row { cell(historyPanel).fullWidth().fullHeight() }
95
103
row { cell(myList).fullWidth().fullHeight() }
@@ -110,8 +118,6 @@ open class SketchToolWindow(val project: Project, val editor: Editor?, private v
110
118
111
119
var handleCancel: ((String ) -> Unit )? = null
112
120
113
- private val listener = SketchInputListener (project, chatCodingService, this )
114
-
115
121
private val processListeners = mutableListOf<SketchProcessListener >()
116
122
117
123
init {
@@ -150,26 +156,33 @@ open class SketchToolWindow(val project: Project, val editor: Editor?, private v
150
156
contentPanel.add(progressBar, BorderLayout .SOUTH )
151
157
152
158
if (showInput) {
153
- inputSection.also {
154
- it.border = JBUI .Borders .empty(8 )
155
- }
156
-
157
- inputSection.addListener(listener)
158
- contentPanel.add(inputSection, BorderLayout .SOUTH )
159
+ ApplicationManager .getApplication().invokeLater({
160
+ setupListener()
161
+ }, ModalityState .nonModal())
162
+ }
159
163
160
- addProcessListener(object : SketchProcessListener {
161
- override fun onBefore () {
162
- isInterrupted = false
163
- inputSection.showStopButton()
164
- }
164
+ setContent(contentPanel)
165
+ }
165
166
166
- override fun onAfter () {
167
- inputSection.showSendButton()
168
- }
169
- })
167
+ private fun setupListener () {
168
+ inputSection.also {
169
+ it.border = JBUI .Borders .empty(8 )
170
170
}
171
171
172
- setContent(contentPanel)
172
+ inputListener.setup()
173
+ inputSection.addListener(inputListener)
174
+ contentPanel.add(inputSection, BorderLayout .SOUTH )
175
+
176
+ addProcessListener(object : SketchProcessListener {
177
+ override fun onBefore () {
178
+ isInterrupted = false
179
+ inputSection.showStopButton()
180
+ }
181
+
182
+ override fun onAfter () {
183
+ inputSection.showSendButton()
184
+ }
185
+ })
173
186
}
174
187
175
188
fun onStart () {
@@ -226,7 +239,7 @@ open class SketchToolWindow(val project: Project, val editor: Editor?, private v
226
239
227
240
fun addSystemPrompt (text : String ) {
228
241
runInEdt {
229
- systemPrompt .add(createSingleTextView(text, language = " VTL" ))
242
+ systemPromptPanel .add(createSingleTextView(text, language = " VTL" ))
230
243
this .revalidate()
231
244
this .repaint()
232
245
}
@@ -331,7 +344,7 @@ open class SketchToolWindow(val project: Project, val editor: Editor?, private v
331
344
AfterRun ()
332
345
333
346
if (AutoSketchMode .getInstance(project).isEnable && ! isInterrupted) {
334
- AutoSketchMode .getInstance(project).start(text, this @SketchToolWindow.listener )
347
+ AutoSketchMode .getInstance(project).start(text, this @SketchToolWindow.inputListener )
335
348
}
336
349
}
337
350
@@ -371,7 +384,7 @@ open class SketchToolWindow(val project: Project, val editor: Editor?, private v
371
384
progressBar.isIndeterminate = false
372
385
progressBar.isVisible = false
373
386
blockViews.clear()
374
- systemPrompt .removeAll()
387
+ systemPromptPanel .removeAll()
375
388
myList.removeAll()
376
389
historyPanel.removeAll()
377
390
initializePreAllocatedBlocks(project)
0 commit comments