Skip to content

Commit 8caf9fa

Browse files
committed
Prevent #504 from happening, where a folder cannot be deleted after moving a note into the same folder it was already in
1 parent fa766a7 commit 8caf9fa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/treeviewlogic.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,24 @@ void TreeViewLogic::onMoveNodeRequested(int nodeId, int targetId)
384384
NodeData target;
385385
QMetaObject::invokeMethod(m_dbManager, "getNode", Qt::BlockingQueuedConnection,
386386
Q_RETURN_ARG(NodeData, target), Q_ARG(int, targetId));
387+
// only allow moving a node into a folder
387388
if (target.nodeType() != NodeData::Folder) {
388389
qDebug() << __FUNCTION__ << "Target is not folder!";
389390
return;
390391
}
392+
// don't allow moving a node into itself (not sure how this can ever happen but just in case)
393+
if (nodeId == targetId) {
394+
qDebug() << __FUNCTION__ << "Can't move a node into itself";
395+
return;
396+
}
397+
// don't allow moving a node into the same parent
398+
NodeData node;
399+
QMetaObject::invokeMethod(m_dbManager, "getNode", Qt::BlockingQueuedConnection,
400+
Q_RETURN_ARG(NodeData, node), Q_ARG(int, nodeId));
401+
if (node.parentId() == targetId) {
402+
qDebug() << __FUNCTION__ << "Can't move a node into the same parent";
403+
return;
404+
}
391405
emit requestMoveNodeInDB(nodeId, target);
392406
}
393407

0 commit comments

Comments
 (0)