mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 18:05:27 +07:00
UI DSL: API reduced, getting rid of PropertyBinding from public API
GitOrigin-RevId: 884280fa62386f568f8c887b00e8d04b0a3425c6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a2505cca88
commit
105613a758
@@ -62,7 +62,7 @@ fun Cell.radioButton(ui: CheckboxDescriptor): CellBuilder<JRadioButton> {
|
||||
|
||||
fun Row.checkBox(ui: CheckboxDescriptor): com.intellij.ui.dsl.builder.Cell<JBCheckBox> {
|
||||
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<JBChe
|
||||
@Deprecated("Use Kotlin UI DSL Version 2")
|
||||
fun Row.radioButton(ui: CheckboxDescriptor): com.intellij.ui.dsl.builder.Cell<JBRadioButton> {
|
||||
val result = radioButton(ui.name)
|
||||
.bindSelected(ui.binding)
|
||||
.bindSelected(ui.binding.get, ui.binding.set)
|
||||
ui.comment?.let { result.comment(it) }
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -15,13 +15,9 @@ interface ButtonsGroup {
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> 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 <reified T : Any> ButtonsGroup.bind(prop: KMutableProperty0<T>): ButtonsGroup {
|
||||
return bind(prop.toBindingInternal())
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> ButtonsGroup.bind(binding: PropertyBinding<T>): ButtonsGroup {
|
||||
return bind(binding, T::class.java)
|
||||
return bind(prop.toBindingInternal(), T::class.java)
|
||||
}
|
||||
|
||||
@@ -15,10 +15,6 @@ import java.awt.event.ActionListener
|
||||
import javax.swing.AbstractButton
|
||||
import kotlin.reflect.KMutableProperty0
|
||||
|
||||
fun <T : AbstractButton> Cell<T>.bindSelected(binding: PropertyBinding<Boolean>): Cell<T> {
|
||||
return bind(AbstractButton::isSelected, AbstractButton::setSelected, binding)
|
||||
}
|
||||
|
||||
@Deprecated("Please, recompile code", level = DeprecationLevel.HIDDEN)
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
fun <T : JBCheckBox> Cell<T>.bindSelected(property: GraphProperty<Boolean>) = bindSelected(property)
|
||||
@@ -52,3 +48,7 @@ fun <T : AbstractButton> Cell<T>.actionListener(actionListener: (event: ActionEv
|
||||
|
||||
val Cell<AbstractButton>.selected
|
||||
get() = component.selected
|
||||
|
||||
private fun <T : AbstractButton> Cell<T>.bindSelected(binding: PropertyBinding<Boolean>): Cell<T> {
|
||||
return bind(AbstractButton::isSelected, AbstractButton::setSelected, binding)
|
||||
}
|
||||
|
||||
@@ -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<T>(val binding: PropertyBinding<T>, val type: Class<T>) : ButtonGroup() {
|
||||
|
||||
fun set(value: Any) {
|
||||
binding.set(type.cast(value))
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,6 @@ fun Cell<JSlider>.labelTable(map: Map<Int, JComponent>): Cell<JSlider> {
|
||||
return this
|
||||
}
|
||||
|
||||
fun Cell<JSlider>.bindValue(binding: PropertyBinding<Int>): Cell<JSlider> {
|
||||
return bind(JSlider::getValue, JSlider::setValue, binding)
|
||||
}
|
||||
|
||||
fun Cell<JSlider>.bindValue(prop: KMutableProperty0<Int>): Cell<JSlider> {
|
||||
return bindValue(prop.toBindingInternal())
|
||||
}
|
||||
@@ -32,3 +28,7 @@ fun Cell<JSlider>.showValueHint(): Cell<JSlider> {
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
private fun Cell<JSlider>.bindValue(binding: PropertyBinding<Int>): Cell<JSlider> {
|
||||
return bind(JSlider::getValue, JSlider::setValue, binding)
|
||||
}
|
||||
|
||||
@@ -7,10 +7,6 @@ import com.intellij.ui.layout.*
|
||||
import javax.swing.JSpinner
|
||||
import kotlin.reflect.KMutableProperty0
|
||||
|
||||
fun <T : JBIntSpinner> Cell<T>.bindIntValue(binding: PropertyBinding<Int>): Cell<T> {
|
||||
return bind(JBIntSpinner::getNumber, JBIntSpinner::setNumber, binding)
|
||||
}
|
||||
|
||||
fun <T : JBIntSpinner> Cell<T>.bindIntValue(prop: KMutableProperty0<Int>): Cell<T> {
|
||||
return bindIntValue(prop.toBindingInternal())
|
||||
}
|
||||
@@ -19,10 +15,6 @@ fun <T : JBIntSpinner> Cell<T>.bindIntValue(getter: () -> Int, setter: (Int) ->
|
||||
return bindIntValue(PropertyBinding(getter, setter))
|
||||
}
|
||||
|
||||
fun <T : JSpinner> Cell<T>.bindValue(binding: PropertyBinding<Double>): Cell<T> {
|
||||
return bind({ it.value as Double }, JSpinner::setValue, binding)
|
||||
}
|
||||
|
||||
fun <T : JSpinner> Cell<T>.bindValue(prop: KMutableProperty0<Double>): Cell<T> {
|
||||
return bindValue(prop.toBindingInternal())
|
||||
}
|
||||
@@ -30,3 +22,11 @@ fun <T : JSpinner> Cell<T>.bindValue(prop: KMutableProperty0<Double>): Cell<T> {
|
||||
fun <T : JSpinner> Cell<T>.bindValue(getter: () -> Double, setter: (Double) -> Unit): Cell<T> {
|
||||
return bindValue(PropertyBinding(getter, setter))
|
||||
}
|
||||
|
||||
private fun <T : JBIntSpinner> Cell<T>.bindIntValue(binding: PropertyBinding<Int>): Cell<T> {
|
||||
return bind(JBIntSpinner::getNumber, JBIntSpinner::setNumber, binding)
|
||||
}
|
||||
|
||||
private fun <T : JSpinner> Cell<T>.bindValue(binding: PropertyBinding<Double>): Cell<T> {
|
||||
return bind({ it.value as Double }, JSpinner::setValue, binding)
|
||||
}
|
||||
|
||||
@@ -36,10 +36,6 @@ const val COLUMNS_MEDIUM = 25
|
||||
|
||||
const val COLUMNS_LARGE = 36
|
||||
|
||||
fun <T : JTextComponent> Cell<T>.bindText(binding: PropertyBinding<String>): Cell<T> {
|
||||
return bind(JTextComponent::getText, JTextComponent::setText, binding)
|
||||
}
|
||||
|
||||
@Deprecated("Please, recompile code", level = DeprecationLevel.HIDDEN)
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
fun <T : JTextComponent> Cell<T>.bindText(property: GraphProperty<String>) = bindText(property)
|
||||
@@ -57,11 +53,6 @@ fun <T : JTextComponent> Cell<T>.bindText(getter: () -> String, setter: (String)
|
||||
return bindText(PropertyBinding(getter, setter))
|
||||
}
|
||||
|
||||
fun <T : JTextComponent> Cell<T>.bindIntText(binding: PropertyBinding<Int>): Cell<T> {
|
||||
return bindText({ binding.get().toString() },
|
||||
{ value -> catchValidationException { binding.set(component.getValidatedIntValue(value)) } })
|
||||
}
|
||||
|
||||
@Deprecated("Please, recompile code", level = DeprecationLevel.HIDDEN)
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
fun <T : JTextComponent> Cell<T>.bindIntText(property: GraphProperty<Int>): Cell<T> = bindIntText(property)
|
||||
@@ -128,3 +119,12 @@ private fun JTextComponent.bind(property: ObservableMutableProperty<String>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T : JTextComponent> Cell<T>.bindText(binding: PropertyBinding<String>): Cell<T> {
|
||||
return bind(JTextComponent::getText, JTextComponent::setText, binding)
|
||||
}
|
||||
|
||||
private fun <T : JTextComponent> Cell<T>.bindIntText(binding: PropertyBinding<Int>): Cell<T> {
|
||||
return bindText({ binding.get().toString() },
|
||||
{ value -> catchValidationException { binding.set(component.getValidatedIntValue(value)) } })
|
||||
}
|
||||
|
||||
@@ -16,10 +16,6 @@ fun <T : TextFieldWithBrowseButton> Cell<T>.columns(columns: Int): Cell<T> {
|
||||
return this
|
||||
}
|
||||
|
||||
fun <T : TextFieldWithBrowseButton> Cell<T>.bindText(binding: PropertyBinding<String>): Cell<T> {
|
||||
return bind(TextFieldWithBrowseButton::getText, TextFieldWithBrowseButton::setText, binding)
|
||||
}
|
||||
|
||||
@Deprecated("Please, recompile code", level = DeprecationLevel.HIDDEN)
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
fun <T : TextFieldWithBrowseButton> Cell<T>.bindText(property: GraphProperty<String>) = bindText(property)
|
||||
@@ -41,3 +37,7 @@ fun <T : TextFieldWithBrowseButton> Cell<T>.text(text: String): Cell<T> {
|
||||
component.text = text
|
||||
return this
|
||||
}
|
||||
|
||||
private fun <T : TextFieldWithBrowseButton> Cell<T>.bindText(binding: PropertyBinding<String>): Cell<T> {
|
||||
return bind(TextFieldWithBrowseButton::getText, TextFieldWithBrowseButton::setText, binding)
|
||||
}
|
||||
|
||||
@@ -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"))
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user