Skip to content

Commit

Permalink
Prevent #504 from happening, where a folder cannot be deleted after m…
Browse files Browse the repository at this point in the history
…oving a note into the same folder it was already in
  • Loading branch information
zjeffer committed Jan 16, 2025
1 parent fa766a7 commit 8caf9fa
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/treeviewlogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,24 @@ void TreeViewLogic::onMoveNodeRequested(int nodeId, int targetId)
NodeData target;
QMetaObject::invokeMethod(m_dbManager, "getNode", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(NodeData, target), Q_ARG(int, targetId));
// only allow moving a node into a folder
if (target.nodeType() != NodeData::Folder) {
qDebug() << __FUNCTION__ << "Target is not folder!";
return;
}
// don't allow moving a node into itself (not sure how this can ever happen but just in case)
if (nodeId == targetId) {
qDebug() << __FUNCTION__ << "Can't move a node into itself";
return;
}
// don't allow moving a node into the same parent
NodeData node;
QMetaObject::invokeMethod(m_dbManager, "getNode", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(NodeData, node), Q_ARG(int, nodeId));
if (node.parentId() == targetId) {
qDebug() << __FUNCTION__ << "Can't move a node into the same parent";
return;
}
emit requestMoveNodeInDB(nodeId, target);
}

Expand Down

0 comments on commit 8caf9fa

Please sign in to comment.