Skip to content

Commit 611b055

Browse files
authored
Add setting panel (#40)
* Add setting panel Makes it possible to set "inputPath", which is where AVA will be run as/from. * Bump version
1 parent ff69196 commit 611b055

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
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.3.9
6+
pluginVersion = 1.4.0
77
pluginSinceBuild = 202
88
pluginUntilBuild = 999.*
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager
2020
import com.intellij.openapi.wm.ToolWindowId
2121
import com.intellij.psi.PsiElement
2222
import com.jetbrains.nodejs.run.NodeJsRunConfiguration
23+
import no.eirikb.avatest.settings.AppSettingsState
2324
import no.eirikb.avatest.utils.getTestNameByClearUnnecessaryString
2425
import java.nio.file.Paths
2526

@@ -69,7 +70,7 @@ class AvaJavaScriptTestRunnerRunConfigurationGenerator : AnAction() {
6970
return
7071
}
7172
node.workingDirectory = basePath
72-
node.inputPath = "node_modules/ava/cli.js"
73+
node.inputPath = AppSettingsState.inputPath
7374
if (testName != null) {
7475
node.name = "ava $fileName $testName"
7576
node.applicationParameters = "-m \"$testName\" -v $relPath"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package no.eirikb.avatest.settings
2+
3+
import com.intellij.ui.components.JBLabel
4+
import com.intellij.ui.components.JBTextField
5+
import com.intellij.util.ui.FormBuilder
6+
import javax.swing.JPanel
7+
8+
class AppSettingsComponent {
9+
val panel: JPanel
10+
val myInputPathText = JBTextField()
11+
var inputPathText: String
12+
get() = myInputPathText.text
13+
set(newText) {
14+
myInputPathText.text = newText
15+
}
16+
17+
init {
18+
panel = FormBuilder.createFormBuilder()
19+
.addLabeledComponent(JBLabel("Enter path to AVA: "), myInputPathText, 1, false)
20+
.addComponentFillVertically(JPanel(), 0)
21+
.panel
22+
}
23+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package no.eirikb.avatest.settings
2+
3+
import com.intellij.openapi.options.Configurable
4+
import org.jetbrains.annotations.Nls
5+
import javax.swing.JComponent
6+
7+
class AppSettingsConfigurable : Configurable {
8+
private var mySettingsComponent: AppSettingsComponent? = null
9+
10+
override fun getDisplayName(): @Nls(capitalization = Nls.Capitalization.Title) String =
11+
"AVA Test Runner Run Configuration Generator"
12+
13+
override fun getPreferredFocusedComponent() = mySettingsComponent!!.myInputPathText
14+
15+
override fun createComponent(): JComponent {
16+
mySettingsComponent = AppSettingsComponent()
17+
return mySettingsComponent!!.panel
18+
}
19+
20+
override fun isModified(): Boolean {
21+
var modified = mySettingsComponent!!.inputPathText != AppSettingsState.inputPath
22+
modified = modified or (mySettingsComponent!!.inputPathText != AppSettingsState.inputPath)
23+
return modified
24+
}
25+
26+
override fun apply() {
27+
AppSettingsState.inputPath = mySettingsComponent!!.inputPathText
28+
}
29+
30+
override fun reset() {
31+
mySettingsComponent!!.inputPathText = AppSettingsState.inputPath
32+
}
33+
34+
override fun disposeUIResources() {
35+
mySettingsComponent = null
36+
}
37+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package no.eirikb.avatest.settings
2+
3+
import com.intellij.openapi.components.PersistentStateComponent
4+
import com.intellij.openapi.components.State
5+
import com.intellij.openapi.components.Storage
6+
import com.intellij.util.xmlb.XmlSerializerUtil
7+
8+
@State(name = "no.eirikb.avatest.settings.AppSettingsState", storages = [Storage("SdkSettingsPlugin.xml")])
9+
object AppSettingsState : PersistentStateComponent<AppSettingsState?> {
10+
var inputPath = "node_modules/ava/cli.js"
11+
12+
override fun getState(): AppSettingsState {
13+
return this
14+
}
15+
16+
override fun loadState(state: AppSettingsState) {
17+
XmlSerializerUtil.copyBean(state, this)
18+
}
19+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@
2020
<keyboard-shortcut keymap="$default" first-keystroke="shift ctrl alt A"/>
2121
</action>
2222
</actions>
23+
24+
<extensions defaultExtensionNs="com.intellij">
25+
<applicationConfigurable parentId="tools" instance="no.eirikb.avatest.settings.AppSettingsConfigurable"
26+
id="no.eirikb.avatest.settings.AppSettingsConfigurable"
27+
displayName="AVA Test Runner Run Configuration Generator"/>
28+
<applicationService serviceImplementation="no.eirikb.avatest.settings.AppSettingsState"/>
29+
</extensions>
2330
</idea-plugin>

0 commit comments

Comments
 (0)