Wizard: use first enum entry as default value for enumSetting
This commit is contained in:
+1
-1
@@ -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() {
|
||||
|
||||
+11
-1
@@ -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()
|
||||
}
|
||||
+4
-4
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+4
-5
@@ -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 {
|
||||
|
||||
+4
-4
@@ -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 ->
|
||||
|
||||
Reference in New Issue
Block a user