Skip to content

Commit 5e7ecc9

Browse files
committed
Restore typed options after unchecking check box
1 parent 7153e7c commit 5e7ecc9

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/ObservableValue.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import kotlin.properties.Delegates
55
// allows attaching multiple listeners for value change
66
class ObservableValue<T>(initialValue: T) {
77
private val changeListeners: MutableList<(T) -> Unit> = mutableListOf()
8-
var value: T by Delegates.observable(initialValue) { _, _, newVal ->
9-
changeListeners.forEach {
10-
it(newVal)
8+
var value: T by Delegates.observable(initialValue) { _, oldVal, newVal ->
9+
changeListeners.forEach {callback ->
10+
if (oldVal != newVal)
11+
callback(newVal)
1112
}
1213
}
1314

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/wizard/steps/ConnectionStep.kt

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,33 @@ class ConnectionStep(
5656
private val connectionStatus = ObservableValue(ConnectionStatus.Failed)
5757
private val useConnectionDefaults = ObservableValue(false)
5858

59+
inner class ConnectionInfo(val port: Int, val host: String, val remotePath: String) {
60+
constructor(): this(portComponent.number, hostTextField.text, remotePathTextField.text)
61+
fun apply() {
62+
portComponent.number = port
63+
hostTextField.text = host
64+
remotePathTextField.text = remotePath
65+
}
66+
}
67+
68+
private val defaultConnectionInfo = ConnectionInfo(
69+
UTBotAllProjectSettings.DEFAULT_PORT,
70+
UTBotAllProjectSettings.DEFAULT_HOST,
71+
if (isWindows) project.path.toWslFormatIfNeeded()
72+
else UTBotProjectStoredSettings.REMOTE_PATH_VALUE_FOR_LOCAL_SCENARIO
73+
)
74+
75+
private var beforeCheckingBoxConnectionInfo: ConnectionInfo? = null
76+
5977
init {
6078
useConnectionDefaults.addOnChangeListener { newValue ->
6179
if (newValue) {
62-
portComponent.number = UTBotAllProjectSettings.DEFAULT_PORT
63-
hostTextField.text = UTBotAllProjectSettings.DEFAULT_HOST
64-
remotePathTextField.text = if (isWindows) project.path.toWslFormatIfNeeded()
65-
else UTBotProjectStoredSettings.REMOTE_PATH_VALUE_FOR_LOCAL_SCENARIO
80+
beforeCheckingBoxConnectionInfo = ConnectionInfo()
81+
println("remembered before check info: ${beforeCheckingBoxConnectionInfo?.remotePath ?: ""}")
82+
defaultConnectionInfo.apply()
83+
} else {
84+
println("Apply before check info: ${beforeCheckingBoxConnectionInfo?.remotePath ?: "empty"}")
85+
beforeCheckingBoxConnectionInfo?.apply()
6686
}
6787
}
6888
}
@@ -88,6 +108,7 @@ class ConnectionStep(
88108
.bindSelected(getter = { useConnectionDefaults.value }, setter = { newValue ->
89109
useConnectionDefaults.value = newValue
90110
}).selected.addListener { newValue ->
111+
println("New value was set to checkbox: $newValue")
91112
useConnectionDefaults.value = newValue
92113
}
93114
}
@@ -143,7 +164,7 @@ class ConnectionStep(
143164
})
144165

145166
val warningMessage: () -> String = {
146-
"⚠️ Warning! Versions are different or not defined:" +
167+
"⚠️ Warning! Versions are different or not defined: " +
147168
"Client: ${ourPluginVersion} Server: ${serverVersion ?: "not defined"}"
148169
}
149170
label(warningMessage()).visibleIf(
@@ -172,11 +193,11 @@ class ConnectionStep(
172193
.applyToComponent {
173194
remotePathTextField = this
174195
}.enabledIf(object : ComponentPredicate() {
175-
override fun invoke() = !useConnectionDefaults.value
176-
override fun addListener(listener: (Boolean) -> Unit) {
177-
useConnectionDefaults.addOnChangeListener { newValue -> listener(!newValue) }
178-
}
179-
})
196+
override fun invoke() = !useConnectionDefaults.value
197+
override fun addListener(listener: (Boolean) -> Unit) {
198+
useConnectionDefaults.addOnChangeListener { newValue -> listener(!newValue) }
199+
}
200+
})
180201
}
181202
}.addToUI()
182203
}

0 commit comments

Comments
 (0)