done: remove unit also remove it's empty parent

This commit is contained in:
Roy Qu 2022-10-02 16:25:00 +08:00
parent 8ca7377cfe
commit 9f39248dbc
1 changed files with 14 additions and 0 deletions

View File

@ -492,6 +492,20 @@ bool Project::removeUnit(int id, bool doClose , bool removeFile)
mModel.removeRow(row,parentIndex);
mUnits.remove(unit->id());
//remove empty parent node
PProjectModelNode currentNode = parentNode;
while (currentNode && currentNode->folderNodeType == ProjectModelNodeType::Folder && currentNode->children.isEmpty()) {
parentNode = currentNode->parent.lock();
if (!parentNode)
break;
row = parentNode->children.indexOf(currentNode);
if (row<0)
break;
parentIndex = mModel.getNodeIndex(parentNode.get());
mModel.removeRow(row,parentIndex);
currentNode = parentNode;
}
setModified(true);
return true;
}