diff --git a/gradle.properties b/gradle.properties index 3377482..65e4cbf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ pluginGroup = no.eirikb.avatest pluginName = AvaJavaScriptTestRunnerRunConfigurationGenerator -pluginVersion = 1.8.1 +pluginVersion = 1.9.0 pluginSinceBuild = 202 pluginUntilBuild = 222.* # Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl diff --git a/src/main/kotlin/no/eirikb/avatest/actions/AvaJavaScriptTestRunnerRunConfigurationGenerator.kt b/src/main/kotlin/no/eirikb/avatest/actions/AvaJavaScriptTestRunnerRunConfigurationGenerator.kt index 3e470ba..3a9481b 100644 --- a/src/main/kotlin/no/eirikb/avatest/actions/AvaJavaScriptTestRunnerRunConfigurationGenerator.kt +++ b/src/main/kotlin/no/eirikb/avatest/actions/AvaJavaScriptTestRunnerRunConfigurationGenerator.kt @@ -82,7 +82,7 @@ class AvaJavaScriptTestRunnerRunConfigurationGenerator : AnAction() { val basePath = project.basePath val relPath = if (basePath == null) fileName else currentFile.path.substring(basePath.length + 1) - val configuration = if (AppSettingsState.selectedCommand) { + val configuration = if (AppSettingsState.instance.selectedCommand) { this.createNodeJsRunConfiguration(project, fileName, relPath, testName) } else { this.createNPMRunConfiguration(project, currentFile, fileName, relPath, testName) @@ -153,7 +153,7 @@ class AvaJavaScriptTestRunnerRunConfigurationGenerator : AnAction() { return null } node.workingDirectory = project.basePath - node.inputPath = AppSettingsState.inputPath + node.inputPath = AppSettingsState.instance.inputPath if (node.inputPath == null) { val projectDir = project.guessProjectDir() node.inputPath = listOf( @@ -189,7 +189,7 @@ class AvaJavaScriptTestRunnerRunConfigurationGenerator : AnAction() { npmRunSettingsBuilder.setPackageJsonPath(packageJsonPath) npmRunSettingsBuilder.setArguments(getRunArguments(relPath, testName)) - npmRunSettingsBuilder.setScriptNames(listOf(AppSettingsState.npmScriptsText)) + npmRunSettingsBuilder.setScriptNames(listOf(AppSettingsState.instance.npmScriptsText)) val npmRunConfiguration = NpmRunConfiguration( project, diff --git a/src/main/kotlin/no/eirikb/avatest/settings/AppSettingsConfigurable.kt b/src/main/kotlin/no/eirikb/avatest/settings/AppSettingsConfigurable.kt index ce585ce..ae1a75a 100644 --- a/src/main/kotlin/no/eirikb/avatest/settings/AppSettingsConfigurable.kt +++ b/src/main/kotlin/no/eirikb/avatest/settings/AppSettingsConfigurable.kt @@ -6,6 +6,7 @@ import javax.swing.JComponent class AppSettingsConfigurable : Configurable { private var mySettingsComponent: AppSettingsComponent? = null + private val settings = AppSettingsState.instance override fun getDisplayName(): @Nls(capitalization = Nls.Capitalization.Title) String = "AVA Test Runner Run Configuration Generator" @@ -18,30 +19,31 @@ class AppSettingsConfigurable : Configurable { } override fun isModified(): Boolean { - var modifiedInputPath = mySettingsComponent!!.inputPathText != AppSettingsState.inputPath - modifiedInputPath = modifiedInputPath or (mySettingsComponent!!.inputPathText != AppSettingsState.inputPath) + var modifiedInputPath = mySettingsComponent!!.inputPathText != settings.inputPath + modifiedInputPath = + modifiedInputPath or (mySettingsComponent!!.inputPathText != settings.inputPath) - var modifiedSelectedModel = mySettingsComponent!!.selectedCommand != AppSettingsState.selectedCommand + var modifiedSelectedModel = mySettingsComponent!!.selectedCommand != settings.selectedCommand modifiedSelectedModel = - modifiedSelectedModel or (mySettingsComponent!!.selectedCommand != AppSettingsState.selectedCommand) + modifiedSelectedModel or (mySettingsComponent!!.selectedCommand != settings.selectedCommand) - var modifiedNPMScriptsText = mySettingsComponent!!.npmScriptsText != AppSettingsState.npmScriptsText + var modifiedNPMScriptsText = mySettingsComponent!!.npmScriptsText != settings.npmScriptsText modifiedNPMScriptsText = - modifiedNPMScriptsText or (mySettingsComponent!!.npmScriptsText != AppSettingsState.npmScriptsText) + modifiedNPMScriptsText or (mySettingsComponent!!.npmScriptsText != settings.npmScriptsText) return modifiedInputPath || modifiedSelectedModel || modifiedNPMScriptsText } override fun apply() { - AppSettingsState.inputPath = mySettingsComponent!!.inputPathText - AppSettingsState.selectedCommand = mySettingsComponent!!.selectedCommand - AppSettingsState.npmScriptsText = mySettingsComponent!!.npmScriptsText + settings.inputPath = mySettingsComponent!!.inputPathText + settings.selectedCommand = mySettingsComponent!!.selectedCommand + settings.npmScriptsText = mySettingsComponent!!.npmScriptsText } override fun reset() { - mySettingsComponent!!.inputPathText = AppSettingsState.inputPath - mySettingsComponent!!.selectedCommand = AppSettingsState.selectedCommand - mySettingsComponent!!.npmScriptsText = AppSettingsState.npmScriptsText + mySettingsComponent!!.inputPathText = settings.inputPath + mySettingsComponent!!.selectedCommand = settings.selectedCommand + mySettingsComponent!!.npmScriptsText = settings.npmScriptsText ?: "" } override fun disposeUIResources() { diff --git a/src/main/kotlin/no/eirikb/avatest/settings/AppSettingsState.kt b/src/main/kotlin/no/eirikb/avatest/settings/AppSettingsState.kt index 056bc8a..613fe3c 100644 --- a/src/main/kotlin/no/eirikb/avatest/settings/AppSettingsState.kt +++ b/src/main/kotlin/no/eirikb/avatest/settings/AppSettingsState.kt @@ -1,21 +1,25 @@ package no.eirikb.avatest.settings +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.components.BaseState import com.intellij.openapi.components.PersistentStateComponent import com.intellij.openapi.components.State import com.intellij.openapi.components.Storage -import com.intellij.util.xmlb.XmlSerializerUtil @State(name = "no.eirikb.avatest.settings.AppSettingsState", storages = [Storage("SdkSettingsPlugin.xml")]) -object AppSettingsState : PersistentStateComponent { - var inputPath: String? = null - var selectedCommand = true - var npmScriptsText = "" +class AppSettingsState : BaseState(), PersistentStateComponent { + var inputPath by string(null) + var selectedCommand by property(true) + var npmScriptsText by string("") - override fun getState(): AppSettingsState { - return this + companion object { + val instance: AppSettingsState + get() = ApplicationManager.getApplication().getService(AppSettingsState::class.java) } + override fun getState(): AppSettingsState = this + override fun loadState(state: AppSettingsState) { - XmlSerializerUtil.copyBean(state, this) + copyFrom(state) } }