Skip to content

Commit 6c89b64

Browse files
committed
feat(core): add option to hide toolbar in CodeHighlightSketch
- Add showToolbar parameter to CodeHighlightSketch constructor- Implement logic to conditionally display the toolbar based on showToolbar flag - Update TerminalSketchProvider to hide toolbar for terminal sketches - Add Terminal icon to AutoDevIcons - Include new terminal.svg icon file
1 parent c43c33f commit 6c89b64

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

core/src/main/kotlin/cc/unitmesh/devti/AutoDevIcons.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ object AutoDevIcons {
3838
@JvmField
3939
val View: Icon = IconLoader.getIcon("/icons/view.svg", AutoDevIcons::class.java)
4040

41+
@JvmField
42+
val Terminal: Icon = IconLoader.getIcon("/icons/terminal.svg", AutoDevIcons::class.java)
43+
4144
@JvmField
4245
val Stop: Icon = IconLoader.getIcon("/icons/stop.svg", AutoDevIcons::class.java)
4346

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ interface LangSketch : Disposable {
2828
fun onDoneStream(allText: String) {}
2929
fun onComplete(code: String) {}
3030

31-
fun setupActionBar(project: Project, editor: Editor, isDeclarePackageFile: Boolean) {
32-
val toolbar = collectActionBar(isDeclarePackageFile) ?: return
31+
fun setupActionBar(project: Project, editor: Editor, isDeclarePackageFile: Boolean): ActionToolbar? {
32+
val toolbar = collectActionBar(isDeclarePackageFile) ?: return null
3333

3434
if (editor is EditorEx) {
3535
toolbar.component.setBackground(editor.backgroundColor)
@@ -46,6 +46,8 @@ interface LangSketch : Disposable {
4646
toolbar.component.setBackground(editor.backgroundColor)
4747
}
4848
})
49+
50+
return toolbar
4951
}
5052

5153
fun collectActionBar(isDeclarePackageFile: Boolean): ActionToolbar? {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.intellij.icons.AllIcons
1313
import com.intellij.ide.scratch.ScratchRootType
1414
import com.intellij.lang.Language
1515
import com.intellij.openapi.Disposable
16+
import com.intellij.openapi.actionSystem.ActionToolbar
1617
import com.intellij.openapi.actionSystem.DataProvider
1718
import com.intellij.openapi.application.ApplicationManager
1819
import com.intellij.openapi.application.ReadAction
@@ -52,7 +53,8 @@ open class CodeHighlightSketch(
5253
private var ideaLanguage: Language? = null,
5354
val editorLineThreshold: Int = 6,
5455
val fileName: String? = null,
55-
val withLeftRightBorder: Boolean = true
56+
val withLeftRightBorder: Boolean = true,
57+
val showToolbar: Boolean = true
5658
) : JBPanel<CodeHighlightSketch>(VerticalLayout(4)), DataProvider, LangSketch, Disposable {
5759
private val devinLineThreshold = 10
5860
private val minDevinLineThreshold = 1
@@ -74,6 +76,8 @@ open class CodeHighlightSketch(
7476
return this != null && this.trim().isNotEmpty()
7577
}
7678

79+
private var toolbar: ActionToolbar? = null
80+
7781
fun initEditor(text: String, fileName: String? = null) {
7882
if (hasSetupAction) return
7983
hasSetupAction = true
@@ -99,7 +103,9 @@ open class CodeHighlightSketch(
99103

100104
val isDeclarePackageFile = BuildSystemProvider.isDeclarePackageFile(fileName)
101105
if (textLanguage != null && textLanguage?.lowercase() != "markdown" && ideaLanguage != PlainTextLanguage.INSTANCE) {
102-
setupActionBar(project, editor, isDeclarePackageFile)
106+
if (showToolbar) {
107+
toolbar = setupActionBar(project, editor, isDeclarePackageFile)
108+
}
103109
} else {
104110
editorFragment?.editor?.backgroundColor = JBColor.PanelBackground
105111
editorFragment?.editor?.setBorder(JBEmptyBorder(0, 0, 0, 0))
Lines changed: 13 additions & 0 deletions
Loading

exts/ext-terminal/src/main/kotlin/cc/unitmesh/terminal/sketch/TerminalSketchProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class TerminalLangSketch(val project: Project, var content: String) : ExtensionL
7575
border = JBUI.Borders.empty(0, 10)
7676
}
7777

78-
val codeSketch = CodeHighlightSketch(project, content, CodeFence.findLanguage("bash")).apply {
78+
val codeSketch = CodeHighlightSketch(project, content, CodeFence.findLanguage("bash"), showToolbar = false).apply {
7979
border = JBUI.Borders.empty()
8080
}
8181

@@ -172,7 +172,7 @@ class TerminalLangSketch(val project: Project, var content: String) : ExtensionL
172172
executeAction = TerminalExecuteAction()
173173

174174
val showTerminalAction = object :
175-
AnAction("Show/Hide Terminal", "Show or hide the terminal", AutoDevIcons.View) {
175+
AnAction("Show/Hide Terminal", "Show or hide the terminal", AutoDevIcons.Terminal) {
176176
override fun actionPerformed(e: AnActionEvent) {
177177
toggleTerminalAction()
178178
}

0 commit comments

Comments
 (0)