mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Better node error implementation
This commit is contained in:
@@ -24,6 +24,7 @@ import android.util.Log
|
|||||||
import com.kunzisoft.keepass.database.element.*
|
import com.kunzisoft.keepass.database.element.*
|
||||||
import com.kunzisoft.keepass.database.exception.CopyDatabaseEntryException
|
import com.kunzisoft.keepass.database.exception.CopyDatabaseEntryException
|
||||||
import com.kunzisoft.keepass.database.exception.CopyDatabaseGroupException
|
import com.kunzisoft.keepass.database.exception.CopyDatabaseGroupException
|
||||||
|
import com.kunzisoft.keepass.database.exception.LoadDatabaseException
|
||||||
|
|
||||||
class CopyNodesRunnable constructor(
|
class CopyNodesRunnable constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
@@ -38,33 +39,42 @@ class CopyNodesRunnable constructor(
|
|||||||
|
|
||||||
override fun nodeAction() {
|
override fun nodeAction() {
|
||||||
|
|
||||||
mNodesToCopy.forEach { currentNode ->
|
var error: LoadDatabaseException? = null
|
||||||
|
foreachNode@ for(currentNode in mNodesToCopy) {
|
||||||
|
|
||||||
when (currentNode.type) {
|
when (currentNode.type) {
|
||||||
Type.GROUP -> {
|
Type.GROUP -> {
|
||||||
Log.e(TAG, "Copy not allowed for group")// Only finish thread
|
Log.e(TAG, "Copy not allowed for group")// Only finish thread
|
||||||
throwErrorAndFinish(CopyDatabaseGroupException())
|
error = CopyDatabaseGroupException()
|
||||||
|
break@foreachNode
|
||||||
}
|
}
|
||||||
Type.ENTRY -> {
|
Type.ENTRY -> {
|
||||||
// Root can contains entry
|
// Root can contains entry
|
||||||
if (mNewParent != database.rootGroup || database.rootCanContainsEntry()) {
|
if (mNewParent != database.rootGroup || database.rootCanContainsEntry()) {
|
||||||
// Update entry with new values
|
// Update entry with new values
|
||||||
mNewParent.touch(modified = false, touchParents = true)
|
mNewParent.touch(modified = false, touchParents = true)
|
||||||
database.copyEntryTo(currentNode as EntryVersioned, mNewParent)?.let { entryCopied ->
|
|
||||||
|
val entryCopied = database.copyEntryTo(currentNode as EntryVersioned, mNewParent)
|
||||||
|
if (entryCopied != null) {
|
||||||
entryCopied.touch(modified = true, touchParents = true)
|
entryCopied.touch(modified = true, touchParents = true)
|
||||||
mEntriesCopied.add(entryCopied)
|
mEntriesCopied.add(entryCopied)
|
||||||
} ?: run {
|
} else {
|
||||||
Log.e(TAG, "Unable to create a copy of the entry")
|
Log.e(TAG, "Unable to create a copy of the entry")
|
||||||
throwErrorAndFinish(CopyDatabaseEntryException())
|
error = CopyDatabaseEntryException()
|
||||||
|
break@foreachNode
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Only finish thread
|
// Only finish thread
|
||||||
throwErrorAndFinish(CopyDatabaseEntryException())
|
error = CopyDatabaseEntryException()
|
||||||
|
break@foreachNode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
saveDatabaseAndFinish()
|
if (error != null)
|
||||||
|
throwErrorAndFinish(error)
|
||||||
|
else
|
||||||
|
saveDatabaseAndFinish()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun nodeFinish(result: Result): ActionNodeValues {
|
override fun nodeFinish(result: Result): ActionNodeValues {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class DeleteNodesRunnable(context: Context,
|
|||||||
|
|
||||||
override fun nodeAction() {
|
override fun nodeAction() {
|
||||||
|
|
||||||
mNodesToDelete.forEach { currentNode ->
|
foreachNode@ for(currentNode in mNodesToDelete) {
|
||||||
mParent = currentNode.parent
|
mParent = currentNode.parent
|
||||||
mParent?.touch(modified = false, touchParents = true)
|
mParent?.touch(modified = false, touchParents = true)
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ package com.kunzisoft.keepass.database.action.node
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.kunzisoft.keepass.database.element.*
|
import com.kunzisoft.keepass.database.element.*
|
||||||
|
import com.kunzisoft.keepass.database.exception.LoadDatabaseException
|
||||||
import com.kunzisoft.keepass.database.exception.MoveDatabaseEntryException
|
import com.kunzisoft.keepass.database.exception.MoveDatabaseEntryException
|
||||||
import com.kunzisoft.keepass.database.exception.MoveDatabaseGroupException
|
import com.kunzisoft.keepass.database.exception.MoveDatabaseGroupException
|
||||||
|
|
||||||
@@ -38,10 +39,10 @@ class MoveNodesRunnable constructor(
|
|||||||
|
|
||||||
override fun nodeAction() {
|
override fun nodeAction() {
|
||||||
|
|
||||||
mNodesToMove.forEach { nodeToMove ->
|
var error: LoadDatabaseException? = null
|
||||||
|
foreachNode@ for(nodeToMove in mNodesToMove) {
|
||||||
// Move node in new parent
|
// Move node in new parent
|
||||||
mOldParent = nodeToMove.parent
|
mOldParent = nodeToMove.parent
|
||||||
nodeToMove.touch(modified = true, touchParents = true)
|
|
||||||
|
|
||||||
when (nodeToMove.type) {
|
when (nodeToMove.type) {
|
||||||
Type.GROUP -> {
|
Type.GROUP -> {
|
||||||
@@ -49,10 +50,12 @@ class MoveNodesRunnable constructor(
|
|||||||
// Move group in new parent if not in the current group
|
// Move group in new parent if not in the current group
|
||||||
if (groupToMove != mNewParent
|
if (groupToMove != mNewParent
|
||||||
&& !mNewParent.isContainedIn(groupToMove)) {
|
&& !mNewParent.isContainedIn(groupToMove)) {
|
||||||
|
nodeToMove.touch(modified = true, touchParents = true)
|
||||||
database.moveGroupTo(groupToMove, mNewParent)
|
database.moveGroupTo(groupToMove, mNewParent)
|
||||||
} else {
|
} else {
|
||||||
// Only finish thread
|
// Only finish thread
|
||||||
throwErrorAndFinish(MoveDatabaseGroupException())
|
error = MoveDatabaseGroupException()
|
||||||
|
break@foreachNode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Type.ENTRY -> {
|
Type.ENTRY -> {
|
||||||
@@ -61,15 +64,20 @@ class MoveNodesRunnable constructor(
|
|||||||
if (mOldParent != mNewParent
|
if (mOldParent != mNewParent
|
||||||
// and root can contains entry
|
// and root can contains entry
|
||||||
&& (mNewParent != database.rootGroup || database.rootCanContainsEntry())) {
|
&& (mNewParent != database.rootGroup || database.rootCanContainsEntry())) {
|
||||||
|
nodeToMove.touch(modified = true, touchParents = true)
|
||||||
database.moveEntryTo(entryToMove, mNewParent)
|
database.moveEntryTo(entryToMove, mNewParent)
|
||||||
} else {
|
} else {
|
||||||
// Only finish thread
|
// Only finish thread
|
||||||
throwErrorAndFinish(MoveDatabaseEntryException())
|
error = MoveDatabaseEntryException()
|
||||||
|
break@foreachNode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
saveDatabaseAndFinish()
|
if (error != null)
|
||||||
|
throwErrorAndFinish(error)
|
||||||
|
else
|
||||||
|
saveDatabaseAndFinish()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun nodeFinish(result: Result): ActionNodeValues {
|
override fun nodeFinish(result: Result): ActionNodeValues {
|
||||||
|
|||||||
Reference in New Issue
Block a user