intellij-idea - 如何在对话框中显示 IntelliJ JSON 编辑器?

标签 intellij-idea jetbrains-ide intellij-plugin intellij-idea-2016

我想在下面展示我正在为 Kotlin 和 Java 开发的插件的对话框中的编辑器。我尝试了下面的代码片段

    editorTextField.setEnabled(true);
    editorTextField.setOneLineMode(false);
    editorTextField.setFileType(new JsonFileType());

有人能指出如何实现这一点吗?

我特别需要行号、JSON 语法突出显示和代码折叠我可以看到所有代码规范 here .请帮助我学习如何在我的插件中使用它们。

JSON 编辑器:

最佳答案

class JsonOutputDialog(language: Language, project: Project, text: String) : DialogWrapper(project) {

    private val panel = JPanel(BorderLayout())

    init {
        super.setOKActionEnabled(false)

        init()

        val editorTextField = CustomEditorField(language, project, text)
        editorTextField.setOneLineMode(false)
        editorTextField.preferredSize = Dimension(800, 600)

        editorTextField.isVisible = true

        panel.add(editorTextField)

        editorTextField.setCaretPosition(0)
    }

    override fun createCenterPanel() = panel
}

class CustomEditorField(language: Language, project: Project, s: String) : LanguageTextField(language, project, s) {

    override fun createEditor(): EditorEx {
        val editor = super.createEditor()
        editor.setVerticalScrollbarVisible(true)
        editor.setHorizontalScrollbarVisible(true)

        val settings = editor.settings
        settings.isLineNumbersShown = true
        settings.isAutoCodeFoldingEnabled = true
        settings.isFoldingOutlineShown = true
        settings.isAllowSingleLogicalLineFolding = true
        settings.isRightMarginShown=true
        return editor
    }
}

这是你需要做的。这里的关键是使用 LanguageTextField 而不是 EditorTextField 并覆盖 createEditor() 方法来配置您正在寻找的所有选项,例如 Line数字和代码折叠。

关于intellij-idea - 如何在对话框中显示 IntelliJ JSON 编辑器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47954339/

相关文章:

python - Pycharm 无法将解释器从 python 2.7 更改为 3.4

java - IntelliJ 书签窗口不可见

scala - Intellij Idea scala 插件使用什么 scala 版本?

intellij-idea - 有没有办法在编辑器中突出显示自上次在 IntelliJ 中提交以来插入的文本?

java - 在 Intellij 的表单中制作一个 hello world 应用程序

python - 为什么我的 Python 程序在 IntelliJ 中出现 UnicodeDecodeError 但在命令行中却正常?

intellij-idea - Intellij 中的 Play Framework 新项目

ide - WebStorm 在编辑时保存文件

kotlin - 使用 IntelliJ IDEA 时,Kotlin 中的 "An illegal reflective access operation has occurred"是什么意思?

java - IntelliJ IDEA 虚拟机选项