Skip to content

Commit 099883c

Browse files
committed
refactor(devti): replace text expand/collapse button with icons #352
- Use AllIcons.General.ArrowDown and ArrowRight for expand/collapse button instead of text - Improve visual consistency with IntelliJ theme - Maintain existing functionality and layout
1 parent 4c72487 commit 099883c

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/plan/TaskSectionPanel.kt

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import cc.unitmesh.devti.gui.chat.message.ChatActionType
77
import cc.unitmesh.devti.observer.plan.AgentTaskEntry
88
import cc.unitmesh.devti.observer.plan.TaskStatus
99
import cc.unitmesh.devti.sketch.ui.AutoDevColors
10+
import com.intellij.icons.AllIcons
1011
import com.intellij.openapi.project.Project
1112
import com.intellij.ui.JBColor
1213
import com.intellij.ui.components.JBPanel
@@ -28,96 +29,96 @@ class TaskSectionPanel(
2829
private val planItem: AgentTaskEntry,
2930
private val onStatusChange: () -> Unit
3031
) : JBPanel<JBPanel<*>>(BorderLayout()) {
31-
32+
3233
private val stepsPanel = JBPanel<JBPanel<*>>()
3334
private var isExpanded = true
3435
private var expandButton: JButton? = null
3536
private var statusLabel: JLabel? = null
3637
private val scrollPane: JBScrollPane
3738
private val MAX_TITLE_LENGTH = 50
38-
39+
3940
init {
4041
layout = BorderLayout()
4142
background = JBUI.CurrentTheme.ToolWindow.background()
4243
border = CompoundBorder(
4344
BorderFactory.createMatteBorder(0, 0, 1, 0, JBColor.border()),
4445
JBUI.Borders.empty(4, 16)
4546
)
46-
47+
4748
val headerPanel = createHeaderPanel()
4849
add(headerPanel, BorderLayout.NORTH)
49-
50+
5051
stepsPanel.layout = BoxLayout(stepsPanel, BoxLayout.Y_AXIS)
5152
stepsPanel.background = JBUI.CurrentTheme.ToolWindow.background()
5253
stepsPanel.border = JBUI.Borders.emptyLeft(4)
53-
54+
5455
refreshStepsPanel()
55-
56+
5657
scrollPane = JBScrollPane(stepsPanel).apply {
5758
border = BorderFactory.createEmptyBorder()
5859
isOpaque = false
5960
viewport.isOpaque = false
6061
horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
6162
verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
6263
}
63-
64+
6465
add(scrollPane, BorderLayout.CENTER)
6566
toggleStepsVisibility(isExpanded)
6667
}
67-
68+
6869
private fun createHeaderPanel(): JPanel {
6970
val headerPanel = JBPanel<JBPanel<*>>(BorderLayout()).apply {
7071
background = JBUI.CurrentTheme.ToolWindow.background()
7172
border = JBUI.Borders.empty(2)
7273
}
73-
74+
7475
val leftPanel = JPanel(FlowLayout(FlowLayout.LEFT, 5, 0)).apply {
7576
isOpaque = false
7677
}
77-
78-
expandButton = JButton(if (isExpanded) "" else "").apply {
78+
79+
expandButton = JButton(if (isExpanded) AllIcons.General.ArrowDown else AllIcons.General.ArrowRight).apply {
7980
preferredSize = Dimension(20, 20)
8081
margin = JBUI.emptyInsets()
8182
isBorderPainted = false
8283
isContentAreaFilled = false
8384
toolTipText = if (isExpanded) "Collapse section" else "Expand section"
84-
85+
8586
addActionListener { e ->
8687
isExpanded = !isExpanded
87-
text = if (isExpanded) "" else ""
88+
icon = if (isExpanded) AllIcons.General.ArrowDown else AllIcons.General.ArrowRight
8889
toolTipText = if (isExpanded) "Collapse section" else "Expand section"
8990
toggleStepsVisibility(isExpanded)
90-
e.source = this // Ensure event propagation
91+
e.source = this
9192
}
9293
}
93-
94+
9495
leftPanel.add(expandButton)
95-
96+
9697
val statusIcon = when (planItem.status) {
9798
TaskStatus.COMPLETED -> JLabel(AutoDevIcons.Checked)
9899
TaskStatus.FAILED -> JLabel(AutoDevIcons.Error)
99100
TaskStatus.IN_PROGRESS -> JLabel(AutoDevIcons.InProgress)
100101
TaskStatus.TODO -> JLabel(AutoDevIcons.Build)
101102
}
102103
leftPanel.add(statusIcon)
103-
104+
104105
val fullTitle = "${index + 1}. ${planItem.title}"
105106
val displayTitle = if (planItem.title.length > MAX_TITLE_LENGTH) {
106107
"${index + 1}. ${planItem.title.take(MAX_TITLE_LENGTH)}..."
107108
} else {
108109
fullTitle
109110
}
110-
111+
111112
val titleLabel = JLabel(displayTitle).apply {
112113
font = font.deriveFont(Font.BOLD)
113114
toolTipText = fullTitle
114115
}
115116
leftPanel.add(titleLabel)
116-
117+
117118
val rightPanel = JPanel(FlowLayout(FlowLayout.RIGHT, 5, 0)).apply {
118119
isOpaque = false
119120
}
120-
121+
121122
statusLabel = JLabel(getStatusText(planItem.status)).apply {
122123
foreground = getStatusColor(planItem.status)
123124
font = font.deriveFont(Font.BOLD, 11f)
@@ -126,7 +127,7 @@ class TaskSectionPanel(
126127
}
127128

128129
rightPanel.add(statusLabel)
129-
130+
130131
if (planItem.status == TaskStatus.TODO || planItem.status == TaskStatus.FAILED) {
131132
val executeButton = JButton(AutoDevIcons.Run).apply {
132133
margin = JBUI.emptyInsets()
@@ -137,7 +138,7 @@ class TaskSectionPanel(
137138
}
138139
rightPanel.add(executeButton)
139140
}
140-
141+
141142
if (planItem.status == TaskStatus.FAILED) {
142143
val retryButton = JButton(AutoDevIcons.REPAIR).apply {
143144
margin = JBUI.emptyInsets()
@@ -148,67 +149,67 @@ class TaskSectionPanel(
148149
}
149150
rightPanel.add(retryButton)
150151
}
151-
152+
152153
headerPanel.add(leftPanel, BorderLayout.WEST)
153154
headerPanel.add(rightPanel, BorderLayout.EAST)
154-
155+
155156
return headerPanel
156157
}
157-
158+
158159
private fun toggleStepsVisibility(visible: Boolean) {
159160
scrollPane.isVisible = visible
160161
SwingUtilities.invokeLater {
161162
parent?.revalidate()
162163
parent?.repaint()
163164
}
164165
}
165-
166+
166167
private fun refreshStepsPanel() {
167168
stepsPanel.removeAll()
168-
169+
169170
planItem.steps.forEach { step ->
170171
val taskStepPanel = TaskStepPanel(project, step) {
171172
updateSectionStatus()
172173
updateProgressAndStatus()
173174
onStatusChange()
174175
}
175-
176+
176177
stepsPanel.add(taskStepPanel)
177178
stepsPanel.add(Box.createVerticalStrut(2)) // Reduced spacing between steps
178179
}
179180
}
180-
181+
181182
private fun executeSection() {
182183
planItem.updateStatus(TaskStatus.IN_PROGRESS)
183184
updateProgressAndStatus()
184-
185+
185186
AutoDevToolWindowFactory.Companion.sendToSketchToolWindow(project, ChatActionType.SKETCH) { ui, _ ->
186187
val content = planItem.title + "\n" + planItem.steps.joinToString("\n") { " - " + it.step }
187188
ui.sendInput(AutoDevBundle.message("sketch.plan.finish.task") + content)
188189
}
189-
190+
190191
refreshStepsPanel()
191192
revalidate()
192193
repaint()
193194
}
194-
195+
195196
fun updateSectionStatus() {
196197
planItem.updateCompletionStatus()
197198
updateProgressAndStatus()
198199
}
199-
200+
200201
private fun updateProgressAndStatus() {
201202
statusLabel?.text = getStatusText(planItem.status)
202203
statusLabel?.foreground = getStatusColor(planItem.status)
203-
204+
204205
removeAll()
205206
add(createHeaderPanel(), BorderLayout.NORTH)
206207
add(stepsPanel, BorderLayout.CENTER)
207-
208+
208209
revalidate()
209210
repaint()
210211
}
211-
212+
212213
private fun getStatusText(status: TaskStatus): String {
213214
return when (status) {
214215
TaskStatus.COMPLETED -> "Completed"
@@ -217,7 +218,7 @@ class TaskSectionPanel(
217218
TaskStatus.TODO -> "To Do"
218219
}
219220
}
220-
221+
221222
private fun getStatusColor(status: TaskStatus): JBColor {
222223
return when (status) {
223224
TaskStatus.COMPLETED -> AutoDevColors.COMPLETED_STATUS

0 commit comments

Comments
 (0)