Skip to content

Commit

Permalink
Merge pull request #25 from makeevrserg/compose-feature
Browse files Browse the repository at this point in the history
- fix saved value
- add klibs.kstorage
- fix scopes
- fix packages
  • Loading branch information
makeevrserg authored Feb 13, 2025
2 parents 8a6a29f + 687945a commit 2e5daac
Show file tree
Hide file tree
Showing 27 changed files with 212 additions and 160 deletions.
2 changes: 2 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ repositories {

dependencies {
implementation(libs.kotlin.coroutines.swing)
api(libs.klibs.kstorage)
api(libs.klibs.mikro.core)
}

intellij {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.makeevrserg.mvikotlin.intellij.core

import com.intellij.openapi.ui.DialogPanel
import com.intellij.openapi.ui.DialogWrapper
import com.makeevrserg.mvikotlin.intellij.dependencies.Dependencies
import javax.swing.JComponent
@Suppress("MaxLineLength")
/**
Expand All @@ -11,9 +10,8 @@ import javax.swing.JComponent
* @see <a href="https://github.com/levinzonr/jetpack-compose-ui-arch-plugin">levinzonr/jetpack-compose-ui-arch-plugin</a>
*/
abstract class BaseDialog : DialogWrapper(true) {

lateinit var panel: DialogPanel
protected val dialogScope = Dependencies.mainScope

override fun createCenterPanel(): JComponent? {
panel = createPanel()
return panel
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.makeevrserg.mvikotlin.intellij.core

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.swing.Swing
import kotlin.coroutines.CoroutineContext

interface CoroutineFeature : CoroutineScope {
class Io : CoroutineFeature {
override val coroutineContext: CoroutineContext = Dispatchers.IO + SupervisorJob()
}

class Main : CoroutineFeature {
override val coroutineContext: CoroutineContext = Dispatchers.Swing + SupervisorJob()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package com.makeevrserg.mvikotlin.intellij.data

import com.makeevrserg.mvikotlin.intellij.data.model.BootstrapperType
import com.makeevrserg.mvikotlin.intellij.data.model.ComponentChildType
import com.makeevrserg.mvikotlin.intellij.storage.StorageValue
import com.makeevrserg.mvikotlin.intellij.krate.IntellijMutableKrate

interface StorageApi {
val useKlibsStorageValue: StorageValue<Boolean>
val createStorePackageStorageValue: StorageValue<Boolean>
val decomposeMviIntegrationStorageValue: StorageValue<Boolean>
val createBootstrapperStorageValue: StorageValue<BootstrapperType>
val componentChildTypeStorageValue: StorageValue<ComponentChildType>
fun createNameStorageValue(): StorageValue<String>
val useKlibsStorageValue: IntellijMutableKrate<Boolean>
val createStorePackageStorageValue: IntellijMutableKrate<Boolean>
val decomposeMviIntegrationStorageValue: IntellijMutableKrate<Boolean>
val createBootstrapperStorageValue: IntellijMutableKrate<BootstrapperType>
val componentChildTypeStorageValue: IntellijMutableKrate<ComponentChildType>
fun createNameStorageValue(): IntellijMutableKrate<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,50 @@ import com.intellij.ide.util.PropertiesComponent
import com.makeevrserg.mvikotlin.intellij.data.StorageApi
import com.makeevrserg.mvikotlin.intellij.data.model.BootstrapperType
import com.makeevrserg.mvikotlin.intellij.data.model.ComponentChildType
import com.makeevrserg.mvikotlin.intellij.storage.StorageValue
import com.makeevrserg.mvikotlin.intellij.storage.impl.BooleanStorageValue
import com.makeevrserg.mvikotlin.intellij.storage.impl.InMemoryStorageValue
import com.makeevrserg.mvikotlin.intellij.krate.IntellijMutableKrate
import com.makeevrserg.mvikotlin.intellij.krate.impl.BooleanStorageValue
import com.makeevrserg.mvikotlin.intellij.krate.impl.EnumStorageValue
import com.makeevrserg.mvikotlin.intellij.krate.impl.inMemoryStorageValue

class StorageApiImpl(private val propertiesComponent: PropertiesComponent) : StorageApi {
override val useKlibsStorageValue: StorageValue<Boolean> by lazy {
override val useKlibsStorageValue: IntellijMutableKrate<Boolean> by lazy {
BooleanStorageValue(
key = "USE_KLIBS_FACTORY",
properties = propertiesComponent,
default = false
)
}
override val createStorePackageStorageValue: StorageValue<Boolean> by lazy {
override val createStorePackageStorageValue: IntellijMutableKrate<Boolean> by lazy {
BooleanStorageValue(
key = "CREATE_STORE_PACKAGE",
properties = propertiesComponent,
default = false
)
}
override val decomposeMviIntegrationStorageValue: StorageValue<Boolean> by lazy {
override val decomposeMviIntegrationStorageValue: IntellijMutableKrate<Boolean> by lazy {
BooleanStorageValue(
key = "DECOMPOSE_MVI_INTEGRATION",
properties = propertiesComponent,
default = false
)
}
override val createBootstrapperStorageValue: StorageValue<BootstrapperType>
get() = InMemoryStorageValue(
override val createBootstrapperStorageValue: IntellijMutableKrate<BootstrapperType>
get() = EnumStorageValue(
key = "CREATE_BOOTSTRAPPER",
initial = BootstrapperType.NONE
initial = BootstrapperType.NONE,
properties = propertiesComponent,
entries = BootstrapperType.entries
)
override val componentChildTypeStorageValue: StorageValue<ComponentChildType>
get() = InMemoryStorageValue(
override val componentChildTypeStorageValue: IntellijMutableKrate<ComponentChildType>
get() = EnumStorageValue(
key = "COMPONENT_CHILD_TYPE",
initial = ComponentChildType.NONE
initial = ComponentChildType.NONE,
properties = propertiesComponent,
entries = ComponentChildType.entries
)

override fun createNameStorageValue(): StorageValue<String> = InMemoryStorageValue(
override fun createNameStorageValue(): IntellijMutableKrate<String> = inMemoryStorageValue(
key = "NAME",
initial = ""
default = "",
)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.project.Project
import com.makeevrserg.mvikotlin.intellij.core.TemplateGenerator

/**
* Author
*
* @see <a href="https://github.com/levinzonr/jetpack-compose-ui-arch-plugin">levinzonr/jetpack-compose-ui-arch-plugin</a>
*/
@Suppress("MaxLineLength")
class ProjectDependencies(val project: Project?) {
val generator = TemplateGenerator(project!!)
val editor: FileEditorManager = FileEditorManager.getInstance(project!!)
val properties: PropertiesComponent = PropertiesComponent.getInstance(project!!)
class ProjectDependencies(project: Project) {
val generator = TemplateGenerator(project)
val editor: FileEditorManager = FileEditorManager.getInstance(project)
val properties: PropertiesComponent = PropertiesComponent.getInstance(project)
val application: Application = ApplicationManager.getApplication()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.makeevrserg.mvikotlin.intellij.krate

import ru.astrainteractive.klibs.kstorage.api.MutableKrate

interface IntellijMutableKrate<T> : MutableKrate<T> {
val key: String

var value: T
get() = loadAndGet()
set(value) {
save(value)
}

fun asPair(): Pair<String, T> {
return key to value
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.makeevrserg.mvikotlin.intellij.krate.impl

import com.intellij.ide.util.PropertiesComponent
import com.makeevrserg.mvikotlin.intellij.krate.IntellijMutableKrate
import ru.astrainteractive.klibs.kstorage.api.MutableKrate
import ru.astrainteractive.klibs.kstorage.api.impl.DefaultMutableKrate

internal class BooleanStorageValue(
override val key: String,
private val properties: PropertiesComponent,
private val default: Boolean
) : IntellijMutableKrate<Boolean>,
MutableKrate<Boolean> by DefaultMutableKrate(
factory = { default },
saver = { properties.setValue(key, it) },
loader = { properties.getBoolean(key, default) }
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.makeevrserg.mvikotlin.intellij.krate.impl

import com.intellij.ide.util.PropertiesComponent
import com.makeevrserg.mvikotlin.intellij.krate.IntellijMutableKrate
import ru.astrainteractive.klibs.kstorage.api.MutableKrate
import ru.astrainteractive.klibs.kstorage.api.impl.DefaultMutableKrate
import kotlin.enums.EnumEntries

internal class EnumStorageValue<T : Enum<T>>(
override val key: String,
private val properties: PropertiesComponent,
initial: T,
entries: EnumEntries<T>
) : IntellijMutableKrate<T>,
MutableKrate<T> by DefaultMutableKrate(
factory = { initial },
saver = {
properties.setValue(key, initial.ordinal.toString())
},
loader = {
val index = properties.getValue(key)?.toIntOrNull() ?: 0
entries.getOrNull(index) ?: entries.first()
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.makeevrserg.mvikotlin.intellij.krate.impl

import com.makeevrserg.mvikotlin.intellij.krate.IntellijMutableKrate
import ru.astrainteractive.klibs.kstorage.api.MutableKrate
import ru.astrainteractive.klibs.kstorage.api.impl.DefaultMutableKrate

internal fun <T> inMemoryStorageValue(
key: String,
default: T
): IntellijMutableKrate<T> {
var value = default
return object :
IntellijMutableKrate<T>,
MutableKrate<T> by DefaultMutableKrate(
factory = { value },
saver = { newValue -> value = newValue },
loader = { value }
) {
override val key: String = key
}
}

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ makeevrserg.java.ktarget=17
# Project
makeevrserg.project.name=MVIKotlin-IntelliJ-Plugin
makeevrserg.project.group=com.makeevrserg.mvikotlin.intellij.plugin
makeevrserg.project.version.string=0.4.0
makeevrserg.project.version.string=0.5.0
makeevrserg.project.description=IntelliJ Plugin for MVIKotlin/Decompose library
makeevrserg.project.developers=makeevrserg|Makeev Roman|[email protected]
makeevrserg.project.url=https://empireprojekt.ru
Expand Down
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ kotlin-coroutines = "1.10.1" # https://github.com/Kotlin/kotlinx.coroutines
jetbrains-intellij = "1.17.4" # https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#ide-configuration
# klibs
klibs-gradleplugin = "1.5.1" # https://github.com/makeevrserg/gradle-plugin
klibs-kstorage = "3.2.6" # https://github.com/makeevrserg/klibs.kstorage
klibs-mikro = "1.8.15" # https://github.com/makeevrserg/klibs.mikro

[libraries]
kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin-version" }
kotlin-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "kotlin-coroutines" }
klibs-kstorage = { module = "ru.astrainteractive.klibs:kstorage", version.ref = "klibs-kstorage" }
klibs-mikro-core = { module = "ru.astrainteractive.klibs:mikro-core", version.ref = "klibs-mikro" }

[plugins]
# Kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.psi.PsiDirectory
import com.makeevrserg.mvikotlin.intellij.component.feature.ComponentFeature
import com.makeevrserg.mvikotlin.intellij.component.ui.ComponentDialog
import com.makeevrserg.mvikotlin.intellij.data.impl.StorageApiImpl
import com.makeevrserg.mvikotlin.intellij.dependencies.ProjectDependencies

class ComponentAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val directory = e.getData(CommonDataKeys.PSI_ELEMENT) as PsiDirectory
val properties: PropertiesComponent = PropertiesComponent.getInstance(e.project!!)
val project = e.project ?: return
val directory = e.getData(CommonDataKeys.PSI_ELEMENT) as? PsiDirectory ?: return
val properties: PropertiesComponent = PropertiesComponent.getInstance(project)
val storageApi = StorageApiImpl(properties)
val viewModel = ComponentViewModel(storageApi, directory, ProjectDependencies(e.project))
val viewModel = ComponentFeature(storageApi, directory, ProjectDependencies(project))
ComponentDialog(viewModel).show()
}
}

This file was deleted.

Loading

0 comments on commit 2e5daac

Please sign in to comment.