Skip to content

Commit 129fb29

Browse files
committed
refactor(dev-planner): improve issue input panel with placeholder and formatting #352
- Replace title with placeholder for issue description- Implement EditorTextField with soft wraps and spell checking - Adjust layout and styling for better user experience
1 parent 09fda6e commit 129fb29

File tree

2 files changed

+44
-61
lines changed

2 files changed

+44
-61
lines changed

core/src/main/kotlin/cc/unitmesh/devti/gui/planner/AutoDevPlannerToolWindow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class AutoDevPlannerToolWindow(val project: Project) : SimpleToolWindowPanel(tru
9696
private fun createIssueInputPanel(): JPanel {
9797
issueInputPanel = IssueInputPanel(
9898
project,
99-
title = "Enter Issue Description",
99+
placeholder = "Enter Issue Description",
100100
onSubmit = { issueText ->
101101
if (issueText.isNotBlank()) {
102102
showLoadingState(issueText)

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

Lines changed: 43 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,48 @@ package cc.unitmesh.devti.shadow
33
import cc.unitmesh.devti.gui.AutoDevToolWindowFactory
44
import cc.unitmesh.devti.gui.chat.message.ChatActionType
55
import cc.unitmesh.devti.sketch.AutoSketchMode
6+
import com.intellij.openapi.editor.SpellCheckingEditorCustomizationProvider
7+
import com.intellij.openapi.fileTypes.FileTypes
68
import com.intellij.openapi.project.Project
7-
import com.intellij.ui.Gray
8-
import com.intellij.ui.JBColor
9-
import com.intellij.ui.components.JBScrollPane
9+
import com.intellij.ui.*
10+
import com.intellij.util.containers.ContainerUtil
1011
import com.intellij.util.ui.JBUI
11-
import com.intellij.util.ui.UIUtil
12-
import java.awt.*
13-
import java.awt.event.FocusEvent
14-
import java.awt.event.FocusListener
15-
import javax.swing.*
16-
import javax.swing.border.LineBorder
12+
import java.awt.BorderLayout
13+
import java.awt.FlowLayout
14+
import javax.swing.BorderFactory
15+
import javax.swing.Box
16+
import javax.swing.JButton
17+
import javax.swing.JPanel
1718

1819
class IssueInputPanel(
1920
private val project: Project,
20-
private val title: String,
21+
private val placeholder: String,
2122
private val onSubmit: (String) -> Unit,
2223
private val onCancel: () -> Unit
2324
) : JPanel(BorderLayout()) {
24-
private val textArea: JTextArea
25+
private val textArea: EditorTextField
2526
private var isPlaceholderVisible = true
2627

2728
init {
28-
background = JBUI.CurrentTheme.ToolWindow.background()
29-
border = JBUI.Borders.customLine(UIUtil.getBoundsColor(), 1, 0, 1, 0)
30-
31-
val mainPanel = JPanel(BorderLayout(8, 8)).apply {
32-
background = JBUI.CurrentTheme.ToolWindow.background()
29+
textArea = createEditor(project).apply {
30+
setPlaceholder(placeholder)
31+
setShowPlaceholderWhenFocused(true)
3332
}
3433

35-
textArea = JTextArea().apply {
36-
lineWrap = true
37-
wrapStyleWord = true
38-
font = Font("Arial", Font.PLAIN, 16)
39-
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-
})
60-
}
34+
val buttonsPanel = createActionButtons()
6135

62-
val scrollPane = JBScrollPane(textArea).apply {
63-
border = null
64-
preferredSize = Dimension(preferredSize.width, 300)
65-
}
36+
add(textArea, BorderLayout.CENTER)
37+
add(buttonsPanel, BorderLayout.SOUTH)
6638

67-
val controlsPanel = JPanel(BorderLayout(10, 0)).apply {
68-
background = JBUI.CurrentTheme.ToolWindow.background()
69-
}
39+
background = textArea.editor?.component?.background ?: JBUI.CurrentTheme.ToolWindow.background()
40+
setBorder(BorderFactory.createEmptyBorder())
41+
}
7042

43+
private fun createActionButtons(): JPanel {
7144
val buttonsPanel = JPanel().apply {
7245
layout = FlowLayout(FlowLayout.RIGHT, 8, 0)
73-
background = JBUI.CurrentTheme.ToolWindow.background()
7446
isOpaque = false
47+
border = null
7548
}
7649

7750
val submitButton = JButton("Submit").apply {
@@ -93,13 +66,7 @@ class IssueInputPanel(
9366
buttonsPanel.add(submitButton)
9467
buttonsPanel.add(Box.createHorizontalStrut(4))
9568
buttonsPanel.add(cancelButton)
96-
97-
controlsPanel.add(buttonsPanel, BorderLayout.EAST)
98-
99-
mainPanel.add(scrollPane, BorderLayout.CENTER)
100-
mainPanel.add(controlsPanel, BorderLayout.SOUTH)
101-
102-
add(mainPanel, BorderLayout.CENTER)
69+
return buttonsPanel
10370
}
10471

10572
fun handlingExecute(newPlan: String) {
@@ -114,11 +81,9 @@ class IssueInputPanel(
11481
fun setText(text: String) {
11582
if (text.isNotBlank()) {
11683
textArea.text = text
117-
textArea.foreground = UIManager.getColor("TextArea.foreground")
11884
isPlaceholderVisible = false
11985
} else {
120-
textArea.text = title
121-
textArea.foreground = JBColor.GRAY
86+
textArea.text = placeholder
12287
isPlaceholderVisible = true
12388
}
12489
}
@@ -127,3 +92,21 @@ class IssueInputPanel(
12792
textArea.requestFocus()
12893
}
12994
}
95+
96+
private fun createEditor(project: Project): EditorTextField {
97+
val features: MutableSet<EditorCustomization?> = HashSet<EditorCustomization?>()
98+
99+
features.add(SoftWrapsEditorCustomization.ENABLED)
100+
features.add(AdditionalPageAtBottomEditorCustomization.DISABLED)
101+
ContainerUtil.addIfNotNull<EditorCustomization?>(
102+
features,
103+
SpellCheckingEditorCustomizationProvider.getInstance().enabledCustomization
104+
)
105+
106+
val editorField =
107+
EditorTextFieldProvider.getInstance().getEditorField(FileTypes.PLAIN_TEXT.language, project, features)
108+
109+
editorField.setFontInheritedFromLAF(false)
110+
return editorField
111+
}
112+

0 commit comments

Comments
 (0)