@@ -3,16 +3,22 @@ package cc.unitmesh.devti.gui.chat
3
3
import cc.unitmesh.devti.AutoDevBundle
4
4
import cc.unitmesh.devti.gui.block.whenDisposed
5
5
import cc.unitmesh.devti.provider.ContextPrompter
6
+ import com.intellij.ide.BrowserUtil
6
7
import com.intellij.openapi.Disposable
7
8
import com.intellij.openapi.ui.NullableComponent
9
+ import com.intellij.openapi.ui.SimpleToolWindowPanel
8
10
import com.intellij.openapi.wm.IdeFocusManager
9
11
import com.intellij.ui.Gray
10
12
import com.intellij.ui.JBColor
11
13
import com.intellij.ui.OnePixelSplitter
14
+ import com.intellij.ui.components.ActionLink
12
15
import com.intellij.ui.components.JBLabel
13
16
import com.intellij.ui.components.JBPanel
14
17
import com.intellij.ui.components.JBScrollPane
15
18
import com.intellij.ui.components.panels.VerticalLayout
19
+ import com.intellij.ui.dsl.builder.*
20
+ import com.intellij.ui.dsl.gridLayout.HorizontalAlign
21
+ import com.intellij.ui.dsl.gridLayout.VerticalAlign
16
22
import com.intellij.util.ui.JBEmptyBorder
17
23
import com.intellij.util.ui.JBFont
18
24
import com.intellij.util.ui.JBUI
@@ -21,19 +27,15 @@ import kotlinx.coroutines.flow.Flow
21
27
import kotlinx.coroutines.flow.collect
22
28
import java.awt.BorderLayout
23
29
import java.awt.event.*
24
- import javax.swing.JButton
25
- import javax.swing.JPanel
26
- import javax.swing.JProgressBar
27
- import javax.swing.ScrollPaneConstants
30
+ import javax.swing.*
28
31
29
32
30
33
class ChatCodingPanel (private val chatCodingService : ChatCodingService , val disposable : Disposable ? ) :
31
- JBPanel < ChatCodingPanel >( ),
34
+ SimpleToolWindowPanel ( true , true ),
32
35
NullableComponent {
33
36
private var progressBar: JProgressBar
34
37
private val myTitle = JBLabel (" Conversation" )
35
38
private val myList = JPanel (VerticalLayout (JBUI .scale(10 )))
36
- private val mainPanel = JPanel (BorderLayout (0 , JBUI .scale(8 )))
37
39
private val myScrollPane = JBScrollPane (
38
40
myList,
39
41
ScrollPaneConstants .VERTICAL_SCROLLBAR_AS_NEEDED ,
@@ -43,9 +45,6 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
43
45
private val focusMouseListener: MouseAdapter
44
46
45
47
init {
46
- val splitter = OnePixelSplitter (true , .98f )
47
- splitter.dividerWidth = 2
48
-
49
48
focusMouseListener = object : MouseAdapter () {
50
49
override fun mouseClicked (e : MouseEvent ? ) {
51
50
focusInput()
@@ -55,24 +54,20 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
55
54
myTitle.foreground = JBColor .namedColor(" Label.infoForeground" , JBColor (Gray .x80, Gray .x8C))
56
55
myTitle.font = JBFont .label()
57
56
58
- layout = BorderLayout (JBUI .scale(7 ), 0 )
59
- background = UIUtil .getListBackground()
60
- mainPanel.isOpaque = false
61
- add(mainPanel, BorderLayout .CENTER )
62
-
63
57
myList.isOpaque = true
64
58
myList.background = UIUtil .getListBackground()
65
59
myScrollPane.border = JBEmptyBorder (10 , 15 , 10 , 15 )
66
60
67
- splitter.firstComponent = myScrollPane
68
-
69
61
progressBar = JProgressBar ()
70
- splitter.secondComponent = progressBar
71
- mainPanel.add(splitter)
62
+
72
63
myScrollPane.verticalScrollBar.autoscrolls = true
73
64
65
+ val actionLink = ActionLink (AutoDevBundle .message(" label.submit.issue" )) {
66
+ BrowserUtil .browse(" https://github.com/unit-mesh/auto-dev/issues" )
67
+ }
68
+ actionLink.setExternalLinkIcon()
69
+
74
70
inputSection = AutoDevInputSection (chatCodingService.project, disposable)
75
- mainPanel.add(inputSection, BorderLayout .SOUTH )
76
71
inputSection.addListener(object : AutoDevInputListener {
77
72
override fun onSubmit (component : AutoDevInputSection , trigger : AutoDevInputTrigger ) {
78
73
val prompt = component.text
@@ -87,13 +82,31 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
87
82
}
88
83
})
89
84
85
+ setContent(
86
+ panel {
87
+ row {
88
+ cell(myList).verticalAlign(VerticalAlign .FILL )
89
+ }
90
+ row {
91
+ cell(progressBar).horizontalAlign(HorizontalAlign .FILL )
92
+ }
93
+ row {
94
+ cell(actionLink).horizontalAlign(HorizontalAlign .RIGHT )
95
+ }
96
+ row {
97
+ cell(inputSection).horizontalAlign(HorizontalAlign .FILL )
98
+ }
99
+ }
100
+ )
101
+
90
102
inputSection.text = " "
91
103
92
104
disposable?.whenDisposed(disposable) {
93
105
myList.removeAll()
94
106
}
95
107
}
96
108
109
+
97
110
fun focusInput () {
98
111
val focusManager = IdeFocusManager .getInstance(chatCodingService.project)
99
112
focusManager.doWhenFocusSettlesDown {
@@ -128,6 +141,8 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
128
141
myList.remove(myList.componentCount - 1 )
129
142
}
130
143
144
+ progressBar.isVisible = true
145
+
131
146
val result = updateMessageInUi(content)
132
147
133
148
progressBar.isIndeterminate = false
@@ -180,7 +195,7 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
180
195
return text
181
196
}
182
197
183
- fun setContent (trimMargin : String ) {
198
+ fun setInput (trimMargin : String ) {
184
199
inputSection.text = trimMargin
185
200
this .focusInput()
186
201
}
0 commit comments