Fix default values

This commit is contained in:
J-Jamet
2021-07-18 20:51:33 +02:00
parent 0d83725b77
commit edaf9f6296

View File

@@ -76,6 +76,7 @@ class TemplateEngineCompatible(database: DatabaseKDBX): TemplateEngine(database)
override fun decodeTemplateEntry(templateEntry: EntryKDBX): EntryKDBX {
val attributes = HashMap<String, TemplateAttributePosition>()
val defaultValues = HashMap<String, String>()
val entryCopy = EntryKDBX().apply {
updateWith(templateEntry)
}
@@ -179,11 +180,8 @@ class TemplateEngineCompatible(database: DatabaseKDBX): TemplateEngine(database)
}
else -> {
// To retrieve default values
if (attributes.containsKey(label)) {
if (value.isNotEmpty()) {
val attribute = attributes[label]!!
attribute.attribute.default = value
}
if (value.isNotEmpty()) {
defaultValues[label] = value
}
entryCopy.removeField(label)
}
@@ -200,6 +198,11 @@ class TemplateEngineCompatible(database: DatabaseKDBX): TemplateEngine(database)
attribute.options.associatePasswordGenerator()
}
// Add default value
if (defaultValues.containsKey(attribute.label)) {
attribute.options.default = defaultValues[attribute.label]!!
}
// Recognize each temp option
attribute.options.get(TEMPLATE_ATTRIBUTE_OPTIONS_TEMP)?.let { defaultOption ->
when (attribute.type) {