Skip to content

Commit 6873629

Browse files
committed
refactor(ui): adjust layout and logic for toolwindow mode #331
- Rename `isInPopup` to `isInToolwindow` for clarity. - Adjust border insets and layout logic based on toolwindow mode. - Move execute task button to only show for TODO tasks. - Update task status handling to mark steps as completed. - Improve terminal output formatting for sketch.
1 parent 5b1be1a commit 6873629

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

core/src/main/kotlin/cc/unitmesh/devti/observer/plan/AgentTaskEntry.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ data class AgentTaskEntry(
2626

2727
if (this.status == TaskStatus.COMPLETED) {
2828
completed = true
29+
steps.forEach { it.completed = true }
2930
return
3031
}
3132

@@ -37,6 +38,10 @@ data class AgentTaskEntry(
3738
steps.any { it.status == TaskStatus.IN_PROGRESS } -> TaskStatus.IN_PROGRESS
3839
else -> TaskStatus.TODO
3940
}
41+
42+
if (completed) {
43+
status = TaskStatus.COMPLETED
44+
}
4045
}
4146

4247
/**

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

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import com.intellij.openapi.project.Project
2020
import com.intellij.openapi.wm.ToolWindowManager
2121
import com.intellij.ui.components.JBCheckBox
2222
import com.intellij.ui.components.JBPanel
23-
import com.intellij.ui.components.JBScrollPane
2423
import com.intellij.ui.components.panels.Wrapper
2524
import com.intellij.util.ui.JBEmptyBorder
2625
import com.intellij.util.ui.JBUI
@@ -49,12 +48,12 @@ class PlanSketch(
4948
private val project: Project,
5049
private var content: String,
5150
private var agentTaskItems: MutableList<AgentTaskEntry>,
52-
private val isInPopup: Boolean = false
51+
private val isInToolwindow: Boolean = false
5352
) : JBPanel<PlanSketch>(BorderLayout()), ExtensionLangSketch {
5453
private val panel = JBPanel<PlanSketch>(BorderLayout())
5554
private val contentPanel = JBPanel<PlanSketch>().apply {
5655
layout = BoxLayout(this, BoxLayout.Y_AXIS)
57-
border = JBEmptyBorder(JBUI.insets(8))
56+
border = JBEmptyBorder(JBUI.insets(4))
5857
}
5958

6059
private val actionGroup = DefaultActionGroup(createToolbar(project))
@@ -86,7 +85,7 @@ class PlanSketch(
8685
}
8786

8887
private val toolbarPanel = JPanel(BorderLayout()).apply {
89-
if (!isInPopup) {
88+
if (!isInToolwindow) {
9089
add(titleLabel, BorderLayout.WEST)
9190
add(toolbar.component, BorderLayout.EAST)
9291
}
@@ -99,35 +98,21 @@ class PlanSketch(
9998
init {
10099
createPlanUI()
101100

102-
val scrollPane = JBScrollPane(contentPanel)
103-
panel.add(scrollPane, BorderLayout.CENTER)
104101
panel.add(toolbarWrapper, BorderLayout.NORTH)
105102

106-
add(panel, BorderLayout.CENTER)
103+
if (isInToolwindow) {
104+
border = JBUI.Borders.empty(8)
105+
}
106+
107+
add(contentPanel, BorderLayout.CENTER)
107108
}
108109

109110
private fun createPlanUI() {
110111
agentTaskItems.forEachIndexed { index, planItem ->
111-
val titlePanel = JBPanel<JBPanel<*>>(FlowLayout(FlowLayout.LEFT)).apply {
112-
border = JBUI.Borders.empty()
113-
}
114-
115-
val executeTaskButton = JButton(AllIcons.Actions.Execute).apply {
116-
border = BorderFactory.createEmptyBorder()
117-
isOpaque = true
118-
preferredSize = Dimension(24, 24)
119-
toolTipText = "Execute Task"
120-
121-
addActionListener {
122-
AutoDevToolWindowFactory.sendToSketchToolWindow(project, ChatActionType.SKETCH) { ui, _ ->
123-
val allSteps = planItem.steps.joinToString("\n") { it.step }
124-
ui.sendInput(AutoDevBundle.message("sketch.plan.finish.task") + allSteps)
125-
}
126-
}
112+
val titlePanel = JBPanel<JBPanel<*>>(FlowLayout(FlowLayout.LEFT, 2, 0)).apply {
113+
border = JBUI.Borders.empty(2)
127114
}
128115

129-
titlePanel.add(executeTaskButton)
130-
131116
// Check if all tasks in the section are completed
132117
updateSectionCompletionStatus(planItem)
133118

@@ -146,19 +131,35 @@ class PlanSketch(
146131
}
147132

148133
val sectionLabel = JLabel(titleText)
149-
sectionLabel.border = JBUI.Borders.empty()
134+
sectionLabel.border = JBUI.Borders.emptyLeft(2)
135+
136+
if (planItem.status == TaskStatus.TODO && planItem.completed == false) {
137+
val executeTaskButton = JButton(AllIcons.Actions.Execute).apply {
138+
border = BorderFactory.createEmptyBorder()
139+
isOpaque = true
140+
preferredSize = Dimension(20, 20)
141+
toolTipText = "Execute Task"
142+
143+
addActionListener {
144+
AutoDevToolWindowFactory.sendToSketchToolWindow(project, ChatActionType.SKETCH) { ui, _ ->
145+
val allSteps = planItem.steps.joinToString("\n") { it.step }
146+
ui.sendInput(AutoDevBundle.message("sketch.plan.finish.task") + allSteps)
147+
}
148+
}
149+
}
150+
titlePanel.add(executeTaskButton)
151+
}
152+
150153
titlePanel.add(sectionLabel)
151154
contentPanel.add(titlePanel)
152155

153156
planItem.steps.forEachIndexed { taskIndex, task ->
154-
val taskPanel = JBPanel<JBPanel<*>>(FlowLayout(FlowLayout.LEFT)).apply {
155-
border = JBUI.Borders.empty()
157+
val taskPanel = JBPanel<JBPanel<*>>(FlowLayout(FlowLayout.LEFT, 2, 0)).apply {
158+
border = JBUI.Borders.empty(1, 16, 1, 0)
156159
}
157160

158-
// First create task label with appropriate styling based on status
159161
val taskLabel = createStyledTaskLabel(task)
160162

161-
// Create a custom status indicator based on task status
162163
val statusIcon = when (task.status) {
163164
TaskStatus.COMPLETED -> JLabel(AllIcons.Actions.Checked)
164165
TaskStatus.FAILED -> JLabel(AllIcons.General.Error)
@@ -193,7 +194,7 @@ class PlanSketch(
193194
val executeButton = JButton(AllIcons.Actions.Execute).apply {
194195
border = BorderFactory.createEmptyBorder()
195196
isOpaque = true
196-
preferredSize = Dimension(24, 24)
197+
preferredSize = Dimension(20, 20)
197198
toolTipText = "Execute"
198199

199200
addActionListener {
@@ -318,7 +319,7 @@ class PlanSketch(
318319
}
319320

320321
override fun onComplete(context: String) {
321-
if (!isInPopup) {
322+
if (!isInToolwindow) {
322323
val agentPlans = MarkdownPlanParser.parse(content).toMutableList()
323324
updatePlan(agentPlans)
324325
project.getService(AgentStateService::class.java).updatePlan(agentPlans)

exts/ext-terminal/src/main/kotlin/cc/unitmesh/terminal/sketch/TerminalSketchProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class TerminalSketchProvider : LanguageSketchProvider {
111111
try {
112112
val output = terminalWidget!!::class.java.getMethod("getText")
113113
.invoke(terminalWidget) as String
114-
sendToSketch(project, output)
114+
sendToSketch(project, "Help me to solve this issue:\n```bash\n$output\n```\n")
115115
} catch (e: Exception) {
116116
AutoDevNotifications.notify(project, "Failed to send to Sketch")
117117
}

0 commit comments

Comments
 (0)