generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(counit): init counit setting service
- Loading branch information
Showing
4 changed files
with
56 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/cc/unitmesh/devti/settings/configurable/CoUnitSettingService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CoUnitProjectSettingsService>() | ||
|
||
@State(name = "CoUnitProjectSettings", storages = [Storage(StoragePathMacros.WORKSPACE_FILE)]) | ||
class CoUnitProjectSettingsService( | ||
val project: Project, | ||
) : SimplePersistentStateComponent<CoUnitProjectSettingsService.CoUnitProjectSettings>(CoUnitProjectSettings()) { | ||
val enableCoUnit: Boolean get() = state.enableCoUnit | ||
val serverAddress: String get() = state.serverAddress | ||
|
||
fun modify(action: (CoUnitProjectSettings) -> Unit) { | ||
// todo | ||
action(state) | ||
} | ||
|
||
abstract class AdProjectSettingsBase<T : AdProjectSettingsBase<T>> : BaseState() { | ||
abstract fun copy(): T | ||
} | ||
|
||
class CoUnitProjectSettings : AdProjectSettingsBase<CoUnitProjectSettings>() { | ||
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters