Skip to content

Commit

Permalink
Two way sync fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian-panek-vmltech committed Nov 3, 2022
1 parent 529b0bc commit 156c124
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions plugin/src/main/kotlin/io/wttech/gradle/config/gui/Gui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import java.awt.event.FocusEvent
import java.awt.event.FocusListener
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent
import java.util.concurrent.locks.ReentrantLock
import javax.swing.*
import javax.swing.text.JTextComponent

Expand Down Expand Up @@ -244,7 +243,7 @@ class Gui(val definition: Definition) {

fun updatePropPanels() {
propPanels.forEach { panel ->
// fix two-way syncing for text field and area (combo works fine)
// fix two-way syncing
val normalizedValue by lazy {
when (panel.data) {
is ListProp -> panel.data.value()?.joinToString("\n")
Expand All @@ -255,19 +254,7 @@ class Gui(val definition: Definition) {
when {
panel.field is JTextField && panel.field.text != normalizedValue -> tryMutate { panel.field.text = normalizedValue }
panel.field is JTextArea && panel.field.text != normalizedValue -> tryMutate { panel.field.text = normalizedValue }
// TODO make it nicer (sync two-way)
panel.field is JComboBox<*> && panel.field.selectedItem != normalizedValue -> tryMutate {
panel.field.selectedItem = when (panel.data) {
is StringProp -> when {
panel.data.options.get().isNotEmpty() -> when (normalizedValue) {
in panel.data.options.get() -> normalizedValue
else -> panel.data.options.get().first()
}
else -> normalizedValue
}
else -> normalizedValue
}
}
panel.field is JComboBox<*> && panel.field.selectedItem != normalizedValue -> tryMutate { panel.field.selectedItem = normalizedValue }
}

panel.container.isVisible = panel.data.visible.get()
Expand Down Expand Up @@ -301,7 +288,7 @@ class Gui(val definition: Definition) {
}

private fun updateMalformedData() {
definition.props.forEach {prop ->
definition.props.forEach { prop ->
if (prop is StringProp) {
if (prop.options.get().isNotEmpty()) {
if (prop.value() !in prop.options.get()) {
Expand Down

0 comments on commit 156c124

Please sign in to comment.