mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 16:22:31 -08:00
Fix template creation
This commit is contained in:
1 parent
4afbb688ba
commit
b55b3731a5
3 files changed
+14
-6
No files matched your search
@@ -149,6 +149,8 @@ class Database {
|
||||
}
|
||||
|
||||
fun getTemplate(entry: Entry): Template? {
|
||||
if (entryIsTemplate(entry))
|
||||
return Template.CREATION
|
||||
entry.entryKDBX?.let { entryKDBX ->
|
||||
return mDatabaseKDBX?.getTemplate(entryKDBX)
|
||||
}
|
||||
|
||||
@@ -101,21 +101,24 @@ class EntryEditViewModel: ViewModel() {
|
||||
registerInfo: RegisterInfo?,
|
||||
searchInfo: SearchInfo?) {
|
||||
mParent = mDatabase?.getGroupById(parentId)
|
||||
mEntry = mDatabase?.createEntry().apply {
|
||||
mEntry = mDatabase?.createEntry()?.apply {
|
||||
// Add the default icon from parent if not a folder
|
||||
val parentIcon = mParent?.icon
|
||||
// Set default icon
|
||||
if (parentIcon != null) {
|
||||
if (parentIcon.custom.isUnknown
|
||||
&& parentIcon.standard.id != IconImageStandard.FOLDER_ID) {
|
||||
this?.icon = IconImage(parentIcon.standard)
|
||||
icon = IconImage(parentIcon.standard)
|
||||
}
|
||||
if (!parentIcon.custom.isUnknown) {
|
||||
this?.icon = IconImage(parentIcon.custom)
|
||||
icon = IconImage(parentIcon.custom)
|
||||
}
|
||||
}
|
||||
// Set default username
|
||||
this?.username = mDatabase?.defaultUsername ?: ""
|
||||
username = mDatabase?.defaultUsername ?: ""
|
||||
// Warning only the entry recognize is parent, parent don't yet recognize the new entry
|
||||
// Useful to recognize child state (ie: entry is a template)
|
||||
parent = mParent
|
||||
}
|
||||
|
||||
loadTemplates()
|
||||
@@ -123,11 +126,11 @@ class EntryEditViewModel: ViewModel() {
|
||||
}
|
||||
|
||||
private fun loadTemplates() {
|
||||
val templates = mDatabase?.getTemplates(mIsTemplate) ?: listOf()
|
||||
|
||||
// Define is current entry is a template (in direct template group)
|
||||
mIsTemplate = mDatabase?.entryIsTemplate(mEntry) ?: false
|
||||
|
||||
val templates = mDatabase?.getTemplates(mIsTemplate) ?: listOf()
|
||||
|
||||
val entryTemplate = mEntry?.let {
|
||||
mDatabase?.getTemplate(it)
|
||||
} ?: Template.STANDARD
|
||||
|
||||
@@ -52,14 +52,17 @@ class EntryViewModel: ViewModel() {
|
||||
{
|
||||
// Manage current version and history
|
||||
mLastEntryVersion = mDatabase?.getEntryById(entryId)
|
||||
|
||||
mEntry = if (historyPosition > -1) {
|
||||
mLastEntryVersion?.getHistory()?.get(historyPosition)
|
||||
} else {
|
||||
mLastEntryVersion
|
||||
}
|
||||
|
||||
mEntryTemplate = mEntry?.let {
|
||||
mDatabase?.getTemplate(it)
|
||||
} ?: Template.STANDARD
|
||||
|
||||
mHistoryPosition = historyPosition
|
||||
|
||||
// To simplify template field visibility
|
||||
|
||||
Reference in new issue
Block a user