From 51bc5fb8f74ca873cbe141e55ffaaa22b3fce885 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Thu, 24 Aug 2023 23:17:52 +0800 Subject: [PATCH] feat(counit): init counit setting service --- .../devti/settings/AutoDevSettingsState.kt | 1 - .../configurable/CoUnitSettingService.kt | 35 +++++++++++++++++++ .../configurable/CoUnitToolConfigurable.kt | 29 ++++++++++----- src/main/resources/META-INF/autodev-core.xml | 1 + 4 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 src/main/kotlin/cc/unitmesh/devti/settings/configurable/CoUnitSettingService.kt diff --git a/src/main/kotlin/cc/unitmesh/devti/settings/AutoDevSettingsState.kt b/src/main/kotlin/cc/unitmesh/devti/settings/AutoDevSettingsState.kt index 93268aa669..5e10f6979b 100644 --- a/src/main/kotlin/cc/unitmesh/devti/settings/AutoDevSettingsState.kt +++ b/src/main/kotlin/cc/unitmesh/devti/settings/AutoDevSettingsState.kt @@ -8,7 +8,6 @@ import com.intellij.util.xmlb.XmlSerializerUtil @State(name = "cc.unitmesh.devti.settings.DevtiSettingsState", storages = [Storage("DevtiSettings.xml")]) class AutoDevSettingsState : PersistentStateComponent { - var gitType = DEFAULT_GIT_TYPE var githubToken = "" var gitlabToken = "" diff --git a/src/main/kotlin/cc/unitmesh/devti/settings/configurable/CoUnitSettingService.kt b/src/main/kotlin/cc/unitmesh/devti/settings/configurable/CoUnitSettingService.kt new file mode 100644 index 0000000000..96c188934b --- /dev/null +++ b/src/main/kotlin/cc/unitmesh/devti/settings/configurable/CoUnitSettingService.kt @@ -0,0 +1,35 @@ +package cc.unitmesh.devti.settings.configurable + +import com.intellij.openapi.components.* +import com.intellij.openapi.project.Project + +val Project.coUnitSettings: CoUnitProjectSettingsService + get() = service() + +@State(name = "CoUnitProjectSettings", storages = [Storage(StoragePathMacros.WORKSPACE_FILE)]) +class CoUnitProjectSettingsService( + val project: Project, +) : SimplePersistentStateComponent(CoUnitProjectSettings()) { + val enableCoUnit: Boolean get() = state.enableCoUnit + val serverAddress: String get() = state.serverAddress + + fun modify(action: (CoUnitProjectSettings) -> Unit) { + // todo + action(state) + } + + abstract class AdProjectSettingsBase> : BaseState() { + abstract fun copy(): T + } + + class CoUnitProjectSettings : AdProjectSettingsBase() { + var enableCoUnit by property(false) + var serverAddress by property("http://localhost:8765") { it.isEmpty() } + + override fun copy(): CoUnitProjectSettings { + val state = CoUnitProjectSettings() + state.copyFrom(this) + return state + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/cc/unitmesh/devti/settings/configurable/CoUnitToolConfigurable.kt b/src/main/kotlin/cc/unitmesh/devti/settings/configurable/CoUnitToolConfigurable.kt index 9551c11fd8..30e43e77ca 100644 --- a/src/main/kotlin/cc/unitmesh/devti/settings/configurable/CoUnitToolConfigurable.kt +++ b/src/main/kotlin/cc/unitmesh/devti/settings/configurable/CoUnitToolConfigurable.kt @@ -2,40 +2,51 @@ package cc.unitmesh.devti.settings.configurable import cc.unitmesh.devti.AutoDevBundle import com.intellij.openapi.Disposable +import com.intellij.openapi.components.service import com.intellij.openapi.options.BoundConfigurable import com.intellij.openapi.project.Project import com.intellij.openapi.ui.DialogPanel import com.intellij.openapi.util.Disposer -import com.intellij.ui.dsl.builder.Cell -import com.intellij.ui.dsl.builder.Row -import com.intellij.ui.dsl.builder.panel +import com.intellij.ui.dsl.builder.* import com.intellij.ui.dsl.gridLayout.HorizontalAlign import javax.swing.JComponent import javax.swing.JTextField class CoUnitToolConfigurable(project: Project) : BoundConfigurable(AutoDevBundle.message("settings.external.counit.name")), Disposable { + private val pathToToolchainComboBox = CoUnitToolchainPathChoosingComboBox() private val serverAddress = JTextField() + + val settings = project.service() + val state = settings.state.copy() + override fun createPanel(): DialogPanel = panel { row { checkBox(AutoDevBundle.message("settings.external.counit.enable.label")) .comment(AutoDevBundle.message("settings.external.counit.enable.label.comment")) -// .bindSelected(project::enableCoUnit) + .bindSelected(state::enableCoUnit) } row(AutoDevBundle.message("settings.external.counit.server.address.label")) { fullWidthCell(serverAddress) -// .bind( -// componentGet = { it.text }, -// componentSet = { component, value -> component.text = value }, -// prop = state::additionalArguments.toMutableProperty() -// ) + .bind( + componentGet = { it.text }, + componentSet = { component, value -> component.text = value }, + prop = state::serverAddress.toMutableProperty() + ) } row(AutoDevBundle.message("settings.external.counit.location.label")) { fullWidthCell(pathToToolchainComboBox) } + + onApply { + settings.modify { + it.enableCoUnit = state.enableCoUnit + it.serverAddress = state.serverAddress + } + } } override fun dispose() { diff --git a/src/main/resources/META-INF/autodev-core.xml b/src/main/resources/META-INF/autodev-core.xml index 3b3d777df8..efbbdc6ab9 100644 --- a/src/main/resources/META-INF/autodev-core.xml +++ b/src/main/resources/META-INF/autodev-core.xml @@ -12,6 +12,7 @@ id="cc.unitmesh.devti.settings.AutoDevSettingsConfigurable" displayName="AutoDev"/> +