2
2
3
3
package org.utbot.cpp.clion.plugin.settings
4
4
5
+ import com.intellij.openapi.components.service
5
6
import com.intellij.openapi.diagnostic.Logger
6
7
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
7
8
import com.intellij.openapi.options.BoundConfigurable
8
9
import com.intellij.openapi.project.Project
9
10
import com.intellij.openapi.ui.DialogPanel
11
+ import com.intellij.ui.components.JBTextField
10
12
import com.intellij.ui.dsl.builder.BottomGap
11
13
import com.intellij.ui.dsl.builder.COLUMNS_LARGE
12
14
import com.intellij.ui.dsl.builder.LabelPosition
@@ -24,19 +26,23 @@ import org.utbot.cpp.clion.plugin.UTBot
24
26
import org.utbot.cpp.clion.plugin.listeners.UTBotSettingsChangedListener
25
27
import org.utbot.cpp.clion.plugin.ui.ObservableValue
26
28
import org.utbot.cpp.clion.plugin.ui.sourceFoldersView.UTBotProjectViewPaneForSettings
29
+ import org.utbot.cpp.clion.plugin.ui.targetsToolWindow.UTBotTarget
27
30
import org.utbot.cpp.clion.plugin.utils.commandLineEditor
28
31
import org.utbot.cpp.clion.plugin.utils.isWindows
32
+ import org.utbot.cpp.clion.plugin.utils.path
29
33
import org.utbot.cpp.clion.plugin.utils.toWslFormat
30
34
import java.awt.Dimension
35
+ import java.nio.file.Paths
31
36
32
37
class UTBotConfigurable (private val myProject : Project ) : BoundConfigurable(
33
38
" Project Settings to Generate Tests"
34
39
) {
35
40
private val logger = Logger .getInstance(" ProjectConfigurable" )
36
41
private val panel by lazy { createMainPanel() }
37
42
38
- private val settings: UTBotProjectStoredSettings .State
39
- get() = myProject.settings.storedSettings
43
+ private val settings: UTBotProjectStoredSettings = myProject.service()
44
+ private lateinit var portTextfield: JBTextField
45
+ private lateinit var serverNameTextField: JBTextField
40
46
41
47
private val isLocalOrWsl = ObservableValue (settings.isLocalOrWslScenario)
42
48
@@ -62,16 +68,17 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
62
68
private fun createMainPanel (): DialogPanel {
63
69
logger.trace(" createPanel was called" )
64
70
return panel {
65
- group(" Connection Settings" ) { this . createConnectionSettings() }
66
- group(" Paths" ) { this . createPathsSettings() }
67
- group(" CMake" ) { this . createCMakeSettings() }
68
- group(" Generator Settings" ) { this . createGeneratorSettings() }
71
+ group(" Connection Settings" ) { createConnectionSettings() }
72
+ group(" Paths" ) { createPathsSettings() }
73
+ group(" CMake" ) { createCMakeSettings() }
74
+ group(" Generator Settings" ) { createGeneratorSettings() }
69
75
}
70
76
}
71
77
72
78
private fun Panel.createConnectionSettings () {
73
79
row(UTBot .message(" settings.project.port" )) {
74
80
intTextField().bindIntText(projectIndependentSettings::port).applyToComponent {
81
+ portTextfield = this
75
82
maximumSize = TEXT_FIELD_MAX_SIZE
76
83
}
77
84
}.rowComment(UTBot .message(" deployment.utbotPort.description" ))
@@ -94,6 +101,7 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
94
101
95
102
row(UTBot .message(" settings.project.serverName" )) {
96
103
textField().bindText(projectIndependentSettings::serverName).applyToComponent {
104
+ serverNameTextField = this
97
105
isLocalOrWsl.addOnChangeListener { newValue ->
98
106
if (newValue)
99
107
this .text = " localhost"
@@ -106,38 +114,31 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
106
114
.applyToComponent {
107
115
isLocalOrWsl.addOnChangeListener { newValue ->
108
116
if (newValue)
109
- this .text = if (isWindows) myProject.settings.projectPath .toWslFormat() else " "
117
+ this .text = if (isWindows) myProject.path .toWslFormat() else " "
110
118
}
111
119
}.enabledIf(enabledIfNotLocalOrWslScenario)
112
120
}.rowComment(UTBot .message(" deployment.remotePath.description" ))
113
121
}
114
122
115
123
private fun Panel.createPathsSettings () {
116
- row(UTBot .message(" settings.project.projectPath" )) {
117
- textFieldWithBrowseButton(
118
- UTBot .message(" settings.project.projectPath.title" ),
119
- myProject,
120
- FileChooserDescriptorFactory .createSingleFileDescriptor()
121
- ).bindText(
122
- getter = { myProject.settings.projectPath },
123
- setter = { value -> myProject.settings.projectPath = value })
124
- .columns(COLUMNS_LARGE )
125
- }.rowComment(UTBot .message(" settings.project.projectPath.info" ))
126
124
createPathChooser(
127
125
settings::buildDirRelativePath,
128
126
UTBot .message(" settings.project.buildDir" ),
129
127
UTBot .message(" settings.project.buildDir.browse.title" )
130
128
).rowComment(UTBot .message(" paths.buildDirectory.description" ))
131
- createPathChooser(
132
- settings::targetPath,
133
- UTBot .message(" settings.project.target" ),
134
- UTBot .message(" settings.project.target.browse.title" )
135
- ).rowComment(UTBot .message(" paths.target.description" ))
136
- createPathChooser(
137
- settings::testDirPath,
138
- UTBot .message(" settings.project.testsDir" ),
139
- UTBot .message(" settings.project.testsDir.browse.title" )
140
- ).rowComment(UTBot .message(" paths.testsDirectory.description" ))
129
+
130
+ row(UTBot .message(" settings.project.target" )) {
131
+ textField().bindText(
132
+ getter = {
133
+ settings.uiTargetPath
134
+ },
135
+ setter = {}
136
+ ).columns(COLUMNS_LARGE ).enabled(false )
137
+ }.rowComment(UTBot .message(" paths.target.description" ))
138
+
139
+ row(UTBot .message(" settings.project.testsDir" )) {
140
+ textField().bindText(settings::testDirRelativePath).columns(COLUMNS_LARGE )
141
+ }.rowComment(UTBot .message(" paths.testsDir.description" ))
141
142
142
143
row {
143
144
val pane = UTBotProjectViewPaneForSettings (myProject)
@@ -221,7 +222,7 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
221
222
spinner(
222
223
UTBotProjectStoredSettings .TIMEOUT_PER_TEST_MIN_VALUE ..
223
224
UTBotProjectStoredSettings .TIMEOUT_PER_TEST_MAX_VALUE
224
- ).bindIntValue(settings::timeoutPerFunction ).applyToComponent {
225
+ ).bindIntValue(settings::timeoutPerTest ).applyToComponent {
225
226
maximumSize = TEXT_FIELD_MAX_SIZE
226
227
}
227
228
}.rowComment(UTBot .message(" advanced.timeoutPerTest.description" ))
@@ -232,8 +233,12 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
232
233
}
233
234
234
235
override fun apply () {
236
+ val wereConnectionSettingsModified =
237
+ portTextfield.text != projectIndependentSettings.port.toString() || serverNameTextField.text != projectIndependentSettings.serverName
235
238
panel.apply ()
236
239
myProject.settings.fireUTBotSettingsChanged()
240
+ if (wereConnectionSettingsModified)
241
+ projectIndependentSettings.fireConnectionSettingsChanged()
237
242
}
238
243
239
244
override fun reset () {
0 commit comments