Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 35922815 authored by Nicolas Carion's avatar Nicolas Carion

Fix forgotten deletion step

parent 30bbf15f
......@@ -233,34 +233,18 @@ std::shared_ptr<AbstractProjectItem> AbstractProjectItem::getEnclosingFolder(boo
bool AbstractProjectItem::selfSoftDelete(Fun &undo, Fun &redo)
{
Fun local_undo = []() { return true; };
Fun local_redo = []() { return true; };
for (const auto &child : m_childItems) {
std::static_pointer_cast<AbstractProjectItem>(child)->selfSoftDelete(undo, redo);
}
Fun operation = [this]() {
if (auto ptr = m_model.lock()) {
ptr->deregisterItem(m_id, this);
} else {
qDebug() << "ERROR: Something went wrong when deleting TreeItem. Model is not available anymore";
return false;
}
return true;
};
std::shared_ptr<TreeItem> self = shared_from_this();
Fun reverse = [this, self]() {
// self is capture explicitly to prevent deletion of the object
if (auto ptr = m_model.lock()) {
ptr->registerItem(self);
} else {
qDebug() << "ERROR: Something went wrong when deleting TreeItem. Model is not available anymore";
bool res = std::static_pointer_cast<AbstractProjectItem>(child)->selfSoftDelete(local_undo, local_redo);
if (!res) {
bool undone = local_undo();
Q_ASSERT(undone);
return false;
}
return true;
};
if (operation()) {
UPDATE_UNDO_REDO(operation, reverse, undo, redo);
return true;
}
return false;
UPDATE_UNDO_REDO(local_redo, local_undo, undo, redo);
return true;
}
QString AbstractProjectItem::lastParentId() const
......
......@@ -392,6 +392,7 @@ bool ProjectItemModel::requestBinClipDeletion(std::shared_ptr<AbstractProjectIte
if (!clip) return false;
int parentId = -1;
if (auto ptr = clip->parent()) parentId = ptr->getId();
clip->selfSoftDelete(undo, redo);
int id = clip->getId();
Fun operation = removeBin_lambda(id);
Fun reverse = addBin_lambda(clip, parentId);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment