@@ -7,10 +7,10 @@ import cc.unitmesh.devti.gui.planner.MarkdownLanguageField
7
7
import cc.unitmesh.devti.inline.AutoDevLineBorder
8
8
import cc.unitmesh.devti.sketch.AutoSketchMode
9
9
import com.intellij.openapi.project.Project
10
+ import com.intellij.ui.components.JBScrollPane
10
11
import com.intellij.ui.JBColor
11
- import com.intellij.util.ui.JBUI.Borders.emptyLeft
12
+ import com.intellij.util.ui.JBUI
12
13
import java.awt.BorderLayout
13
- import java.awt.FlowLayout
14
14
import javax.swing.BorderFactory
15
15
import javax.swing.Box
16
16
import javax.swing.JButton
@@ -22,49 +22,39 @@ class IssueInputPanel(
22
22
private val onSubmit : (String ) -> Unit ,
23
23
private val onCancel : () -> Unit
24
24
) : 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
29
26
30
27
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 )
45
30
}
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
+ }
54
43
}
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
+ })
62
51
}
52
+ buttonPanel.add(buttonsBox, BorderLayout .EAST )
53
+ buttonPanel.border = JBUI .Borders .empty(5 )
63
54
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())
68
58
}
69
59
70
60
fun handlingExecute (newPlan : String ) {
@@ -74,17 +64,21 @@ class IssueInputPanel(
74
64
}
75
65
}
76
66
77
- fun getText (): String = textArea.text
67
+ fun getText (): String = textArea? .text ? : " "
78
68
79
69
fun setText (text : String ) {
80
70
if (text.isNotBlank()) {
81
- textArea.text = text
71
+ textArea? .text = text
82
72
} else {
83
- textArea.text = placeholder
73
+ textArea? .text = placeholder
84
74
}
85
75
}
86
76
87
77
fun requestTextAreaFocus () {
88
- textArea.requestFocus()
78
+ textArea?.requestFocus()
79
+ }
80
+
81
+ fun dispose () {
82
+ textArea = null
89
83
}
90
84
}
0 commit comments