Skip to content

Commit d4bf83c

Browse files
committed
refactor(devti): optimize IssueInputPanel layout and functionality #352
- Simplified layout using BorderLayout instead of FlowLayout- Added JBScrollPane for text area to handle content overflow - Improved null safety by using nullable type for textArea- Added dispose function to properly release resources - Adjusted button placement and spacing
1 parent 9039e9d commit d4bf83c

File tree

1 file changed

+37
-43
lines changed

1 file changed

+37
-43
lines changed

core/src/main/kotlin/cc/unitmesh/devti/shadow/IssueInputPanel.kt

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import cc.unitmesh.devti.gui.planner.MarkdownLanguageField
77
import cc.unitmesh.devti.inline.AutoDevLineBorder
88
import cc.unitmesh.devti.sketch.AutoSketchMode
99
import com.intellij.openapi.project.Project
10+
import com.intellij.ui.components.JBScrollPane
1011
import com.intellij.ui.JBColor
11-
import com.intellij.util.ui.JBUI.Borders.emptyLeft
12+
import com.intellij.util.ui.JBUI
1213
import java.awt.BorderLayout
13-
import java.awt.FlowLayout
1414
import javax.swing.BorderFactory
1515
import javax.swing.Box
1616
import javax.swing.JButton
@@ -22,49 +22,39 @@ class IssueInputPanel(
2222
private val onSubmit: (String) -> Unit,
2323
private val onCancel: () -> Unit
2424
) : JPanel(BorderLayout()) {
25-
private val textArea: MarkdownLanguageField = MarkdownLanguageField(project, "", placeholder, "issue.md")
26-
.apply {
27-
border = AutoDevLineBorder(JBColor.namedColor("Focus.borderColor", JBColor.BLUE), 1, true, 4)
28-
}
25+
private var textArea: MarkdownLanguageField? = null
2926

3027
init {
31-
val buttonsPanel = createActionButtons()
32-
33-
add(textArea, BorderLayout.CENTER)
34-
add(buttonsPanel, BorderLayout.SOUTH)
35-
36-
background = JBColor.WHITE
37-
setBorder(BorderFactory.createEmptyBorder())
38-
}
39-
40-
private fun createActionButtons(): JPanel {
41-
val buttonsPanel = JPanel().apply {
42-
layout = FlowLayout(FlowLayout.RIGHT, 8, 0)
43-
isOpaque = false
44-
border = null
28+
textArea = MarkdownLanguageField(project, "", placeholder, "issue.md").apply {
29+
border = AutoDevLineBorder(JBColor.namedColor("Focus.borderColor", JBColor.BLUE), 1, true, 4)
4530
}
46-
47-
val submitButton = JButton("Submit").apply {
48-
addActionListener {
49-
if (text.isNotBlank()) {
50-
handlingExecute(text)
51-
onSubmit(text)
52-
} else {
53-
AutoDevNotifications.notify(project, "Input cannot be empty")
31+
32+
val buttonPanel = JPanel(BorderLayout())
33+
val buttonsBox = Box.createHorizontalBox().apply {
34+
add(JButton("Submit").apply {
35+
addActionListener {
36+
val text = textArea?.text ?: ""
37+
if (text.isNotBlank()) {
38+
handlingExecute(text)
39+
onSubmit(text)
40+
} else {
41+
AutoDevNotifications.notify(project, "Input cannot be empty")
42+
}
5443
}
55-
}
56-
}
57-
58-
val cancelButton = JButton("Cancel").apply {
59-
addActionListener {
60-
onCancel()
61-
}
44+
})
45+
add(Box.createHorizontalStrut(10))
46+
add(JButton("Cancel").apply {
47+
addActionListener {
48+
onCancel()
49+
}
50+
})
6251
}
52+
buttonPanel.add(buttonsBox, BorderLayout.EAST)
53+
buttonPanel.border = JBUI.Borders.empty(5)
6354

64-
buttonsPanel.add(submitButton)
65-
buttonsPanel.add(Box.createHorizontalStrut(4))
66-
buttonsPanel.add(cancelButton)
67-
return buttonsPanel
55+
add(JBScrollPane(textArea), BorderLayout.CENTER)
56+
add(buttonPanel, BorderLayout.SOUTH)
57+
setBorder(BorderFactory.createEmptyBorder())
6858
}
6959

7060
fun handlingExecute(newPlan: String) {
@@ -74,17 +64,21 @@ class IssueInputPanel(
7464
}
7565
}
7666

77-
fun getText(): String = textArea.text
67+
fun getText(): String = textArea?.text ?: ""
7868

7969
fun setText(text: String) {
8070
if (text.isNotBlank()) {
81-
textArea.text = text
71+
textArea?.text = text
8272
} else {
83-
textArea.text = placeholder
73+
textArea?.text = placeholder
8474
}
8575
}
8676

8777
fun requestTextAreaFocus() {
88-
textArea.requestFocus()
78+
textArea?.requestFocus()
79+
}
80+
81+
fun dispose() {
82+
textArea = null
8983
}
9084
}

0 commit comments

Comments
 (0)