Skip to content

Commit 377ecd4

Browse files
committed
refactor(sketch): remove AutoSketchMode and clean up imports #257
- Delete AutoSketchMode.kt and related functionality. - Clean up imports and organize code in SketchToolWindow.kt. - Remove unused dependencies and simplify UI logic
1 parent 190e459 commit 377ecd4

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cc.unitmesh.devti.sketch
2+
3+
import com.intellij.openapi.components.Service
4+
import com.intellij.openapi.components.service
5+
import com.intellij.openapi.project.Project
6+
7+
@Service(Service.Level.PROJECT)
8+
class AutoSketchMode() {
9+
var isEnable: Boolean = false
10+
11+
companion object {
12+
fun getInstance(project: Project): AutoSketchMode {
13+
return project.service<AutoSketchMode>()
14+
}
15+
}
16+
}

core/src/main/kotlin/cc/unitmesh/devti/sketch/SketchToolWindow.kt

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package cc.unitmesh.devti.sketch
22

33
import cc.unitmesh.devti.alignRight
4-
import cc.unitmesh.devti.gui.chat.*
4+
import cc.unitmesh.devti.gui.chat.ChatCodingService
55
import cc.unitmesh.devti.gui.chat.message.ChatActionType
66
import cc.unitmesh.devti.gui.chat.ui.AutoDevInputSection
77
import cc.unitmesh.devti.inline.AutoDevInlineChatService
88
import cc.unitmesh.devti.inline.fullHeight
99
import cc.unitmesh.devti.inline.fullWidth
10+
import cc.unitmesh.devti.provider.RunService
1011
import cc.unitmesh.devti.sketch.ui.ExtensionLangSketch
11-
import cc.unitmesh.devti.util.parser.CodeFence
12-
import cc.unitmesh.devti.sketch.ui.highlight.CodeHighlightSketch
1312
import cc.unitmesh.devti.sketch.ui.LangSketch
1413
import cc.unitmesh.devti.sketch.ui.LanguageSketchProvider
14+
import cc.unitmesh.devti.sketch.ui.highlight.CodeHighlightSketch
15+
import cc.unitmesh.devti.util.parser.CodeFence
1516
import com.intellij.icons.AllIcons
17+
import com.intellij.ide.scratch.ScratchRootType
1618
import com.intellij.openapi.Disposable
1719
import com.intellij.openapi.application.runInEdt
1820
import com.intellij.openapi.editor.Editor
@@ -21,12 +23,12 @@ import com.intellij.openapi.project.Project
2123
import com.intellij.openapi.ui.DialogPanel
2224
import com.intellij.openapi.ui.NullableComponent
2325
import com.intellij.openapi.ui.SimpleToolWindowPanel
26+
import com.intellij.psi.PsiManager
2427
import com.intellij.ui.components.JBLabel
2528
import com.intellij.ui.components.JBScrollPane
2629
import com.intellij.ui.components.panels.VerticalLayout
2730
import com.intellij.ui.dsl.builder.panel
2831
import com.intellij.util.ui.JBUI
29-
import com.sun.java.accessibility.util.AWTEventMonitor.addActionListener
3032
import java.awt.BorderLayout
3133
import java.awt.Dimension
3234
import java.awt.Toolkit
@@ -35,12 +37,7 @@ import java.awt.event.KeyAdapter
3537
import java.awt.event.KeyEvent
3638
import java.awt.event.MouseAdapter
3739
import java.awt.event.MouseEvent
38-
import javax.swing.BorderFactory
39-
import javax.swing.JButton
40-
import javax.swing.JPanel
41-
import javax.swing.JProgressBar
42-
import javax.swing.ScrollPaneConstants
43-
import javax.swing.SwingUtilities
40+
import javax.swing.*
4441

4542
class SketchToolWindow(val project: Project, val editor: Editor?, private val showInput: Boolean = false) :
4643
SimpleToolWindowPanel(true, true),
@@ -79,12 +76,9 @@ class SketchToolWindow(val project: Project, val editor: Editor?, private val sh
7976

8077
private var panelContent: DialogPanel = panel {
8178
if (showInput) {
82-
// 开启 AI 降临模式(全自动化) with toggle
8379
row {
8480
checkBox("AI 降临模式(全自动化)").apply {
85-
addActionListener {
86-
///
87-
}
81+
AutoSketchMode.getInstance(project).isEnable = this.component.isSelected
8882
}
8983
}
9084
}
@@ -246,6 +240,28 @@ class SketchToolWindow(val project: Project, val editor: Editor?, private val sh
246240
progressBar.isIndeterminate = false
247241
progressBar.isVisible = false
248242
scrollToBottom()
243+
244+
if (AutoSketchMode.getInstance(project).isEnable) {
245+
startAutoSketchMode(text)
246+
}
247+
}
248+
249+
250+
fun startAutoSketchMode(text: String) {
251+
val codeFenceList = CodeFence.parseAll(text)
252+
val devinCodeFence = codeFenceList.filter { it.language.displayName == "DevIn" }
253+
254+
devinCodeFence.forEach {
255+
val scratchFile = ScratchRootType.getInstance()
256+
.createScratchFile(project, "sketch.shire", it.language, it.text)
257+
?: return
258+
259+
val psiFile = PsiManager.getInstance(project).findFile(scratchFile)
260+
?: return
261+
262+
RunService.provider(project, scratchFile)
263+
?.runFile(project, scratchFile, psiFile, isFromToolAction = true)
264+
}
249265
}
250266

251267
private fun scrollToBottom() {

0 commit comments

Comments
 (0)