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
@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
此外,我不知道如何在修改checkBox
、textfield
值后将其保存在本地
发布于 2021-10-11 19:53:40
我已经解决了
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
}
}
https://stackoverflow.com/questions/69529631
复制相似问题