idea-plugin / arrow.meta.ide.dsl.ui.toolwindow / ToolWindowSyntax / toolWindowWithEditor

toolWindowWithEditor

open fun ToolWindowSyntax.toolWindowWithEditor(project: Project, fileType: LanguageFileType, readOnly: Boolean, text: String, register: JPanel.(Editor, Project) -> Unit = { it, _ -> add(it.component) }, layoutManager: LayoutManager = BorderLayout(), editor: Editor = editor(project, fileType, readOnly, text), dispose: EditorFactory.(Editor) -> Unit = { releaseEditor(it) }): JPanel

constructs a JPanel with an Editor inside.

import arrow.meta.ide.IdePlugin
import arrow.meta.ide.IdeMetaPlugin
import arrow.meta.ide.resources.ArrowIcons
import arrow.meta.ide.invoke
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.wm.ToolWindowAnchor
import org.jetbrains.kotlin.idea.KotlinFileType

val IdeMetaPlugin.editorToolwindow: IdePlugin
  get() = "TestEditor in Toolwindow" {
    meta(
      addToolWindowFromAction(
        "TestEditor",
        "Unique",
        ArrowIcons.ICON4,
        content = { project, toolWindow ->
          toolWindowWithEditor(
            project = project,
            fileType = KotlinFileType.INSTANCE,
            readOnly = false,
            text = "val hello = 'Hello World'",
            register = { editor, _ ->
              add(editor.component) // register the editor to the displayed root content
              editor.appendText("// Add more code, execute tasks or register more UI components to the editor")
            })
        },
        anchor = ToolWindowAnchor.BOTTOM
      )
    )
  }

fun Editor.appendText(text: String): Unit =
  ApplicationManager.getApplication().runReadAction { document.setText(document.text + text) }

Parameters

dispose - needs to be implemented using at least EditorFactory.releaseEditor, which is the default implementation.

layoutManager - check all SubTypes for various use-cases.

See Also

addToolWindowFromAction

Do you like Arrow?

Arrow Org
<