首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在使用Kotlin UI DSL编写intellij插件时,如何在设置中存储控件的值?

在使用Kotlin UI DSL编写intellij插件时,如何在设置中存储控件的值?
EN

Stack Overflow用户
提问于 2021-10-11 16:34:09
回答 1查看 38关注 0票数 0
代码语言:javascript
运行
复制
class OsuModeConfigurable: BoundConfigurable(
    displayName = "Osu! Mode",
    "osu mode"
) {

    private val log = logger<OsuModeConfigurable>()
    private val settings = AppSettingsState().getInstance()

    private val panel = panel {

        titledRow("Primary") {
            row {
                 checkBox("Enable Osu! Mode", isSelected = settings.enableMode)
            }
            row {
                checkBox("Enable Combo Counter", isSelected = settings.enableComboCounter)
            }
            row {
                checkBox("Enable Cursor Explosions", isSelected = settings.enableCursorExplosions)
            }
            row {
                cell {
                    label("Explosion size:")
                    intTextField(
                        getter = { 6 },
                        setter = { it },
                        range = IntRange(1, 10)
                    )
                }
                row {
                    comment("The size of the explosions. For value X, the height is set to X rem and the width to X ch")
                }
            }
        }
        titledRow("Other") {
            row {
                cell {
                    label("Github:")
                    browserLink("intellij osu mode plugin", "https://github.com/Nthily/intellij-osu-mode-plugin")
                }
            }
            row {
                cell {
                    label("Author:")
                    label("Nthily")
                }
            }
            row {
                cell {
                    label("Version:")
                    label("1.0")
                }
            }
        }
    }

    override fun createPanel(): DialogPanel {
        return panel
    }

    override fun isModified(): Boolean {
        return panel.isModified()
    }

    override fun apply() {
        panel.apply()
    }

    override fun reset() {
        panel.reset()
    }
}

AppSettingsState.kt

代码语言:javascript
运行
复制
@State(
    name = "Osu! Mode",
    storages = [
        Storage("osuMode.xml")
    ]
)
class AppSettingsState: PersistentStateComponent<AppSettingsState> {

    var enableMode = true
    var enableCursorExplosions = true
    var enableComboCounter = true

    fun getInstance(): AppSettingsState {
        return ApplicationManager.getApplication().getService(AppSettingsState::class.java)
    }

    override fun getState(): AppSettingsState {
        return this
    }

    override fun loadState(appSettingState: AppSettingsState) {
        XmlSerializerUtil.copyBean(state, this)
    }
}

在使用Kotlin UI textfield编写intellij插件时,我不知道如何存储这些kotlin UI,intellij上的文档没有编写kotlin UI DSL的示例

我不知道如何获取checkBox值是否已更改,在上面的代码中,panel.isModified()似乎总是为false

此外,我不知道如何在修改checkBoxtextfield值后将其保存在本地

EN

回答 1

Stack Overflow用户

发布于 2021-10-11 19:53:40

我已经解决了

代码语言:javascript
运行
复制
class OsuModeConfigurable: BoundConfigurable(
    displayName = "Osu! Mode",
    "osu mode"
) {

    private val log = logger<OsuModeConfigurable>()
    private val settings = AppSettingsState().getInstance()

    private lateinit var box: CellBuilder<JBCheckBox>

    private var panel = panel {

        titledRow("Primary") {
            row {
                 box = checkBox("Enable Osu! Mode")
            }
            row {
                checkBox("Enable Combo Counter")
            }
            row {
                checkBox("Enable Cursor Explosions")
            }
            row {
                cell {
                    label("Explosion size:")
                    intTextField(
                        getter = { 6 },
                        setter = { it },
                        range = IntRange(1, 10)
                    )
                }
                row {
                    comment("The size of the explosions. For value X, the height is set to X rem and the width to X ch")
                }
            }
        }
        titledRow("Other") {
            row {
                cell {
                    label("Github:")
                    browserLink("intellij osu mode plugin", "https://github.com/Nthily/intellij-osu-mode-plugin")
                }
            }
            row {
                cell {
                    label("Author:")
                    label("Nthily")
                }
            }
            row {
                cell {
                    label("Version:")
                    label("1.0")
                }
            }
        }
    }

    override fun createPanel(): DialogPanel {
        return panel
    }

    override fun isModified(): Boolean {

        return settings.enableMode != box.component.isSelected
    }

    override fun apply() {
        settings.enableMode = box.component.isSelected
    }

    override fun reset() {
        box.component.isSelected = settings.enableMode
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69529631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档