Wizard: use first enum entry as default value for enumSetting

This commit is contained in:
Ilya Kirillov
2020-02-21 19:10:00 +03:00
parent 3967522c08
commit ad39d0520a
6 changed files with 25 additions and 16 deletions
@@ -64,10 +64,10 @@ class TargetsModel(
fun add(module: Module) {
uiEditorUsagesStats.modulesCreated++
addToTheTree(module, modifyValue = true, parent = tree.selectedNode ?: root)
with(readingContext) {
module.apply { initDefaultValuesForSettings() }
}
addToTheTree(module, modifyValue = true, parent = tree.selectedNode ?: root)
}
fun update() {
@@ -1,8 +1,8 @@
package org.jetbrains.kotlin.tools.projectWizard
import org.jetbrains.kotlin.tools.projectWizard.core.EntitiesOwnerDescriptor
import org.jetbrains.kotlin.tools.projectWizard.core.Parser
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
import org.jetbrains.kotlin.tools.projectWizard.core.enumParser
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
import kotlin.properties.ReadOnlyProperty
@@ -77,3 +77,13 @@ interface SettingsOwner {
}
}
inline fun <reified E> SettingsOwner.enumSettingImpl(
title: String,
neededAtPhase: GenerationPhase,
crossinline init: DropDownSettingType.Builder<E>.() -> Unit = {}
) where E : Enum<E>, E : DisplayableSettingItem = dropDownSetting<E>(title, neededAtPhase, enumParser()) {
values = enumValues<E>().asList()
defaultValue = values.firstOrNull()
init()
}
@@ -2,6 +2,7 @@ package org.jetbrains.kotlin.tools.projectWizard.core
import org.jetbrains.kotlin.tools.projectWizard.SettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
import org.jetbrains.kotlin.tools.projectWizard.enumSettingImpl
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
import org.jetbrains.kotlin.tools.projectWizard.settings.version.Version
@@ -154,14 +155,13 @@ abstract class Plugin(override val context: Context) : EntityBase(),
): ReadOnlyProperty<Any, PluginSetting<Path, PathSettingType>> =
super.pathSetting(title, neededAtPhase, init) as ReadOnlyProperty<Any, PluginSetting<Path, PathSettingType>>
@Suppress("UNCHECKED_CAST")
inline fun <reified E> enumSetting(
title: String,
neededAtPhase: GenerationPhase,
crossinline init: DropDownSettingType.Builder<E>.() -> Unit = {}
) where E : Enum<E>, E : DisplayableSettingItem = dropDownSetting<E>(title, neededAtPhase, enumParser()) {
values = enumValues<E>().asList()
init()
}
): ReadOnlyProperty<Any, PluginSetting<E, DropDownSettingType<E>>> where E : Enum<E>, E : DisplayableSettingItem =
enumSettingImpl(title, neededAtPhase, init) as ReadOnlyProperty<Any, PluginSetting<E, DropDownSettingType<E>>>
}
val PluginReference.withParentPlugins
@@ -42,7 +42,7 @@ open class ReadingContext(
val <V : Any, T : SettingType<V>> PluginSettingReference<V, T>.pluginSetting: Setting<V, T>
get() = context.settingContext.getPluginSetting(this)
fun <V : Any> Setting<V, SettingType<V>>.getSavedValueForSetting(): V? {
private fun <V : Any> Setting<V, SettingType<V>>.getSavedValueForSetting(): V? {
if (!isSavable || this !is PluginSetting<*, *>) return null
val serializer = type.serializer.safeAs<SerializerImpl<V>>() ?: return null
val savedValue = service<SettingSavingWizardService>().getSettingValue(path) ?: return null
@@ -5,6 +5,7 @@ import org.jetbrains.kotlin.tools.projectWizard.SettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.core.*
import org.jetbrains.kotlin.tools.projectWizard.core.cached
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
import org.jetbrains.kotlin.tools.projectWizard.enumSettingImpl
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildSystemIR
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.KotlinBuildSystemPluginIR
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.StdlibType
@@ -148,15 +149,13 @@ abstract class ModuleConfiguratorSettings : SettingsOwner {
init
) as ReadOnlyProperty<Any, ModuleConfiguratorSetting<Path, PathSettingType>>
@Suppress("UNCHECKED_CAST")
inline fun <reified E> enumSetting(
title: String,
neededAtPhase: GenerationPhase,
crossinline init: DropDownSettingType.Builder<E>.() -> Unit = {}
) where E : Enum<E>, E : DisplayableSettingItem = dropDownSetting<E>(title, neededAtPhase, enumParser()) {
values = enumValues<E>().asList()
init()
}
): ReadOnlyProperty<Any, ModuleConfiguratorSetting<E, DropDownSettingType<E>>> where E : Enum<E>, E : DisplayableSettingItem =
enumSettingImpl(title, neededAtPhase, init) as ReadOnlyProperty<Any, ModuleConfiguratorSetting<E, DropDownSettingType<E>>>
}
interface ModuleConfiguratorWithSettings : ModuleConfigurator {
@@ -5,6 +5,7 @@ import org.jetbrains.kotlin.tools.projectWizard.SettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.WizardRunConfiguration
import org.jetbrains.kotlin.tools.projectWizard.core.*
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
import org.jetbrains.kotlin.tools.projectWizard.enumSettingImpl
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildSystemIR
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.DependencyIR
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.ModuleIR
@@ -221,14 +222,13 @@ abstract class Template : SettingsOwner, EntitiesOwnerDescriptor {
init
) as ReadOnlyProperty<Any, TemplateSetting<Path, PathSettingType>>
@Suppress("UNCHECKED_CAST")
inline fun <reified E> enumSetting(
title: String,
neededAtPhase: GenerationPhase,
crossinline init: DropDownSettingType.Builder<E>.() -> Unit = {}
) where E : Enum<E>, E : DisplayableSettingItem = dropDownSetting<E>(title, neededAtPhase, enumParser()) {
values = enumValues<E>().asList()
init()
}
): ReadOnlyProperty<Any, TemplateSetting<E, DropDownSettingType<E>>> where E : Enum<E>, E : DisplayableSettingItem =
enumSettingImpl(title, neededAtPhase, init) as ReadOnlyProperty<Any, TemplateSetting<E, DropDownSettingType<E>>>
companion object {
fun parser(sourcesetIdentificator: Identificator): Parser<Template> = mapParser { map, path ->