Skip to content

Commit 7b4ae3e

Browse files
committed
feat(gui): add change summary to AutoDevPlannerToolWindow #352
- Add PlannerResultSummary component to display change summary - Update AutoDevPlannerToolWindow to include change summary panel - Modify AgentStateService to publish change updates - Extend PlanUpdateListener with onUpdateChange method
1 parent 2929794 commit 7b4ae3e

File tree

4 files changed

+91
-8
lines changed

4 files changed

+91
-8
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.intellij.openapi.application.ApplicationManager
1212
import com.intellij.openapi.application.runInEdt
1313
import com.intellij.openapi.project.Project
1414
import com.intellij.openapi.ui.SimpleToolWindowPanel
15+
import com.intellij.openapi.vcs.changes.Change
1516
import com.intellij.openapi.wm.ToolWindowManager
1617
import com.intellij.ui.dsl.builder.panel
1718
import com.intellij.util.ui.JBUI
@@ -33,6 +34,9 @@ class AutoDevPlannerToolWindow(val project: Project) : SimpleToolWindowPanel(tru
3334
private var currentCallback: ((String) -> Unit)? = null
3435
private val planPanel: JPanel by lazy { createPlanPanel() }
3536
private lateinit var issueInputPanel: ShadowPanel
37+
private val plannerResultSummary: PlannerResultSummary by lazy {
38+
PlannerResultSummary(project, mutableListOf())
39+
}
3640

3741
init {
3842
if (content.isBlank()) {
@@ -42,6 +46,7 @@ class AutoDevPlannerToolWindow(val project: Project) : SimpleToolWindowPanel(tru
4246
contentPanel.add(planPanel, BorderLayout.CENTER)
4347
}
4448

49+
add(contentPanel, BorderLayout.CENTER)
4550
add(contentPanel, BorderLayout.CENTER)
4651

4752
connection.subscribe(PlanUpdateListener.Companion.TOPIC, object : PlanUpdateListener {
@@ -57,6 +62,13 @@ class AutoDevPlannerToolWindow(val project: Project) : SimpleToolWindowPanel(tru
5762
}
5863
}
5964
}
65+
66+
override fun onUpdateChange(changes: MutableList<Change>) {
67+
plannerResultSummary.updateChanges(changes)
68+
69+
contentPanel.revalidate()
70+
contentPanel.repaint()
71+
}
6072
})
6173
}
6274

@@ -145,6 +157,7 @@ class AutoDevPlannerToolWindow(val project: Project) : SimpleToolWindowPanel(tru
145157

146158
contentPanel.removeAll()
147159
contentPanel.add(planPanel, BorderLayout.CENTER)
160+
contentPanel.add(plannerResultSummary, BorderLayout.SOUTH)
148161
contentPanel.revalidate()
149162
contentPanel.repaint()
150163

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

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,78 @@ package cc.unitmesh.devti.gui.planner
22

33
import com.intellij.openapi.project.Project
44
import com.intellij.openapi.vcs.changes.Change
5+
import com.intellij.ui.components.JBLabel
6+
import com.intellij.ui.components.JBScrollPane
7+
import com.intellij.util.ui.JBUI
8+
import com.intellij.util.ui.UIUtil
9+
import java.awt.BorderLayout
10+
import java.awt.GridLayout
11+
import javax.swing.JPanel
512

613
class PlannerResultSummary(
7-
val project: Project,
8-
val changes: List<Change>
9-
) {
10-
fun getDiffContent(change: Change) {
11-
change.afterRevision?.file?.name
12-
change.afterRevision?.file?.path
13-
change.afterRevision?.content
14+
private val project: Project,
15+
private var changes: List<Change>
16+
) : JPanel(BorderLayout()) {
17+
18+
private val changesPanel = JPanel(GridLayout(0, 1, 0, 5))
19+
private val statsLabel = JBLabel("暂无变更")
20+
21+
init {
22+
background = JBUI.CurrentTheme.ToolWindow.background()
23+
border = JBUI.Borders.empty(10)
24+
25+
val titlePanel = JPanel(BorderLayout()).apply {
26+
isOpaque = false
27+
border = JBUI.Borders.emptyBottom(10)
28+
add(JBLabel("执行结果").apply {
29+
font = font.deriveFont(font.size + 2f)
30+
foreground = UIUtil.getLabelForeground()
31+
}, BorderLayout.WEST)
32+
add(statsLabel, BorderLayout.EAST)
33+
}
34+
35+
add(titlePanel, BorderLayout.NORTH)
36+
37+
changesPanel.isOpaque = false
38+
add(JBScrollPane(changesPanel).apply {
39+
border = JBUI.Borders.empty()
40+
background = background
41+
}, BorderLayout.CENTER)
42+
43+
updateChanges(changes.toMutableList())
1444
}
15-
}
45+
46+
fun updateChanges(changes: MutableList<Change>) {
47+
this.changes = changes
48+
changesPanel.removeAll()
49+
50+
if (changes.isEmpty()) {
51+
statsLabel.text = "暂无变更"
52+
changesPanel.add(JBLabel("暂无代码变更").apply {
53+
foreground = UIUtil.getLabelDisabledForeground()
54+
})
55+
} else {
56+
statsLabel.text = "${changes.size} 个文件变更"
57+
58+
// 简单显示变更的文件
59+
changes.forEach { change ->
60+
val filePath = change.virtualFile?.path ?: "未知文件"
61+
val fileName = filePath.substringAfterLast('/')
62+
63+
val changeType = when {
64+
change.type == Change.Type.NEW -> "新增"
65+
change.type == Change.Type.DELETED -> "删除"
66+
change.type == Change.Type.MOVED -> "移动"
67+
else -> "修改"
68+
}
69+
70+
changesPanel.add(JBLabel("$changeType: $fileName").apply {
71+
toolTipText = filePath
72+
})
73+
}
74+
}
75+
76+
revalidate()
77+
repaint()
78+
}
79+
}

core/src/main/kotlin/cc/unitmesh/devti/observer/agent/AgentStateService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class AgentStateService(val project: Project) {
3838
val shelvedChange = createShelvedChange(project, path, change)
3939
if (shelvedChange != null) {
4040
state.changes.add(shelvedChange.change)
41+
42+
ApplicationManager.getApplication().messageBus
43+
.syncPublisher(PlanUpdateListener.TOPIC)
44+
.onUpdateChange(state.changes)
4145
}
4246
}
4347

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package cc.unitmesh.devti.observer.plan
22

3+
import com.intellij.openapi.vcs.changes.Change
34
import com.intellij.util.messages.Topic
45
import java.util.*
56

67
@FunctionalInterface
78
interface PlanUpdateListener: EventListener {
89
fun onPlanUpdate(items: MutableList<AgentTaskEntry>)
10+
fun onUpdateChange(changes: MutableList<Change>)
911

1012
companion object {
1113
@Topic.AppLevel

0 commit comments

Comments
 (0)