Skip to content

Commit 0ddbc88

Browse files
committed
feat(ui): add toolbar and popup for ThoughtPlanSketch #331
- Added a toolbar with a popup action to the ThoughtPlanSketch UI. - Removed steps 6-8 from the plan.devin files as they are no longer necessary.
1 parent d14e03b commit 0ddbc88

File tree

3 files changed

+82
-16
lines changed

3 files changed

+82
-16
lines changed

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

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,33 @@ package cc.unitmesh.devti.sketch.ui
33
import cc.unitmesh.devti.sketch.ui.code.CodeHighlightSketch
44
import cc.unitmesh.devti.sketch.ui.plan.MarkdownPlanParser
55
import cc.unitmesh.devti.sketch.ui.plan.PlanItem
6+
import com.intellij.icons.AllIcons
67
import com.intellij.lang.Language
8+
import com.intellij.openapi.actionSystem.ActionManager
9+
import com.intellij.openapi.actionSystem.AnAction
10+
import com.intellij.openapi.actionSystem.AnActionEvent
11+
import com.intellij.openapi.actionSystem.DefaultActionGroup
12+
import com.intellij.openapi.fileEditor.FileEditorManager
713
import com.intellij.openapi.project.Project
14+
import com.intellij.openapi.ui.popup.JBPopup
15+
import com.intellij.openapi.ui.popup.JBPopupFactory
16+
import com.intellij.openapi.ui.popup.util.MinimizeButton
817
import com.intellij.ui.components.JBCheckBox
918
import com.intellij.ui.components.JBPanel
1019
import com.intellij.ui.components.JBScrollPane
20+
import com.intellij.ui.components.panels.Wrapper
1121
import com.intellij.util.ui.JBEmptyBorder
1222
import com.intellij.util.ui.JBUI
23+
import com.intellij.util.ui.UIUtil
1324
import java.awt.BorderLayout
1425
import java.awt.FlowLayout
26+
import java.awt.event.MouseAdapter
27+
import java.awt.event.MouseEvent
1528
import javax.swing.Box
1629
import javax.swing.BoxLayout
1730
import javax.swing.JComponent
1831
import javax.swing.JLabel
32+
import javax.swing.JPanel
1933

