Wizard: minor, commonize settings initialization with default values
This commit is contained in:
+7
@@ -21,4 +21,11 @@ open class SettingsWritingContext(context: Context, servicesManager: ServicesMan
|
|||||||
fun <V : Any, T : SettingType<V>> SettingReference<V, T>.setValue(newValue: V) {
|
fun <V : Any, T : SettingType<V>> SettingReference<V, T>.setValue(newValue: V) {
|
||||||
context.settingContext[this] = newValue
|
context.settingContext[this] = newValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <V : Any, T : SettingType<V>> SettingReference<V, T>.setSettingValueToItsDefaultIfItIsNotSetValue() {
|
||||||
|
val defaultValue = savedOrDefaultValue ?: return
|
||||||
|
if (notRequiredSettingValue == null) {
|
||||||
|
setValue(defaultValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+1
-5
@@ -169,11 +169,7 @@ interface ModuleConfiguratorWithSettings : ModuleConfigurator {
|
|||||||
fun SettingsWritingContext.initDefaultValuesFor(module: Module) {
|
fun SettingsWritingContext.initDefaultValuesFor(module: Module) {
|
||||||
withSettingsOf(module) {
|
withSettingsOf(module) {
|
||||||
getConfiguratorSettings().forEach { setting ->
|
getConfiguratorSettings().forEach { setting ->
|
||||||
val reference = setting.reference
|
setting.reference.setSettingValueToItsDefaultIfItIsNotSetValue()
|
||||||
val defaultValue = reference.savedOrDefaultValue ?: return@forEach
|
|
||||||
if (reference.notRequiredSettingValue == null) {
|
|
||||||
reference.setValue(defaultValue)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -78,11 +78,7 @@ abstract class Template : SettingsOwner, EntitiesOwnerDescriptor {
|
|||||||
fun SettingsWritingContext.initDefaultValuesFor(module: Module) {
|
fun SettingsWritingContext.initDefaultValuesFor(module: Module) {
|
||||||
withSettingsOf(module) {
|
withSettingsOf(module) {
|
||||||
settings.forEach { setting ->
|
settings.forEach { setting ->
|
||||||
val reference = setting.reference
|
setting.reference.setSettingValueToItsDefaultIfItIsNotSetValue()
|
||||||
val defaultValue = reference.savedOrDefaultValue ?: return@forEach
|
|
||||||
if (reference.notRequiredSettingValue == null) {
|
|
||||||
reference.setValue(defaultValue)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-4
@@ -40,10 +40,7 @@ abstract class Wizard(createPlugins: PluginsCreator, val servicesManager: Servic
|
|||||||
private fun initPluginDefaultValues() {
|
private fun initPluginDefaultValues() {
|
||||||
with(settingsWritingContext) {
|
with(settingsWritingContext) {
|
||||||
for (setting in pluginSettings) {
|
for (setting in pluginSettings) {
|
||||||
if (setting.reference.notRequiredSettingValue == null) {
|
setting.reference.setSettingValueToItsDefaultIfItIsNotSetValue()
|
||||||
val defaultValue = setting.reference.savedOrDefaultValue ?: continue
|
|
||||||
setting.reference.setValue(defaultValue)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user