@@ -37,6 +37,9 @@ import java.awt.BorderLayout
37
37
import java.awt.Dimension
38
38
import java.awt.FontMetrics
39
39
import javax.swing.JComponent
40
+ import javax.swing.JPanel
41
+ import javax.swing.JButton
42
+ import javax.swing.Box
40
43
import java.util.concurrent.atomic.AtomicBoolean
41
44
42
45
class AutoDevPlannerToolWindowFactory : ToolWindowFactory , ToolWindowManagerListener , DumbAware {
@@ -74,7 +77,7 @@ class AutoDevPlanerTooWindow(val project: Project) : SimpleToolWindowPanel(true,
74
77
override fun getName (): @NlsActions .ActionText String? = " AutoDev Planer"
75
78
var connection = ApplicationManager .getApplication().messageBus.connect(this )
76
79
77
- val content = """ 1. 分析当前Blog功能结构(✓)
80
+ var content = """ 1. 分析当前Blog功能结构(✓)
78
81
- 当前Blog功能分散在entity(BlogPost)、service、controller层,采用贫血模型
79
82
- domain.Blog类存在但未充分使用,需要明确领域模型边界
80
83
@@ -100,9 +103,28 @@ class AutoDevPlanerTooWindow(val project: Project) : SimpleToolWindowPanel(true,
100
103
- 修改现有测试用例
101
104
- 添加领域模型单元测试"""
102
105
var planSketch: PlanSketch = PlanSketch (project, content, MarkdownPlanParser .parse(content).toMutableList(), true )
106
+
107
+ private var markdownEditor: MarkdownLanguageField ? = null
108
+ private val contentPanel = JPanel (BorderLayout ())
109
+ private var isEditorMode = false
110
+ private var currentCallback: ((String ) -> Unit )? = null
111
+ private val planPanel: JPanel by lazy { createPlanPanel() }
103
112
104
113
init {
105
- val planPanel = panel {
114
+ contentPanel.add(planPanel, BorderLayout .CENTER )
115
+ add(contentPanel, BorderLayout .CENTER )
116
+
117
+ connection.subscribe(PlanUpdateListener .TOPIC , object : PlanUpdateListener {
118
+ override fun onPlanUpdate (items : MutableList <AgentTaskEntry >) {
119
+ if (! isEditorMode) {
120
+ planSketch.updatePlan(items)
121
+ }
122
+ }
123
+ })
124
+ }
125
+
126
+ private fun createPlanPanel (): JPanel {
127
+ return panel {
106
128
row {
107
129
cell(planSketch)
108
130
.fullWidth()
@@ -115,48 +137,85 @@ class AutoDevPlanerTooWindow(val project: Project) : SimpleToolWindowPanel(true,
115
137
)
116
138
background = JBUI .CurrentTheme .ToolWindow .background()
117
139
}
140
+ }
118
141
119
- add(planPanel, BorderLayout .CENTER )
120
-
121
- connection.subscribe(PlanUpdateListener .TOPIC , object : PlanUpdateListener {
122
- override fun onPlanUpdate (items : MutableList <AgentTaskEntry >) {
123
- planSketch.updatePlan(items)
124
- }
125
- })
142
+ private fun switchToEditorView () {
143
+ if (isEditorMode) return
144
+
145
+ if (markdownEditor == null ) {
146
+ markdownEditor = MarkdownLanguageField (project, content, " Edit your plan here..." , " plan.md" )
147
+ } else {
148
+ markdownEditor?.text = content
149
+ }
150
+
151
+ val buttonPanel = JPanel (BorderLayout ())
152
+ val buttonsBox = Box .createHorizontalBox().apply {
153
+ add(JButton (" Save" ).apply {
154
+ addActionListener {
155
+ val newContent = markdownEditor?.text ? : " "
156
+ switchToPlanView(newContent)
157
+ currentCallback?.invoke(newContent)
158
+ }
159
+ })
160
+ add(Box .createHorizontalStrut(10 ))
161
+ add(JButton (" Cancel" ).apply {
162
+ addActionListener {
163
+ switchToPlanView()
164
+ }
165
+ })
166
+ }
167
+ buttonPanel.add(buttonsBox, BorderLayout .EAST )
168
+ buttonPanel.border = JBUI .Borders .empty(5 )
169
+
170
+ // Switch views
171
+ contentPanel.removeAll()
172
+ val editorPanel = JPanel (BorderLayout ())
173
+ editorPanel.add(JBScrollPane (markdownEditor), BorderLayout .CENTER )
174
+ editorPanel.add(buttonPanel, BorderLayout .SOUTH )
175
+
176
+ contentPanel.add(editorPanel, BorderLayout .CENTER )
177
+ contentPanel.revalidate()
178
+ contentPanel.repaint()
179
+
180
+ isEditorMode = true
181
+ }
182
+
183
+ private fun switchToPlanView (newContent : String? = null) {
184
+ if (newContent != null && newContent != content) {
185
+ content = newContent
186
+
187
+ val parsedItems = MarkdownPlanParser .parse(newContent).toMutableList()
188
+ planSketch.updatePlan(parsedItems)
189
+ }
190
+
191
+ contentPanel.removeAll()
192
+ contentPanel.add(planPanel, BorderLayout .CENTER )
193
+ contentPanel.revalidate()
194
+ contentPanel.repaint()
195
+
196
+ isEditorMode = false
126
197
}
127
198
128
199
override fun dispose () {
129
-
200
+ markdownEditor = null
130
201
}
131
202
132
203
companion object {
133
204
fun showPlanEditor (project : Project , planText : String , callback : (String ) -> Unit ) {
134
- val dialog = object : DialogWrapper (project) {
135
- private val markdownEditor =
136
- MarkdownLanguageField (project, planText, " Edit your plan here... " , " plan.md " )
137
-
138
- init {
139
- title = " Edit Plan "
140
- // Ensure the text is properly set
141
- if (markdownEditor.text.isEmpty () && planText.isNotEmpty() ) {
142
- markdownEditor.text = planText
205
+ val toolWindow = ToolWindowManager .getInstance (project).getToolWindow( AutoDevPlannerToolWindowFactory . PlANNER_ID )
206
+ if (toolWindow != null ) {
207
+ val content = toolWindow.contentManager.getContent( 0 )
208
+ val plannerWindow = content?.component as ? AutoDevPlanerTooWindow
209
+
210
+ plannerWindow?. let {
211
+ it.currentCallback = callback
212
+ if (planText.isNotEmpty () && planText != it.content ) {
213
+ it.content = planText
143
214
}
144
- init ()
145
- }
146
-
147
- override fun createCenterPanel (): JComponent {
148
- val panel = JBScrollPane (markdownEditor)
149
- panel.preferredSize = Dimension (800 , 600 )
150
- return panel
151
- }
152
-
153
- override fun doOKAction () {
154
- super .doOKAction()
155
- callback(markdownEditor.text)
215
+ it.switchToEditorView()
216
+ toolWindow.show()
156
217
}
157
218
}
158
-
159
- dialog.show()
160
219
}
161
220
}
162
221
}
@@ -188,14 +247,10 @@ private class MarkdownLanguageField(
188
247
val scheme = EditorColorsUtil .getColorSchemeForBackground(this .colorsScheme.defaultBackground)
189
248
this .colorsScheme = this .createBoundColorSchemeDelegate(scheme)
190
249
191
- val metrics: FontMetrics = getFontMetrics(font)
192
- val columnWidth = metrics.charWidth(' m' )
193
- isOneLineMode = false
194
- preferredSize = Dimension (50 * columnWidth, 30 * metrics.height)
195
-
196
250
settings.isLineNumbersShown = true
197
- settings.isLineMarkerAreaShown = true
198
- settings.isFoldingOutlineShown = true
251
+ settings.isLineMarkerAreaShown = false
252
+ settings.isFoldingOutlineShown = false
253
+ settings.isUseSoftWraps = true
199
254
}
200
255
}
201
256
}
0 commit comments