#java #kotlin #intellij-idea #intellij-plugin
Вопрос:
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) } }
Я не знаю, как хранить эти checkBox
textfield
значения при написании плагина intellij с использованием DSL пользовательского интерфейса Kotlin, в документации по intellij нет примера написания DSL пользовательского интерфейса kotlin
Я не знаю, как узнать checkBox
, изменилось ли значение, в приведенной выше панели кода.IsModified() всегда кажется ложным
Кроме того, я не знаю , как сохранить checkBox
textfield
значения локально после их изменения
Ответ №1:
Я решил эту проблему
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 } }