@@ -87,9 +87,8 @@ class AutoDevPlannerToolWindow(val project: Project) : SimpleToolWindowPanel(tru
87
87
88
88
private fun switchToView (view : PlannerView ) {
89
89
if (currentView?.viewType == view.viewType) return
90
-
91
90
contentPanel.removeAll()
92
-
91
+
93
92
currentView = view
94
93
view.initialize(this )
95
94
@@ -130,7 +129,6 @@ class AutoDevPlannerToolWindow(val project: Project) : SimpleToolWindowPanel(tru
130
129
131
130
inner class PlanView : PlannerView {
132
131
override val viewType = PlannerViewType .PLAN
133
-
134
132
override fun initialize (window : AutoDevPlannerToolWindow ) {
135
133
val planPanel = panel {
136
134
row {
@@ -147,7 +145,6 @@ class AutoDevPlannerToolWindow(val project: Project) : SimpleToolWindowPanel(tru
147
145
148
146
inner class EditorView : PlannerView {
149
147
override val viewType = PlannerViewType .EDITOR
150
-
151
148
override fun initialize (window : AutoDevPlannerToolWindow ) {
152
149
val editPlanPanel = EditPlanPanel (
153
150
project = project,
@@ -209,39 +206,34 @@ class AutoDevPlannerToolWindow(val project: Project) : SimpleToolWindowPanel(tru
209
206
}
210
207
211
208
companion object {
212
- fun showPlanEditor (project : Project , planText : String , callback : (String ) -> Unit ) {
213
- val toolWindow =
214
- ToolWindowManager .Companion .getInstance(project)
215
- .getToolWindow(AutoDevPlannerToolWindowFactory .Companion .PlANNER_ID )
216
- if (toolWindow != null ) {
217
- val content = toolWindow.contentManager.getContent(0 )
218
- val plannerWindow = content?.component as ? AutoDevPlannerToolWindow
219
-
220
- plannerWindow?.let {
221
- it.currentCallback = callback
222
- if (planText.isNotEmpty() && planText != it.content) {
223
- it.content = planText
224
- }
225
-
226
- it.switchToView(it.EditorView ())
227
- toolWindow.show()
228
- }
229
- }
230
- }
231
-
232
- fun showIssueInput (project : Project ) {
233
- val toolWindow = ToolWindowManager .Companion .getInstance(project).getToolWindow(
234
- AutoDevPlannerToolWindowFactory .Companion .PlANNER_ID
235
- )
209
+ private fun withPlannerWindow (project : Project , action : (AutoDevPlannerToolWindow ) -> Unit ) {
210
+ val toolWindow = ToolWindowManager .getInstance(project)
211
+ .getToolWindow(AutoDevPlannerToolWindowFactory .Companion .PlANNER_ID )
236
212
if (toolWindow == null ) return
237
213
238
214
val content = toolWindow.contentManager.getContent(0 )
239
215
val plannerWindow = content?.component as ? AutoDevPlannerToolWindow
240
216
241
217
plannerWindow?.let {
242
- it.switchToView (it. IssueInputView () )
218
+ action (it)
243
219
toolWindow.show()
244
220
}
245
221
}
222
+
223
+ fun showPlanEditor (project : Project , planText : String , callback : (String ) -> Unit ) {
224
+ withPlannerWindow(project) { plannerWindow ->
225
+ plannerWindow.currentCallback = callback
226
+ if (planText.isNotEmpty() && planText != plannerWindow.content) {
227
+ plannerWindow.content = planText
228
+ }
229
+ plannerWindow.switchToView(plannerWindow.EditorView ())
230
+ }
231
+ }
232
+
233
+ fun showIssueInput (project : Project ) {
234
+ withPlannerWindow(project) { plannerWindow ->
235
+ plannerWindow.switchToView(plannerWindow.IssueInputView ())
236
+ }
237
+ }
246
238
}
247
239
}
0 commit comments