Skip to content

Commit 3b9f7e4

Browse files
committed
feat(devti): restore and enhance right toolbar functionality
- Uncomment and implement createRightToolbar and createViewActionGroup methods - Add necessary imports for ActionGroup, ActionManager, ActionPlaces, ActionToolbar, and DefaultActionGroup - This change restores the right toolbar functionality, allowing users to switch between editor and preview layouts
1 parent 9df519a commit 3b9f7e4

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import cc.unitmesh.devti.sketch.ui.ExtensionLangSketch
44
import cc.unitmesh.devti.sketch.ui.LangSketch
55
import cc.unitmesh.devti.sketch.ui.code.CodeHighlightSketch
66
import cc.unitmesh.devti.util.parser.CodeFence
7-
import com.intellij.lang.Language
7+
import com.intellij.openapi.actionSystem.ActionGroup
8+
import com.intellij.openapi.actionSystem.ActionManager
9+
import com.intellij.openapi.actionSystem.ActionPlaces
10+
import com.intellij.openapi.actionSystem.ActionToolbar
11+
import com.intellij.openapi.actionSystem.DefaultActionGroup
812
import com.intellij.openapi.fileEditor.FileEditor
913
import com.intellij.openapi.fileEditor.FileEditorProvider
1014
import com.intellij.openapi.fileEditor.TextEditorWithPreview.Layout
@@ -52,23 +56,23 @@ abstract class FileEditorPreviewSketch(
5256
return VfsUtilCore.loadText(this)
5357
}
5458

55-
// fun createRightToolbar(target: JComponent): ActionToolbar {
56-
// val rightToolbar = ActionManager.getInstance()
57-
// .createActionToolbar(ActionPlaces.TEXT_EDITOR_WITH_PREVIEW, createViewActionGroup(), true)
58-
// rightToolbar.targetComponent = target
59-
// rightToolbar.isReservePlaceAutoPopupIcon = false
60-
//
61-
// return rightToolbar
62-
// }
63-
//
64-
// protected open fun createViewActionGroup(): ActionGroup {
65-
// val actionManager = ActionManager.getInstance()
66-
// return DefaultActionGroup(
67-
// actionManager.getAction("TextEditorWithPreview.Layout.EditorOnly"),
68-
// actionManager.getAction("TextEditorWithPreview.Layout.EditorAndPreview"),
69-
// actionManager.getAction("TextEditorWithPreview.Layout.PreviewOnly")
70-
// )
71-
// }
59+
fun createRightToolbar(target: JComponent): ActionToolbar {
60+
val rightToolbar = ActionManager.getInstance()
61+
.createActionToolbar(ActionPlaces.TEXT_EDITOR_WITH_PREVIEW, createViewActionGroup(), true)
62+
rightToolbar.targetComponent = target
63+
rightToolbar.isReservePlaceAutoPopupIcon = false
64+
65+
return rightToolbar
66+
}
67+
68+
protected open fun createViewActionGroup(): ActionGroup {
69+
val actionManager = ActionManager.getInstance()
70+
return DefaultActionGroup(
71+
actionManager.getAction("TextEditorWithPreview.Layout.EditorOnly"),
72+
actionManager.getAction("TextEditorWithPreview.Layout.EditorAndPreview"),
73+
actionManager.getAction("TextEditorWithPreview.Layout.PreviewOnly")
74+
)
75+
}
7276

7377
override fun dispose() {}
7478

0 commit comments

Comments
 (0)