From 3a57ed8c908315a7c7386366ddfc86440997dcff Mon Sep 17 00:00:00 2001 From: Pavel Porvatov Date: Tue, 20 Feb 2024 20:27:05 +0100 Subject: [PATCH] [Kotlin UI DSL] Hidden deprecated API GitOrigin-RevId: ae6adb989e0b588b895d60bed800f6ddb7c134d5 --- .../intellij/execution/target/TargetUIUtil.kt | 2 +- .../src/com/intellij/ui/layout/Cell.kt | 52 +++++++++++-------- .../com/intellij/ui/layout/LayoutBuilder.kt | 5 +- .../src/com/intellij/ui/layout/Row.kt | 2 +- .../ui/layout/migLayout/MigLayoutRow.kt | 11 ++-- .../layout/migLayout/componentConstraints.kt | 2 +- 6 files changed, 38 insertions(+), 36 deletions(-) diff --git a/platform/execution-impl/src/com/intellij/execution/target/TargetUIUtil.kt b/platform/execution-impl/src/com/intellij/execution/target/TargetUIUtil.kt index 069c0c793374..03848ee9d74a 100644 --- a/platform/execution-impl/src/com/intellij/execution/target/TargetUIUtil.kt +++ b/platform/execution-impl/src/com/intellij/execution/target/TargetUIUtil.kt @@ -36,7 +36,7 @@ fun textFieldWithBrowseTargetButton(row: Row, targetBrowserHints) textFieldWithBrowseButton.addActionListener(browser) textFieldWithBrowseButton.text = property.get() - return row.component(textFieldWithBrowseButton).withBinding(TextFieldWithBrowseButton::getText, + return row.component(textFieldWithBrowseButton).withBindingInt(TextFieldWithBrowseButton::getText, TextFieldWithBrowseButton::setText, property) } diff --git a/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt b/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt index 4158e7b6f039..3e8628dad6a7 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt @@ -82,7 +82,7 @@ inline fun KMutableProperty0.toBinding(): PropertyBinding KMutableProperty0.toNullableBinding(defaultValue: T): PropertyBinding { return PropertyBinding({ get() ?: defaultValue }, { set(it) }) } @@ -153,7 +153,7 @@ interface CellBuilder { fun applyIfEnabled(): CellBuilder @ApiStatus.ScheduledForRemoval - @Deprecated("Use Kotlin UI DSL Version 2") + @Deprecated("Use Kotlin UI DSL Version 2", level = DeprecationLevel.HIDDEN) fun withBinding( componentGet: (T) -> V, componentSet: (T, V) -> Unit, @@ -165,6 +165,20 @@ interface CellBuilder { return this } + @ApiStatus.ScheduledForRemoval + @ApiStatus.Internal + @Deprecated("Use Kotlin UI DSL Version 2") + fun withBindingInt( + componentGet: (T) -> V, + componentSet: (T, V) -> Unit, + modelBinding: PropertyBinding + ): CellBuilder { + onApply { if (shouldSaveOnApply()) modelBinding.set(componentGet(component)) } + onReset { componentSet(component, modelBinding.get()) } + onIsModified { shouldSaveOnApply() && componentGet(component) != modelBinding.get() } + return this + } + @ApiStatus.ScheduledForRemoval @Deprecated("Use Kotlin UI DSL Version 2") fun withGraphProperty(property: GraphProperty<*>): CellBuilder @@ -174,7 +188,7 @@ interface CellBuilder { fun enabled(isEnabled: Boolean) @ApiStatus.ScheduledForRemoval - @Deprecated("Use Kotlin UI DSL Version 2") + @Deprecated("Use Kotlin UI DSL Version 2", level = DeprecationLevel.HIDDEN) fun enableIf(predicate: ComponentPredicate): CellBuilder @ApiStatus.ScheduledForRemoval @@ -207,18 +221,18 @@ fun CellBuilder.applyToComponent(task: T.() -> Unit): CellBu @ApiStatus.ScheduledForRemoval @Deprecated("Use Kotlin UI DSL Version 2") fun CellBuilder.withTextBinding(modelBinding: PropertyBinding): CellBuilder { - return withBinding(JTextComponent::getText, JTextComponent::setText, modelBinding) + return withBindingInt(JTextComponent::getText, JTextComponent::setText, modelBinding) } @ApiStatus.ScheduledForRemoval @Deprecated("Use Kotlin UI DSL Version 2") fun CellBuilder.withSelectedBinding(modelBinding: PropertyBinding): CellBuilder { - return withBinding(AbstractButton::isSelected, AbstractButton::setSelected, modelBinding) + return withBindingInt(AbstractButton::isSelected, AbstractButton::setSelected, modelBinding) } -@get:Deprecated("Use Kotlin UI DSL Version 2") +@get:Deprecated("Use Kotlin UI DSL Version 2", level = DeprecationLevel.HIDDEN) @get:ApiStatus.ScheduledForRemoval -@Deprecated("Use Kotlin UI DSL Version 2") +@Deprecated("Use Kotlin UI DSL Version 2", level = DeprecationLevel.HIDDEN) val CellBuilder.selected: ComponentPredicate get() = component.selected @@ -233,7 +247,7 @@ abstract class Cell : BaseBuilder { * Grow weight will only be compared against the weights for the same cell. */ @ApiStatus.ScheduledForRemoval - @Deprecated("Use Kotlin UI DSL Version 2") + @Deprecated("Use Kotlin UI DSL Version 2", level = DeprecationLevel.HIDDEN) val growX: CCFlags = CCFlags.growX @ApiStatus.ScheduledForRemoval @@ -296,7 +310,7 @@ abstract class Cell : BaseBuilder { } @ApiStatus.ScheduledForRemoval - @Deprecated("Use Kotlin UI DSL Version 2") + @Deprecated("Use Kotlin UI DSL Version 2", level = DeprecationLevel.HIDDEN) fun button(@Button text: String, actionListener: (event: ActionEvent) -> Unit): CellBuilder { val button = JButton(BundleBase.replaceMnemonicAmpersand(text)) button.addActionListener(actionListener) @@ -304,7 +318,7 @@ abstract class Cell : BaseBuilder { } @ApiStatus.ScheduledForRemoval - @Deprecated("Use Kotlin UI DSL Version 2") + @Deprecated("Use Kotlin UI DSL Version 2", level = DeprecationLevel.HIDDEN) inline fun checkBox(@Checkbox text: String, isSelected: Boolean = false, @DetailedDescription comment: String? = null, @@ -356,7 +370,7 @@ abstract class Cell : BaseBuilder { } @ApiStatus.ScheduledForRemoval - @Deprecated("Use Kotlin UI DSL Version 2") + @Deprecated("Use Kotlin UI DSL Version 2", level = DeprecationLevel.HIDDEN) fun comboBox(model: ComboBoxModel, getter: () -> T?, setter: (T?) -> Unit, @@ -374,7 +388,7 @@ abstract class Cell : BaseBuilder { this.renderer = renderer ?: SimpleListCellRenderer.create("") { it.toString() } selectedItem = modelBinding.get() } - .withBinding( + .withBindingInt( { component -> component.selectedItem as T? }, { component, value -> component.setSelectedItem(value) }, modelBinding @@ -382,7 +396,7 @@ abstract class Cell : BaseBuilder { } @ApiStatus.ScheduledForRemoval - @Deprecated("Use Kotlin UI DSL Version 2") + @Deprecated("Use Kotlin UI DSL Version 2", level = DeprecationLevel.HIDDEN) inline fun comboBox( model: ComboBoxModel, prop: KMutableProperty0, @@ -418,19 +432,11 @@ abstract class Cell : BaseBuilder { .withTextBinding(binding) } - @Deprecated("Use Kotlin UI DSL Version 2") - private fun scrollableTextArea(binding: PropertyBinding, rows: Int? = null): CellBuilder { - val textArea = JBTextArea(binding.get(), rows ?: 0, 0) - val scrollPane = JBScrollPane(textArea) - return component(textArea, scrollPane) - .withTextBinding(binding) - } - @ApiStatus.ScheduledForRemoval @Deprecated("Use Kotlin UI DSL Version 2", level = DeprecationLevel.HIDDEN) fun spinner(getter: () -> Int, setter: (Int) -> Unit, minValue: Int, maxValue: Int, step: Int = 1): CellBuilder { val spinner = JBIntSpinner(getter(), minValue, maxValue, step) - return component(spinner).withBinding(JBIntSpinner::getNumber, JBIntSpinner::setNumber, PropertyBinding(getter, setter)) + return component(spinner).withBindingInt(JBIntSpinner::getNumber, JBIntSpinner::setNumber, PropertyBinding(getter, setter)) } @ApiStatus.ScheduledForRemoval @@ -487,7 +493,7 @@ class InnerCell(val cell: Cell) : Cell() { } @ApiStatus.ScheduledForRemoval -@Deprecated("Use simplified method com.intellij.ui.dsl.builder.UtilsKt.listCellRenderer instead") +@Deprecated("Use com.intellij.ui.dsl.listCellRenderer.BuilderKt.textListCellRenderer/listCellRenderer instead", level = DeprecationLevel.HIDDEN) fun listCellRenderer(renderer: SimpleListCellRenderer.(value: T, index: Int, isSelected: Boolean) -> Unit): SimpleListCellRenderer { return object : SimpleListCellRenderer() { override fun customize(list: JList, value: T?, index: Int, selected: Boolean, hasFocus: Boolean) { diff --git a/platform/platform-impl/src/com/intellij/ui/layout/LayoutBuilder.kt b/platform/platform-impl/src/com/intellij/ui/layout/LayoutBuilder.kt index d60de69ea37a..9ff1f66ad644 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/LayoutBuilder.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/LayoutBuilder.kt @@ -15,11 +15,12 @@ open class LayoutBuilder @PublishedApi internal constructor(@PublishedApi intern @ApiStatus.ScheduledForRemoval -@Deprecated("Use Kotlin UI DSL Version 2") +@Deprecated("Use Kotlin UI DSL Version 2", level = DeprecationLevel.HIDDEN) class RowBuilderWithButtonGroupProperty + @PublishedApi @ApiStatus.ScheduledForRemoval -@Deprecated("Use Kotlin UI DSL Version 2") +@Deprecated("Use Kotlin UI DSL Version 2", level = DeprecationLevel.HIDDEN) internal constructor(private val builder: RowBuilder, private val prop: PropertyBinding) : RowBuilder by builder diff --git a/platform/platform-impl/src/com/intellij/ui/layout/Row.kt b/platform/platform-impl/src/com/intellij/ui/layout/Row.kt index f3d12e6b1dfd..286749fa1a74 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/Row.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/Row.kt @@ -42,7 +42,7 @@ interface RowBuilder : BaseBuilder { } @ApiStatus.ScheduledForRemoval - @Deprecated("Use Kotlin UI DSL Version 2") + @Deprecated("Use Kotlin UI DSL Version 2", level = DeprecationLevel.HIDDEN) fun titledRow(@NlsContexts.BorderTitle title: String, init: Row.() -> Unit): Row /** diff --git a/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt b/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt index 9250c30c431f..4c5b6e80949b 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt @@ -248,11 +248,11 @@ internal class MigLayoutRow(private val parent: MigLayoutRow?, } override fun titledRow(@NlsContexts.Separator title: String, init: Row.() -> Unit): Row { - return createBlockRow(title, true, init) + return createBlockRow(title, init) } - private fun createBlockRow(@NlsContexts.Separator title: String?, isSeparated: Boolean, init: Row.() -> Unit): Row { - val parentRow = createChildRow(indent = indent, title = title, isSeparated = isSeparated, incrementsIndent = isSeparated) + private fun createBlockRow(@NlsContexts.Separator title: String?, init: Row.() -> Unit): Row { + val parentRow = createChildRow(indent = indent, title = title, isSeparated = true, incrementsIndent = true) parentRow.init() val result = parentRow.createChildRow() result.internalPlaceholder() @@ -588,8 +588,3 @@ private val JComponent.origin: JComponent else -> this } } - -private fun Row.attachSubRowsEnabled(component: AbstractButton) { - subRowsEnabled = component.selected() - component.selected.addListener { subRowsEnabled = it } -} diff --git a/platform/platform-impl/src/com/intellij/ui/layout/migLayout/componentConstraints.kt b/platform/platform-impl/src/com/intellij/ui/layout/migLayout/componentConstraints.kt index c9361aadd54a..b0b3579a3ad7 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/migLayout/componentConstraints.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/migLayout/componentConstraints.kt @@ -41,7 +41,7 @@ internal fun overrideFlags(cc: CC, flags: Array) { @ApiStatus.ScheduledForRemoval @Deprecated("Mig Layout is going to be removed, IDEA-306719") -internal class DefaultComponentConstraintCreator(private val spacing: SpacingConfiguration) { +internal class DefaultComponentConstraintCreator(spacing: SpacingConfiguration) { private val shortTextSizeSpec = ConstraintParser.parseBoundSize("${spacing.shortTextWidth}px!", false, true) private val mediumTextSizeSpec = ConstraintParser.parseBoundSize("${spacing.shortTextWidth}px::${spacing.maxShortTextWidth}px", false, true)