From 67034546ae32c8a9627ecdf2fa494de032b15bf4 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Fri, 20 Mar 2020 12:51:08 +0300 Subject: [PATCH] Wizard: do not show drop down component if it has <= 1 possible values --- .../wizard/ui/components/DropDownComponent.kt | 8 +++----- .../wizard/ui/setting/DefaultSettingComponent.kt | 3 +++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/DropDownComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/DropDownComponent.kt index db03ebd5481..4c86d39a390 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/DropDownComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/DropDownComponent.kt @@ -19,7 +19,7 @@ class DropDownComponent( initialValues: List = emptyList(), initiallySelectedValue: T? = null, labelText: String? = null, - private val filter: (T) -> Boolean = { true }, + filter: (T) -> Boolean = { true }, private val validator: SettingValidator = settingValidator { ValidationResult.OK }, private val iconProvider: (T) -> Icon? = { null }, onValueUpdate: (T) -> Unit = {} @@ -68,10 +68,8 @@ class DropDownComponent( } } - fun setValues(newValues: List) { - @Suppress("UNCHECKED_CAST") - uiComponent.model = DefaultComboBoxModel(newValues.filter(filter).toTypedArray() as Array) - } + val valuesCount + get() = uiComponent.model.size override fun updateUiValue(newValue: T) = safeUpdateUi { uiComponent.selectedItem = newValue diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/DefaultSettingComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/DefaultSettingComponent.kt index ab90290594d..f6365ccc48a 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/DefaultSettingComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/DefaultSettingComponent.kt @@ -118,6 +118,9 @@ class DropdownSettingComponent( labelText = setting.title.takeIf { needLabel }, onValueUpdate = { newValue -> value = newValue } ).asSubComponent() + + override fun shouldBeShow(): Boolean = + uiComponent.valuesCount > 1 } class BooleanSettingComponent(