Skip to content

Commit ca03efe

Browse files
authored
81 configuration reseting when restarting webstorm (#82)
* Fix AppSettingsState persisting AppSettingsState didn't persist between restart of IntelliJ. Fixed by copying the approach of https://github.com/AMPivovarov/FastMouseScroll/blob/master/src/main/kotlin/FMSSettings.kt with Service and State split a part, and making it as class, and more Java-ish. * Bump version Doing a minor since the state setup is quite different.
1 parent e1a7ad4 commit ca03efe

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
pluginGroup = no.eirikb.avatest
55
pluginName = AvaJavaScriptTestRunnerRunConfigurationGenerator
6-
pluginVersion = 1.8.1
6+
pluginVersion = 1.9.0
77
pluginSinceBuild = 202
88
pluginUntilBuild = 222.*
99
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl

src/main/kotlin/no/eirikb/avatest/actions/AvaJavaScriptTestRunnerRunConfigurationGenerator.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class AvaJavaScriptTestRunnerRunConfigurationGenerator : AnAction() {
8282
val basePath = project.basePath
8383
val relPath = if (basePath == null) fileName else currentFile.path.substring(basePath.length + 1)
8484

85-
val configuration = if (AppSettingsState.selectedCommand) {
85+
val configuration = if (AppSettingsState.instance.selectedCommand) {
8686
this.createNodeJsRunConfiguration(project, fileName, relPath, testName)
8787
} else {
8888
this.createNPMRunConfiguration(project, currentFile, fileName, relPath, testName)
@@ -153,7 +153,7 @@ class AvaJavaScriptTestRunnerRunConfigurationGenerator : AnAction() {
153153
return null
154154
}
155155
node.workingDirectory = project.basePath
156-
node.inputPath = AppSettingsState.inputPath
156+
node.inputPath = AppSettingsState.instance.inputPath
157157
if (node.inputPath == null) {
158158
val projectDir = project.guessProjectDir()
159159
node.inputPath = listOf(
@@ -189,7 +189,7 @@ class AvaJavaScriptTestRunnerRunConfigurationGenerator : AnAction() {
189189
npmRunSettingsBuilder.setPackageJsonPath(packageJsonPath)
190190

191191
npmRunSettingsBuilder.setArguments(getRunArguments(relPath, testName))
192-
npmRunSettingsBuilder.setScriptNames(listOf(AppSettingsState.npmScriptsText))
192+
npmRunSettingsBuilder.setScriptNames(listOf(AppSettingsState.instance.npmScriptsText))
193193

194194
val npmRunConfiguration = NpmRunConfiguration(
195195
project,

src/main/kotlin/no/eirikb/avatest/settings/AppSettingsConfigurable.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import javax.swing.JComponent
66

77
class AppSettingsConfigurable : Configurable {
88
private var mySettingsComponent: AppSettingsComponent? = null
9+
private val settings = AppSettingsState.instance
910

1011
override fun getDisplayName(): @Nls(capitalization = Nls.Capitalization.Title) String =
1112
"AVA Test Runner Run Configuration Generator"
@@ -18,30 +19,31 @@ class AppSettingsConfigurable : Configurable {
1819
}
1920

2021
override fun isModified(): Boolean {
21-
var modifiedInputPath = mySettingsComponent!!.inputPathText != AppSettingsState.inputPath
22-
modifiedInputPath = modifiedInputPath or (mySettingsComponent!!.inputPathText != AppSettingsState.inputPath)
22+
var modifiedInputPath = mySettingsComponent!!.inputPathText != settings.inputPath
23+
modifiedInputPath =
24+
modifiedInputPath or (mySettingsComponent!!.inputPathText != settings.inputPath)
2325

24-
var modifiedSelectedModel = mySettingsComponent!!.selectedCommand != AppSettingsState.selectedCommand
26+
var modifiedSelectedModel = mySettingsComponent!!.selectedCommand != settings.selectedCommand
2527
modifiedSelectedModel =
26-
modifiedSelectedModel or (mySettingsComponent!!.selectedCommand != AppSettingsState.selectedCommand)
28+
modifiedSelectedModel or (mySettingsComponent!!.selectedCommand != settings.selectedCommand)
2729

28-
var modifiedNPMScriptsText = mySettingsComponent!!.npmScriptsText != AppSettingsState.npmScriptsText
30+
var modifiedNPMScriptsText = mySettingsComponent!!.npmScriptsText != settings.npmScriptsText
2931
modifiedNPMScriptsText =
30-
modifiedNPMScriptsText or (mySettingsComponent!!.npmScriptsText != AppSettingsState.npmScriptsText)
32+
modifiedNPMScriptsText or (mySettingsComponent!!.npmScriptsText != settings.npmScriptsText)
3133

3234
return modifiedInputPath || modifiedSelectedModel || modifiedNPMScriptsText
3335
}
3436

3537
override fun apply() {
36-
AppSettingsState.inputPath = mySettingsComponent!!.inputPathText
37-
AppSettingsState.selectedCommand = mySettingsComponent!!.selectedCommand
38-
AppSettingsState.npmScriptsText = mySettingsComponent!!.npmScriptsText
38+
settings.inputPath = mySettingsComponent!!.inputPathText
39+
settings.selectedCommand = mySettingsComponent!!.selectedCommand
40+
settings.npmScriptsText = mySettingsComponent!!.npmScriptsText
3941
}
4042

4143
override fun reset() {
42-
mySettingsComponent!!.inputPathText = AppSettingsState.inputPath
43-
mySettingsComponent!!.selectedCommand = AppSettingsState.selectedCommand
44-
mySettingsComponent!!.npmScriptsText = AppSettingsState.npmScriptsText
44+
mySettingsComponent!!.inputPathText = settings.inputPath
45+
mySettingsComponent!!.selectedCommand = settings.selectedCommand
46+
mySettingsComponent!!.npmScriptsText = settings.npmScriptsText ?: ""
4547
}
4648

4749
override fun disposeUIResources() {
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
package no.eirikb.avatest.settings
22

3+
import com.intellij.openapi.application.ApplicationManager
4+
import com.intellij.openapi.components.BaseState
35
import com.intellij.openapi.components.PersistentStateComponent
46
import com.intellij.openapi.components.State
57
import com.intellij.openapi.components.Storage
6-
import com.intellij.util.xmlb.XmlSerializerUtil
78

89
@State(name = "no.eirikb.avatest.settings.AppSettingsState", storages = [Storage("SdkSettingsPlugin.xml")])
9-
object AppSettingsState : PersistentStateComponent<AppSettingsState?> {
10-
var inputPath: String? = null
11-
var selectedCommand = true
12-
var npmScriptsText = ""
10+
class AppSettingsState : BaseState(), PersistentStateComponent<AppSettingsState> {
11+
var inputPath by string(null)
12+
var selectedCommand by property(true)
13+
var npmScriptsText by string("")
1314

14-
override fun getState(): AppSettingsState {
15-
return this
15+
companion object {
16+
val instance: AppSettingsState
17+
get() = ApplicationManager.getApplication().getService(AppSettingsState::class.java)
1618
}
1719

20+
override fun getState(): AppSettingsState = this
21+
1822
override fun loadState(state: AppSettingsState) {
19-
XmlSerializerUtil.copyBean(state, this)
23+
copyFrom(state)
2024
}
2125
}

0 commit comments

Comments
 (0)