diff --git a/platform/platform-impl/src/com/intellij/application/options/editor/CheckboxDescriptor.kt b/platform/platform-impl/src/com/intellij/application/options/editor/CheckboxDescriptor.kt index 1cf76354787f..337a5e623796 100644 --- a/platform/platform-impl/src/com/intellij/application/options/editor/CheckboxDescriptor.kt +++ b/platform/platform-impl/src/com/intellij/application/options/editor/CheckboxDescriptor.kt @@ -62,7 +62,7 @@ fun Cell.radioButton(ui: CheckboxDescriptor): CellBuilder { fun Row.checkBox(ui: CheckboxDescriptor): com.intellij.ui.dsl.builder.Cell { val result = checkBox(ui.name) - .bindSelected(ui.binding) + .bindSelected(ui.binding.get, ui.binding.set) ui.comment?.let { result.comment(it) } return result } @@ -71,7 +71,7 @@ fun Row.checkBox(ui: CheckboxDescriptor): com.intellij.ui.dsl.builder.Cell { val result = radioButton(ui.name) - .bindSelected(ui.binding) + .bindSelected(ui.binding.get, ui.binding.set) ui.comment?.let { result.comment(it) } return result } diff --git a/platform/platform-impl/src/com/intellij/internal/ui/AnimationPanelTestAction.kt b/platform/platform-impl/src/com/intellij/internal/ui/AnimationPanelTestAction.kt index 3a291faee7de..036ce9e0cf5e 100644 --- a/platform/platform-impl/src/com/intellij/internal/ui/AnimationPanelTestAction.kt +++ b/platform/platform-impl/src/com/intellij/internal/ui/AnimationPanelTestAction.kt @@ -499,7 +499,7 @@ class AnimationPanelTestAction : DumbAwareAction("Show Animation Panel") { } row { checkBox("Enable high precision timer").bindSelected( - PropertyBinding(JBAnimatorHelper::isAvailable, JBAnimatorHelper::setAvailable) + JBAnimatorHelper::isAvailable, JBAnimatorHelper::setAvailable ) }.visible(SystemInfoRt.isWindows) row { diff --git a/platform/platform-impl/src/com/intellij/ui/dsl/builder/ButtonsGroup.kt b/platform/platform-impl/src/com/intellij/ui/dsl/builder/ButtonsGroup.kt index d5bac36cdc49..4bc32b17f8d0 100644 --- a/platform/platform-impl/src/com/intellij/ui/dsl/builder/ButtonsGroup.kt +++ b/platform/platform-impl/src/com/intellij/ui/dsl/builder/ButtonsGroup.kt @@ -15,13 +15,9 @@ interface ButtonsGroup { } inline fun ButtonsGroup.bind(noinline getter: () -> T, noinline setter: (T) -> Unit): ButtonsGroup { - return bind(PropertyBinding(getter, setter)) + return bind(PropertyBinding(getter, setter), T::class.java) } inline fun ButtonsGroup.bind(prop: KMutableProperty0): ButtonsGroup { - return bind(prop.toBindingInternal()) -} - -inline fun ButtonsGroup.bind(binding: PropertyBinding): ButtonsGroup { - return bind(binding, T::class.java) + return bind(prop.toBindingInternal(), T::class.java) } diff --git a/platform/platform-impl/src/com/intellij/ui/dsl/builder/button.kt b/platform/platform-impl/src/com/intellij/ui/dsl/builder/button.kt index 580140ea33cb..94ac94f3744b 100644 --- a/platform/platform-impl/src/com/intellij/ui/dsl/builder/button.kt +++ b/platform/platform-impl/src/com/intellij/ui/dsl/builder/button.kt @@ -15,10 +15,6 @@ import java.awt.event.ActionListener import javax.swing.AbstractButton import kotlin.reflect.KMutableProperty0 -fun Cell.bindSelected(binding: PropertyBinding): Cell { - return bind(AbstractButton::isSelected, AbstractButton::setSelected, binding) -} - @Deprecated("Please, recompile code", level = DeprecationLevel.HIDDEN) @ApiStatus.ScheduledForRemoval fun Cell.bindSelected(property: GraphProperty) = bindSelected(property) @@ -52,3 +48,7 @@ fun Cell.actionListener(actionListener: (event: ActionEv val Cell.selected get() = component.selected + +private fun Cell.bindSelected(binding: PropertyBinding): Cell { + return bind(AbstractButton::isSelected, AbstractButton::setSelected, binding) +} diff --git a/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/BindButtonGroup.kt b/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/BindButtonGroup.kt deleted file mode 100644 index e7d6075c5652..000000000000 --- a/platform/platform-impl/src/com/intellij/ui/dsl/builder/impl/BindButtonGroup.kt +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.ui.dsl.builder.impl - -import com.intellij.ui.layout.* -import org.jetbrains.annotations.ApiStatus -import javax.swing.ButtonGroup - -@ApiStatus.Internal -internal class BindButtonGroup(val binding: PropertyBinding, val type: Class) : ButtonGroup() { - - fun set(value: Any) { - binding.set(type.cast(value)) - } -} \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ui/dsl/builder/slider.kt b/platform/platform-impl/src/com/intellij/ui/dsl/builder/slider.kt index 072fcff14df1..b22a0808b1f5 100644 --- a/platform/platform-impl/src/com/intellij/ui/dsl/builder/slider.kt +++ b/platform/platform-impl/src/com/intellij/ui/dsl/builder/slider.kt @@ -13,10 +13,6 @@ fun Cell.labelTable(map: Map): Cell { return this } -fun Cell.bindValue(binding: PropertyBinding): Cell { - return bind(JSlider::getValue, JSlider::setValue, binding) -} - fun Cell.bindValue(prop: KMutableProperty0): Cell { return bindValue(prop.toBindingInternal()) } @@ -32,3 +28,7 @@ fun Cell.showValueHint(): Cell { } return this } + +private fun Cell.bindValue(binding: PropertyBinding): Cell { + return bind(JSlider::getValue, JSlider::setValue, binding) +} diff --git a/platform/platform-impl/src/com/intellij/ui/dsl/builder/spinner.kt b/platform/platform-impl/src/com/intellij/ui/dsl/builder/spinner.kt index ba8614589ced..f86a9b36ba5c 100644 --- a/platform/platform-impl/src/com/intellij/ui/dsl/builder/spinner.kt +++ b/platform/platform-impl/src/com/intellij/ui/dsl/builder/spinner.kt @@ -7,10 +7,6 @@ import com.intellij.ui.layout.* import javax.swing.JSpinner import kotlin.reflect.KMutableProperty0 -fun Cell.bindIntValue(binding: PropertyBinding): Cell { - return bind(JBIntSpinner::getNumber, JBIntSpinner::setNumber, binding) -} - fun Cell.bindIntValue(prop: KMutableProperty0): Cell { return bindIntValue(prop.toBindingInternal()) } @@ -19,10 +15,6 @@ fun Cell.bindIntValue(getter: () -> Int, setter: (Int) -> return bindIntValue(PropertyBinding(getter, setter)) } -fun Cell.bindValue(binding: PropertyBinding): Cell { - return bind({ it.value as Double }, JSpinner::setValue, binding) -} - fun Cell.bindValue(prop: KMutableProperty0): Cell { return bindValue(prop.toBindingInternal()) } @@ -30,3 +22,11 @@ fun Cell.bindValue(prop: KMutableProperty0): Cell { fun Cell.bindValue(getter: () -> Double, setter: (Double) -> Unit): Cell { return bindValue(PropertyBinding(getter, setter)) } + +private fun Cell.bindIntValue(binding: PropertyBinding): Cell { + return bind(JBIntSpinner::getNumber, JBIntSpinner::setNumber, binding) +} + +private fun Cell.bindValue(binding: PropertyBinding): Cell { + return bind({ it.value as Double }, JSpinner::setValue, binding) +} diff --git a/platform/platform-impl/src/com/intellij/ui/dsl/builder/textField.kt b/platform/platform-impl/src/com/intellij/ui/dsl/builder/textField.kt index 1d4f6062f767..7154a3d28d98 100644 --- a/platform/platform-impl/src/com/intellij/ui/dsl/builder/textField.kt +++ b/platform/platform-impl/src/com/intellij/ui/dsl/builder/textField.kt @@ -36,10 +36,6 @@ const val COLUMNS_MEDIUM = 25 const val COLUMNS_LARGE = 36 -fun Cell.bindText(binding: PropertyBinding): Cell { - return bind(JTextComponent::getText, JTextComponent::setText, binding) -} - @Deprecated("Please, recompile code", level = DeprecationLevel.HIDDEN) @ApiStatus.ScheduledForRemoval fun Cell.bindText(property: GraphProperty) = bindText(property) @@ -57,11 +53,6 @@ fun Cell.bindText(getter: () -> String, setter: (String) return bindText(PropertyBinding(getter, setter)) } -fun Cell.bindIntText(binding: PropertyBinding): Cell { - return bindText({ binding.get().toString() }, - { value -> catchValidationException { binding.set(component.getValidatedIntValue(value)) } }) -} - @Deprecated("Please, recompile code", level = DeprecationLevel.HIDDEN) @ApiStatus.ScheduledForRemoval fun Cell.bindIntText(property: GraphProperty): Cell = bindIntText(property) @@ -128,3 +119,12 @@ private fun JTextComponent.bind(property: ObservableMutableProperty) { } } } + +private fun Cell.bindText(binding: PropertyBinding): Cell { + return bind(JTextComponent::getText, JTextComponent::setText, binding) +} + +private fun Cell.bindIntText(binding: PropertyBinding): Cell { + return bindText({ binding.get().toString() }, + { value -> catchValidationException { binding.set(component.getValidatedIntValue(value)) } }) +} diff --git a/platform/platform-impl/src/com/intellij/ui/dsl/builder/textFieldWithBrowseButton.kt b/platform/platform-impl/src/com/intellij/ui/dsl/builder/textFieldWithBrowseButton.kt index f3c71105501e..f3a3c71745f6 100644 --- a/platform/platform-impl/src/com/intellij/ui/dsl/builder/textFieldWithBrowseButton.kt +++ b/platform/platform-impl/src/com/intellij/ui/dsl/builder/textFieldWithBrowseButton.kt @@ -16,10 +16,6 @@ fun Cell.columns(columns: Int): Cell { return this } -fun Cell.bindText(binding: PropertyBinding): Cell { - return bind(TextFieldWithBrowseButton::getText, TextFieldWithBrowseButton::setText, binding) -} - @Deprecated("Please, recompile code", level = DeprecationLevel.HIDDEN) @ApiStatus.ScheduledForRemoval fun Cell.bindText(property: GraphProperty) = bindText(property) @@ -41,3 +37,7 @@ fun Cell.text(text: String): Cell { component.text = text return this } + +private fun Cell.bindText(binding: PropertyBinding): Cell { + return bind(TextFieldWithBrowseButton::getText, TextFieldWithBrowseButton::setText, binding) +} diff --git a/platform/platform-impl/src/com/intellij/ui/mouse/MouseWheelSmoothScrollOptions.kt b/platform/platform-impl/src/com/intellij/ui/mouse/MouseWheelSmoothScrollOptions.kt index 76756ba82cee..e402b8d03887 100644 --- a/platform/platform-impl/src/com/intellij/ui/mouse/MouseWheelSmoothScrollOptions.kt +++ b/platform/platform-impl/src/com/intellij/ui/mouse/MouseWheelSmoothScrollOptions.kt @@ -89,7 +89,7 @@ internal class MouseWheelSmoothScrollOptionsAction : DumbAwareAction() { JBAnimatorHelper.requestHighPrecisionTimer(myBezierPainter.animator) } } - }.bindSelected(PropertyBinding(JBAnimatorHelper::isAvailable, JBAnimatorHelper::setAvailable)) + }.bindSelected(JBAnimatorHelper::isAvailable, JBAnimatorHelper::setAvailable) contextHelp(IdeBundle.message("checkbox.smooth.scrolling.enable.high.precision.timer.help")) rowComment(IdeBundle.message("checkbox.smooth.scrolling.enable.high.precision.timer.comments")) } diff --git a/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/ButtonTest.kt b/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/ButtonTest.kt index c924d369aad4..3c74eb835efc 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/ButtonTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/ButtonTest.kt @@ -47,14 +47,6 @@ class ButtonTest { assertEquals(checkBox.component.isSelected, localProperty) } } - - panel { - row { - val checkBox = checkBox("") - .bindSelected(PropertyBinding({ localProperty }, { localProperty = it })) - assertEquals(checkBox.component.isSelected, localProperty) - } - } } @Test @@ -65,9 +57,6 @@ class ButtonTest { testCheckBox( { checkBox("checkBox").bindSelected({ boolean }, { boolean = it }) }, { boolean }) - testCheckBox( - { checkBox("checkBox").bindSelected(PropertyBinding({ boolean }, { boolean = it })) }, - { boolean }) // Test different kinds of properties testCheckBox( diff --git a/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/TextFieldTest.kt b/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/TextFieldTest.kt index 714b151c56db..71c9a14274d7 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/TextFieldTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/TextFieldTest.kt @@ -31,14 +31,6 @@ class TextFieldTest { assertEquals(textField.component.text, localProperty) } } - - panel { - row { - val textField = textField() - .bindText(PropertyBinding({ localProperty }, { localProperty = it })) - assertEquals(textField.component.text, localProperty) - } - } } @Test diff --git a/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/TextFieldWithBrowseButtonTest.kt b/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/TextFieldWithBrowseButtonTest.kt index a7638ae85579..9232810c92aa 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/TextFieldWithBrowseButtonTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/dsl/builder/TextFieldWithBrowseButtonTest.kt @@ -31,14 +31,6 @@ class TextFieldWithBrowseButtonTest { assertEquals(textField.component.text, localProperty) } } - - panel { - row { - val textField = textFieldWithBrowseButton() - .bindText(PropertyBinding({ localProperty }, { localProperty = it })) - assertEquals(textField.component.text, localProperty) - } - } } @Test