2034
class ThoughtPlanSketchProvider : LanguageSketchProvider {
2135
override fun isSupported(lang: String): Boolean = lang == "plan"
@@ -43,26 +57,90 @@ class PlanSketch(
4357
layout = BoxLayout(this, BoxLayout.Y_AXIS)
4458
border = JBEmptyBorder(JBUI.insets(8))
4559
}
60+
61+
private val actionGroup = DefaultActionGroup(createConsoleActions())
62+
private val toolbar = ActionManager.getInstance().createActionToolbar("PlanSketch", actionGroup, true).apply {
63+
targetComponent = panel
64+
}
65+
66+
private val titleLabel = JLabel("Thought Plan").apply {
67+
border = JBUI.Borders.empty(0, 10)
68+
}
69+
70+
private val toolbarPanel = JPanel(BorderLayout()).apply {
71+
add(titleLabel, BorderLayout.WEST)
72+
add(toolbar.component, BorderLayout.EAST)
73+
}
74+
75+
private val toolbarWrapper = Wrapper(JBUI.Panels.simplePanel(toolbarPanel)).also {
76+
it.border = JBUI.Borders.customLine(UIUtil.getBoundsColor(), 1, 1, 1, 1)
77+
}
4678

4779
init {
4880
createPlanUI()
4981

5082
val scrollPane = JBScrollPane(contentPanel)
5183
panel.add(scrollPane, BorderLayout.CENTER)
84+
panel.add(toolbarWrapper, BorderLayout.NORTH)
85+
5286
add(panel, BorderLayout.CENTER)
5387
}
88+
89+
private fun createConsoleActions(): List<AnAction> {
90+
val popupAction = object : AnAction("Popup", "Show in popup window", AllIcons.Ide.External_link_arrow) {
91+
override fun displayTextInToolbar(): Boolean = true
92+
93+
override fun actionPerformed(e: AnActionEvent) {
94+
executePopup().mouseClicked(null)
95+
}
96+
}
97+
98+
return listOf(popupAction)
99+
}
100+
101+
private fun executePopup(): MouseAdapter = object : MouseAdapter() {
102+
override fun mouseClicked(e: MouseEvent?) {
103+
var popup: JBPopup? = null
104+
popup = JBPopupFactory.getInstance()
105+
.createComponentPopupBuilder(panel, null)
106+
.setProject(project)
107+
.setResizable(true)
108+
.setMovable(true)
109+
.setTitle("Thought Plan")
110+
.setCancelButton(MinimizeButton("Hide"))
111+
.setCancelCallback {
112+
popup?.cancel()
113+
// Return the panel to its original location
114+
remove(panel)
115+
add(panel, BorderLayout.CENTER)
116+
revalidate()
117+
repaint()
118+
true
119+
}
120+
.setFocusable(true)
121+
.setRequestFocus(true)
122+
.createPopup()
123+
124+
val editor = FileEditorManager.getInstance(project).selectedTextEditor
125+
if (editor != null) {
126+
popup.showInBestPositionFor(editor)
127+
} else {
128+
popup.showInFocusCenter()
129+
}
130+
}
131+
}
54132

55133
private fun createPlanUI() {
56134
planItems.forEachIndexed { index, planItem ->
57135
val titlePanel = JBPanel<JBPanel<*>>(FlowLayout(FlowLayout.LEFT)).apply {
58136
border = JBUI.Borders.empty()
59137
}
60138

61-
val titleText = if (planItem.completed)
62-
"<html><b>${index + 1}. ${planItem.title} ✓</b></html>"
63-
else
139+
val titleText = if (planItem.completed)
140+
"<html><b>${index + 1}. ${planItem.title} ✓</b></html>"
141+
else
64142
"<html><b>${index + 1}. ${planItem.title}</b></html>"
65-
143+
66144
val sectionLabel = JLabel(titleText)
67145
sectionLabel.border = JBUI.Borders.empty()
68146
titlePanel.add(sectionLabel)

core/src/main/resources/genius/en/code/plan.devin

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ Here is the rule you should follow:
4747
4. Propose and explain the necessary code modifications to resolve `<user.question>`, ensuring that edge cases are
4848
properly handled. Analyze these modifications before implementing them.
4949
5. Edit the source code in the repo to resolve `<user.question>`.
50-
6. If a script to reproduce the issue has been created, execute it again on the updated repository to confirm that
51-
`<user.question>` is resolved.
52-
7. It is best practice to find and run tests related to the modified files to ensure no new issues have been introduced
53-
and to confirm that these tests still pass.
54-
8. Once you have verified the solution, provide a summary of the changes made and the final status of the issue. Then
55-
use the `submit` command to provide the complete response back to the user.
5650

5751
If `<user.question>` directly contradicts any of these steps, follow the instructions from `<user.question>`
5852
first. Be thorough in your thinking process, so it's okay if it is lengthy.

core/src/main/resources/genius/zh/code/plan.devin

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ Here is the rule you should follow:
4747
4. Propose and explain the necessary code modifications to resolve `<user.question>`, ensuring that edge cases are
4848
properly handled. Analyze these modifications before implementing them.
4949
5. Edit the source code in the repo to resolve `<user.question>`.
50-
6. If a script to reproduce the issue has been created, execute it again on the updated repository to confirm that
51-
`<user.question>` is resolved.
52-
7. It is best practice to find and run tests related to the modified files to ensure no new issues have been introduced
53-
and to confirm that these tests still pass.
54-
8. Once you have verified the solution, provide a summary of the changes made and the final status of the issue. Then
55-
use the `submit` command to provide the complete response back to the user.
5650

5751
If `<user.question>` directly contradicts any of these steps, follow the instructions from `<user.question>`
5852
first. Be thorough in your thinking process, so it's okay if it is lengthy.

0 commit comments

Comments
 (0)