Skip to content

Commit 09fda6e

Browse files
committed
feat(devti): enhance issue input panel with placeholder functionality
#353 - Add placeholder text to the text area - Implement focus listener to handle placeholder visibility - Adjust text color for placeholder and user input- Update getText and setText methods to handle placeholder
1 parent 3fba1f3 commit 09fda6e

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

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

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import cc.unitmesh.devti.gui.chat.message.ChatActionType
55
import cc.unitmesh.devti.sketch.AutoSketchMode
66
import com.intellij.openapi.project.Project
77
import com.intellij.ui.Gray
8+
import com.intellij.ui.JBColor
89
import com.intellij.ui.components.JBScrollPane
910
import com.intellij.util.ui.JBUI
11+
import com.intellij.util.ui.UIUtil
1012
import java.awt.*
13+
import java.awt.event.FocusEvent
14+
import java.awt.event.FocusListener
1115
import javax.swing.*
1216
import javax.swing.border.LineBorder
1317

@@ -18,75 +22,80 @@ class IssueInputPanel(
1822
private val onCancel: () -> Unit
1923
) : JPanel(BorderLayout()) {
2024
private val textArea: JTextArea
25+
private var isPlaceholderVisible = true
2126

2227
init {
2328
background = JBUI.CurrentTheme.ToolWindow.background()
29+
border = JBUI.Borders.customLine(UIUtil.getBoundsColor(), 1, 0, 1, 0)
2430

2531
val mainPanel = JPanel(BorderLayout(8, 8)).apply {
26-
border = BorderFactory.createCompoundBorder(
27-
JBUI.Borders.empty(8),
28-
BorderFactory.createCompoundBorder(LineBorder(Gray._230, 1, true),
29-
JBUI.Borders.empty(8)
30-
)
31-
)
3232
background = JBUI.CurrentTheme.ToolWindow.background()
3333
}
3434

35-
val headerLabel = JLabel(title).apply {
36-
font = font.deriveFont(font.size + 2f)
37-
border = JBUI.Borders.emptyBottom(10)
38-
}
39-
4035
textArea = JTextArea().apply {
4136
lineWrap = true
4237
wrapStyleWord = true
43-
border = null
4438
font = Font("Arial", Font.PLAIN, 16)
4539
rows = 10
40+
text = title
41+
foreground = JBColor.GRAY
42+
43+
addFocusListener(object : FocusListener {
44+
override fun focusGained(e: FocusEvent?) {
45+
if (isPlaceholderVisible) {
46+
text = ""
47+
foreground = UIManager.getColor("TextArea.foreground")
48+
isPlaceholderVisible = false
49+
}
50+
}
51+
52+
override fun focusLost(e: FocusEvent?) {
53+
if (text.isEmpty()) {
54+
text = title
55+
foreground = JBColor.GRAY
56+
isPlaceholderVisible = true
57+
}
58+
}
59+
})
4660
}
4761

4862
val scrollPane = JBScrollPane(textArea).apply {
4963
border = null
50-
preferredSize = Dimension(400, 300)
64+
preferredSize = Dimension(preferredSize.width, 300)
5165
}
5266

5367
val controlsPanel = JPanel(BorderLayout(10, 0)).apply {
54-
border = JBUI.Borders.emptyTop(10)
5568
background = JBUI.CurrentTheme.ToolWindow.background()
5669
}
5770

5871
val buttonsPanel = JPanel().apply {
5972
layout = FlowLayout(FlowLayout.RIGHT, 8, 0)
73+
background = JBUI.CurrentTheme.ToolWindow.background()
6074
isOpaque = false
6175
}
6276

6377
val submitButton = JButton("Submit").apply {
6478
addActionListener {
65-
val text = textArea.text
79+
val text = if (isPlaceholderVisible) "" else textArea.text
6680
if (text.isNotBlank()) {
6781
handlingExecute(text)
6882
onSubmit(text)
6983
}
7084
}
71-
72-
preferredSize = Dimension(90, 32)
7385
}
7486

7587
val cancelButton = JButton("Cancel").apply {
7688
addActionListener {
7789
onCancel()
7890
}
79-
80-
preferredSize = Dimension(90, 32)
8191
}
8292

8393
buttonsPanel.add(submitButton)
84-
buttonsPanel.add(Box.createHorizontalStrut(5))
94+
buttonsPanel.add(Box.createHorizontalStrut(4))
8595
buttonsPanel.add(cancelButton)
8696

8797
controlsPanel.add(buttonsPanel, BorderLayout.EAST)
8898

89-
mainPanel.add(headerLabel, BorderLayout.NORTH)
9099
mainPanel.add(scrollPane, BorderLayout.CENTER)
91100
mainPanel.add(controlsPanel, BorderLayout.SOUTH)
92101

@@ -100,10 +109,18 @@ class IssueInputPanel(
100109
}
101110
}
102111

103-
fun getText(): String = textArea.text
112+
fun getText(): String = if (isPlaceholderVisible) "" else textArea.text
104113

105114
fun setText(text: String) {
106-
textArea.text = text
115+
if (text.isNotBlank()) {
116+
textArea.text = text
117+
textArea.foreground = UIManager.getColor("TextArea.foreground")
118+
isPlaceholderVisible = false
119+
} else {
120+
textArea.text = title
121+
textArea.foreground = JBColor.GRAY
122+
isPlaceholderVisible = true
123+
}
107124
}
108125

109126
fun requestTextAreaFocus() {

0 commit comments

Comments
 (0)