Skip to content

Commit 5fffc8c

Browse files
committed
refactor: change to dsl layout for beeter maintain
1 parent aaa097d commit 5fffc8c

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

src/main/kotlin/cc/unitmesh/devti/gui/chat/ChatCodingPanel.kt

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@ package cc.unitmesh.devti.gui.chat
33
import cc.unitmesh.devti.AutoDevBundle
44
import cc.unitmesh.devti.gui.block.whenDisposed
55
import cc.unitmesh.devti.provider.ContextPrompter
6+
import com.intellij.ide.BrowserUtil
67
import com.intellij.openapi.Disposable
78
import com.intellij.openapi.ui.NullableComponent
9+
import com.intellij.openapi.ui.SimpleToolWindowPanel
810
import com.intellij.openapi.wm.IdeFocusManager
911
import com.intellij.ui.Gray
1012
import com.intellij.ui.JBColor
1113
import com.intellij.ui.OnePixelSplitter
14+
import com.intellij.ui.components.ActionLink
1215
import com.intellij.ui.components.JBLabel
1316
import com.intellij.ui.components.JBPanel
1417
import com.intellij.ui.components.JBScrollPane
1518
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
1622
import com.intellij.util.ui.JBEmptyBorder
1723
import com.intellij.util.ui.JBFont
1824
import com.intellij.util.ui.JBUI
@@ -21,19 +27,15 @@ import kotlinx.coroutines.flow.Flow
2127
import kotlinx.coroutines.flow.collect
2228
import java.awt.BorderLayout
2329
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.*
2831

2932

3033
class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disposable: Disposable?) :
31-
JBPanel<ChatCodingPanel>(),
34+
SimpleToolWindowPanel(true, true),
3235
NullableComponent {
3336
private var progressBar: JProgressBar
3437
private val myTitle = JBLabel("Conversation")
3538
private val myList = JPanel(VerticalLayout(JBUI.scale(10)))
36-
private val mainPanel = JPanel(BorderLayout(0, JBUI.scale(8)))
3739
private val myScrollPane = JBScrollPane(
3840
myList,
3941
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
@@ -43,9 +45,6 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
4345
private val focusMouseListener: MouseAdapter
4446

4547
init {
46-
val splitter = OnePixelSplitter(true, .98f)
47-
splitter.dividerWidth = 2
48-
4948
focusMouseListener = object : MouseAdapter() {
5049
override fun mouseClicked(e: MouseEvent?) {
5150
focusInput()
@@ -55,24 +54,20 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
5554
myTitle.foreground = JBColor.namedColor("Label.infoForeground", JBColor(Gray.x80, Gray.x8C))
5655
myTitle.font = JBFont.label()
5756

58-
layout = BorderLayout(JBUI.scale(7), 0)
59-
background = UIUtil.getListBackground()
60-
mainPanel.isOpaque = false
61-
add(mainPanel, BorderLayout.CENTER)
62-
6357
myList.isOpaque = true
6458
myList.background = UIUtil.getListBackground()
6559
myScrollPane.border = JBEmptyBorder(10, 15, 10, 15)
6660

67-
splitter.firstComponent = myScrollPane
68-
6961
progressBar = JProgressBar()
70-
splitter.secondComponent = progressBar
71-
mainPanel.add(splitter)
62+
7263
myScrollPane.verticalScrollBar.autoscrolls = true
7364

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+
7470
inputSection = AutoDevInputSection(chatCodingService.project, disposable)
75-
mainPanel.add(inputSection, BorderLayout.SOUTH)
7671
inputSection.addListener(object : AutoDevInputListener {
7772
override fun onSubmit(component: AutoDevInputSection, trigger: AutoDevInputTrigger) {
7873
val prompt = component.text
@@ -87,13 +82,31 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
8782
}
8883
})
8984

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+
90102
inputSection.text = ""
91103

92104
disposable?.whenDisposed(disposable) {
93105
myList.removeAll()
94106
}
95107
}
96108

109+
97110
fun focusInput() {
98111
val focusManager = IdeFocusManager.getInstance(chatCodingService.project)
99112
focusManager.doWhenFocusSettlesDown {
@@ -128,6 +141,8 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
128141
myList.remove(myList.componentCount - 1)
129142
}
130143

144+
progressBar.isVisible = true
145+
131146
val result = updateMessageInUi(content)
132147

133148
progressBar.isIndeterminate = false
@@ -180,7 +195,7 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
180195
return text
181196
}
182197

183-
fun setContent(trimMargin: String) {
198+
fun setInput(trimMargin: String) {
184199
inputSection.text = trimMargin
185200
this.focusInput()
186201
}

src/main/kotlin/cc/unitmesh/devti/toolwindow/SendToWindow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ fun chatWithSelection(
6262
contentManager?.addContent(content!!)
6363

6464
toolWindowManager?.activate {
65-
contentPanel.setContent("\n```$language\n$prefixText\n```")
65+
contentPanel.setInput("\n```$language\n$prefixText\n```")
6666
}
6767
}

src/main/resources/messages/AutoDevBundle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ intentions.chat.selected.code.name=Chat with this code
3535
intentions.chat.selected.fragment.name=Chat with {0} fragment
3636
intentions.chat.selected.element.name=Chat with ''{0}'' {1}
3737
chat.too.long.user.message=Message has is {0} tokens, it's too looooooooooooooooooong
38-
tooltip.thanks=Thanks for like, but we don't support this
38+
tooltip.thanks=Thanks for like, but we don't support this
39+
label.submit.issue=Want new feature?

0 commit comments

Comments
 (0)