@@ -7,6 +7,7 @@ import cc.unitmesh.devti.gui.chat.message.ChatActionType
7
7
import cc.unitmesh.devti.observer.plan.AgentTaskEntry
8
8
import cc.unitmesh.devti.observer.plan.TaskStatus
9
9
import cc.unitmesh.devti.sketch.ui.AutoDevColors
10
+ import com.intellij.icons.AllIcons
10
11
import com.intellij.openapi.project.Project
11
12
import com.intellij.ui.JBColor
12
13
import com.intellij.ui.components.JBPanel
@@ -28,96 +29,96 @@ class TaskSectionPanel(
28
29
private val planItem : AgentTaskEntry ,
29
30
private val onStatusChange : () -> Unit
30
31
) : JBPanel<JBPanel<*>>(BorderLayout ()) {
31
-
32
+
32
33
private val stepsPanel = JBPanel <JBPanel <* >>()
33
34
private var isExpanded = true
34
35
private var expandButton: JButton ? = null
35
36
private var statusLabel: JLabel ? = null
36
37
private val scrollPane: JBScrollPane
37
38
private val MAX_TITLE_LENGTH = 50
38
-
39
+
39
40
init {
40
41
layout = BorderLayout ()
41
42
background = JBUI .CurrentTheme .ToolWindow .background()
42
43
border = CompoundBorder (
43
44
BorderFactory .createMatteBorder(0 , 0 , 1 , 0 , JBColor .border()),
44
45
JBUI .Borders .empty(4 , 16 )
45
46
)
46
-
47
+
47
48
val headerPanel = createHeaderPanel()
48
49
add(headerPanel, BorderLayout .NORTH )
49
-
50
+
50
51
stepsPanel.layout = BoxLayout (stepsPanel, BoxLayout .Y_AXIS )
51
52
stepsPanel.background = JBUI .CurrentTheme .ToolWindow .background()
52
53
stepsPanel.border = JBUI .Borders .emptyLeft(4 )
53
-
54
+
54
55
refreshStepsPanel()
55
-
56
+
56
57
scrollPane = JBScrollPane (stepsPanel).apply {
57
58
border = BorderFactory .createEmptyBorder()
58
59
isOpaque = false
59
60
viewport.isOpaque = false
60
61
horizontalScrollBarPolicy = ScrollPaneConstants .HORIZONTAL_SCROLLBAR_NEVER
61
62
verticalScrollBarPolicy = ScrollPaneConstants .VERTICAL_SCROLLBAR_AS_NEEDED
62
63
}
63
-
64
+
64
65
add(scrollPane, BorderLayout .CENTER )
65
66
toggleStepsVisibility(isExpanded)
66
67
}
67
-
68
+
68
69
private fun createHeaderPanel (): JPanel {
69
70
val headerPanel = JBPanel <JBPanel <* >>(BorderLayout ()).apply {
70
71
background = JBUI .CurrentTheme .ToolWindow .background()
71
72
border = JBUI .Borders .empty(2 )
72
73
}
73
-
74
+
74
75
val leftPanel = JPanel (FlowLayout (FlowLayout .LEFT , 5 , 0 )).apply {
75
76
isOpaque = false
76
77
}
77
-
78
- expandButton = JButton (if (isExpanded) " ▼ " else " ▶ " ).apply {
78
+
79
+ expandButton = JButton (if (isExpanded) AllIcons . General . ArrowDown else AllIcons . General . ArrowRight ).apply {
79
80
preferredSize = Dimension (20 , 20 )
80
81
margin = JBUI .emptyInsets()
81
82
isBorderPainted = false
82
83
isContentAreaFilled = false
83
84
toolTipText = if (isExpanded) " Collapse section" else " Expand section"
84
-
85
+
85
86
addActionListener { e ->
86
87
isExpanded = ! isExpanded
87
- text = if (isExpanded) " ▼ " else " ▶ "
88
+ icon = if (isExpanded) AllIcons . General . ArrowDown else AllIcons . General . ArrowRight
88
89
toolTipText = if (isExpanded) " Collapse section" else " Expand section"
89
90
toggleStepsVisibility(isExpanded)
90
- e.source = this // Ensure event propagation
91
+ e.source = this
91
92
}
92
93
}
93
-
94
+
94
95
leftPanel.add(expandButton)
95
-
96
+
96
97
val statusIcon = when (planItem.status) {
97
98
TaskStatus .COMPLETED -> JLabel (AutoDevIcons .Checked )
98
99
TaskStatus .FAILED -> JLabel (AutoDevIcons .Error )
99
100
TaskStatus .IN_PROGRESS -> JLabel (AutoDevIcons .InProgress )
100
101
TaskStatus .TODO -> JLabel (AutoDevIcons .Build )
101
102
}
102
103
leftPanel.add(statusIcon)
103
-
104
+
104
105
val fullTitle = " ${index + 1 } . ${planItem.title} "
105
106
val displayTitle = if (planItem.title.length > MAX_TITLE_LENGTH ) {
106
107
" ${index + 1 } . ${planItem.title.take(MAX_TITLE_LENGTH )} ..."
107
108
} else {
108
109
fullTitle
109
110
}
110
-
111
+
111
112
val titleLabel = JLabel (displayTitle).apply {
112
113
font = font.deriveFont(Font .BOLD )
113
114
toolTipText = fullTitle
114
115
}
115
116
leftPanel.add(titleLabel)
116
-
117
+
117
118
val rightPanel = JPanel (FlowLayout (FlowLayout .RIGHT , 5 , 0 )).apply {
118
119
isOpaque = false
119
120
}
120
-
121
+
121
122
statusLabel = JLabel (getStatusText(planItem.status)).apply {
122
123
foreground = getStatusColor(planItem.status)
123
124
font = font.deriveFont(Font .BOLD , 11f )
@@ -126,7 +127,7 @@ class TaskSectionPanel(
126
127
}
127
128
128
129
rightPanel.add(statusLabel)
129
-
130
+
130
131
if (planItem.status == TaskStatus .TODO || planItem.status == TaskStatus .FAILED ) {
131
132
val executeButton = JButton (AutoDevIcons .Run ).apply {
132
133
margin = JBUI .emptyInsets()
@@ -137,7 +138,7 @@ class TaskSectionPanel(
137
138
}
138
139
rightPanel.add(executeButton)
139
140
}
140
-
141
+
141
142
if (planItem.status == TaskStatus .FAILED ) {
142
143
val retryButton = JButton (AutoDevIcons .REPAIR ).apply {
143
144
margin = JBUI .emptyInsets()
@@ -148,67 +149,67 @@ class TaskSectionPanel(
148
149
}
149
150
rightPanel.add(retryButton)
150
151
}
151
-
152
+
152
153
headerPanel.add(leftPanel, BorderLayout .WEST )
153
154
headerPanel.add(rightPanel, BorderLayout .EAST )
154
-
155
+
155
156
return headerPanel
156
157
}
157
-
158
+
158
159
private fun toggleStepsVisibility (visible : Boolean ) {
159
160
scrollPane.isVisible = visible
160
161
SwingUtilities .invokeLater {
161
162
parent?.revalidate()
162
163
parent?.repaint()
163
164
}
164
165
}
165
-
166
+
166
167
private fun refreshStepsPanel () {
167
168
stepsPanel.removeAll()
168
-
169
+
169
170
planItem.steps.forEach { step ->
170
171
val taskStepPanel = TaskStepPanel (project, step) {
171
172
updateSectionStatus()
172
173
updateProgressAndStatus()
173
174
onStatusChange()
174
175
}
175
-
176
+
176
177
stepsPanel.add(taskStepPanel)
177
178
stepsPanel.add(Box .createVerticalStrut(2 )) // Reduced spacing between steps
178
179
}
179
180
}
180
-
181
+
181
182
private fun executeSection () {
182
183
planItem.updateStatus(TaskStatus .IN_PROGRESS )
183
184
updateProgressAndStatus()
184
-
185
+
185
186
AutoDevToolWindowFactory .Companion .sendToSketchToolWindow(project, ChatActionType .SKETCH ) { ui, _ ->
186
187
val content = planItem.title + " \n " + planItem.steps.joinToString(" \n " ) { " - " + it.step }
187
188
ui.sendInput(AutoDevBundle .message(" sketch.plan.finish.task" ) + content)
188
189
}
189
-
190
+
190
191
refreshStepsPanel()
191
192
revalidate()
192
193
repaint()
193
194
}
194
-
195
+
195
196
fun updateSectionStatus () {
196
197
planItem.updateCompletionStatus()
197
198
updateProgressAndStatus()
198
199
}
199
-
200
+
200
201
private fun updateProgressAndStatus () {
201
202
statusLabel?.text = getStatusText(planItem.status)
202
203
statusLabel?.foreground = getStatusColor(planItem.status)
203
-
204
+
204
205
removeAll()
205
206
add(createHeaderPanel(), BorderLayout .NORTH )
206
207
add(stepsPanel, BorderLayout .CENTER )
207
-
208
+
208
209
revalidate()
209
210
repaint()
210
211
}
211
-
212
+
212
213
private fun getStatusText (status : TaskStatus ): String {
213
214
return when (status) {
214
215
TaskStatus .COMPLETED -> " Completed"
@@ -217,7 +218,7 @@ class TaskSectionPanel(
217
218
TaskStatus .TODO -> " To Do"
218
219
}
219
220
}
220
-
221
+
221
222
private fun getStatusColor (status : TaskStatus ): JBColor {
222
223
return when (status) {
223
224
TaskStatus .COMPLETED -> AutoDevColors .COMPLETED_STATUS
0 commit comments