Skip to content

Commit 6f6bdb1

Browse files
committed
refactor(gui): refactor chat coding panel to use new FrontendCodeView class
The commit introduces a new class `FrontendCodeView` and refactors the `ChatCodingPanel` to use it. The `FrontendCodeView` simplifies the code by combining two panels (`WebBlockView` and `CodeBlockView`) into a single panel. The refactoring also removes duplicate code and improves the readability of the `ChatCodingPanel`.
1 parent 1254088 commit 6f6bdb1

File tree

4 files changed

+37
-33
lines changed

4 files changed

+37
-33
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,8 @@ class VariableListCellRenderer : ListCellRenderer<AutoDevVariableListItemCompone
4646
isSelected: Boolean,
4747
cellHasFocus: Boolean,
4848
): Component {
49-
if (isSelected) {
50-
value!!.background = jList.selectionBackground
51-
value.foreground = jList.selectionForeground
52-
} else {
53-
value!!.background = jList.getBackground()
54-
value.foreground = jList.getForeground()
55-
}
49+
value!!.background = if (isSelected) jList.selectionBackground else jList.background
50+
value.foreground = if (isSelected) jList.selectionForeground else jList.foreground
5651
value.isEnabled = jList.isEnabled
5752
value.font = jList.font
5853

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

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import com.intellij.ui.Gray
2626
import com.intellij.ui.JBColor
2727
import com.intellij.ui.components.ActionLink
2828
import com.intellij.ui.components.JBLabel
29-
import com.intellij.ui.components.JBPanel
3029
import com.intellij.ui.components.JBScrollPane
3130
import com.intellij.ui.components.panels.VerticalLayout
3231
import com.intellij.ui.dsl.builder.panel
@@ -37,7 +36,6 @@ import kotlinx.coroutines.Dispatchers
3736
import kotlinx.coroutines.delay
3837
import kotlinx.coroutines.flow.*
3938
import kotlinx.coroutines.withContext
40-
import java.awt.BorderLayout
4139
import java.awt.event.ActionListener
4240
import java.awt.event.MouseAdapter
4341
import java.awt.event.MouseEvent
@@ -278,31 +276,9 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
278276
val blockView = WebBlockView(webBlock, project, {})
279277
val codeView = CodeBlockView(CodeBlock(msg, language = HTMLLanguage.INSTANCE), project, {})
280278

281-
myList.add(SimpleView(blockView, codeView))
279+
myList.add(FrontendCodeView(blockView, codeView))
282280

283281
updateUI()
284282
}
285283
}
286284

287-
class SimpleView(val webview: WebBlockView, val codeView: CodeBlockView) : JBPanel<MessageView>() {
288-
init {
289-
isDoubleBuffered = true
290-
isOpaque = true
291-
background = JBColor(0xE0EEF7, 0x2d2f30)
292-
293-
layout = BorderLayout(JBUI.scale(8), 0)
294-
val centerPanel = JPanel(VerticalLayout(JBUI.scale(8)))
295-
296-
centerPanel.isOpaque = false
297-
centerPanel.border = JBUI.Borders.emptyRight(8)
298-
centerPanel.background = JBColor(0xE0EEF7, 0x2d2f30)
299-
300-
add(centerPanel, BorderLayout.WEST)
301-
302-
webview.initialize()
303-
centerPanel.add(webview.getComponent())
304-
305-
codeView.initialize()
306-
centerPanel.add(codeView.getComponent())
307-
}
308-
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package cc.unitmesh.devti.gui.chat
2+
3+
import cc.unitmesh.devti.counit.view.WebBlockView
4+
import com.intellij.temporary.gui.block.CodeBlockView
5+
import com.intellij.ui.JBColor
6+
import com.intellij.ui.components.JBPanel
7+
import com.intellij.ui.components.panels.VerticalLayout
8+
import com.intellij.util.ui.JBUI
9+
import java.awt.BorderLayout
10+
import javax.swing.JPanel
11+
12+
class FrontendCodeView(val webview: WebBlockView, val codeView: CodeBlockView) : JBPanel<MessageView>() {
13+
init {
14+
isDoubleBuffered = true
15+
isOpaque = true
16+
background = JBColor(0xE0EEF7, 0x2d2f30)
17+
18+
layout = BorderLayout(JBUI.scale(8), 0)
19+
val centerPanel = JPanel(VerticalLayout(JBUI.scale(8)))
20+
21+
centerPanel.isOpaque = false
22+
centerPanel.border = JBUI.Borders.emptyRight(8)
23+
centerPanel.background = JBColor(0xE0EEF7, 0x2d2f30)
24+
25+
add(centerPanel, BorderLayout.WEST)
26+
27+
webview.initialize()
28+
centerPanel.add(webview.getComponent())
29+
30+
codeView.initialize()
31+
centerPanel.add(codeView.getComponent())
32+
}
33+
}

src/main/kotlin/cc/unitmesh/devti/gui/component/JsonLanguageField.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.intellij.ui.LanguageTextField
88
import java.awt.Dimension
99
import java.awt.FontMetrics
1010

11-
class JsonLanguageField(val myProject: Project, val value: String, private val placeholder: String) :
11+
class JsonLanguageField(private val myProject: Project, val value: String, private val placeholder: String) :
1212
LanguageTextField(JsonLanguage.INSTANCE, myProject, value) {
1313
override fun createEditor(): EditorEx {
1414
return super.createEditor().apply {

0 commit comments

Comments
 (0)