Skip to content

Commit

Permalink
Traktor: When removing group in DatabaseView it's children are also r…
Browse files Browse the repository at this point in the history
…emoved.
  • Loading branch information
apistol78 committed Nov 2, 2023
1 parent 1f8e096 commit 90e689b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
7 changes: 7 additions & 0 deletions code/Database/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ bool Group::remove()
if (!m_providerGroup->remove())
return false;

m_parent->internalRemoveGroup(this);
internalDestroy();
return true;
}
Expand Down Expand Up @@ -322,6 +323,12 @@ bool Group::internalAddExtInstance(const Guid& instanceGuid)
return false;
}

void Group::internalRemoveGroup(Group* childGroup)
{
T_ANONYMOUS_VAR(Acquire< Semaphore >)(m_lock);
m_childGroups.remove(childGroup);
}

void Group::instanceEventCreated(Instance* instance)
{
// Add child instance.
Expand Down
2 changes: 2 additions & 0 deletions code/Database/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class T_DLLCLASS Group

bool internalAddExtInstance(const Guid& instanceGuid);

void internalRemoveGroup(Group* childGroup);

// \name IInstanceEventListener
// \{

Expand Down
35 changes: 32 additions & 3 deletions code/Editor/App/DatabaseView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,37 @@ bool replaceIdentifiers(RfmCompound* reflection, const std::list< InstanceClipbo
return modified;
}

bool removeGroup(db::Group* group)
{
// Recurse with child groups first.
RefArray< db::Group > childGroups;
group->getChildGroups(childGroups);
for (auto childGroup : childGroups)
{
if (!removeGroup(childGroup))
return false;
}

// No more child groups; now remove all child instances.
RefArray< db::Instance > childInstances;
group->getChildInstances(childInstances);
for (auto childInstance : childInstances)
{
if (!childInstance->checkout())
return false;
if (!childInstance->remove())
return false;
if (!childInstance->commit())
return false;
}

// Finally remove this group since it's now empty.
if (!group->remove())
return false;

return true;
}

}

DatabaseView::DatabaseView(IEditor* editor)
Expand Down Expand Up @@ -665,10 +696,8 @@ bool DatabaseView::handleCommand(const ui::Command& command)

if (!instance->checkout())
return false;

if (!instance->remove())
return false;

if (!instance->commit())
return false;

Expand Down Expand Up @@ -948,7 +977,7 @@ bool DatabaseView::handleCommand(const ui::Command& command)
if (ui::MessageBox::show(this, i18n::Text(L"DATABASE_DELETE_ARE_YOU_SURE"), i18n::Text(L"DATABASE_DELETE_GROUP"), ui::MbYesNo | ui::MbIconQuestion) != ui::DialogResult::Yes)
return false;

if (!group->remove())
if (!removeGroup(group))
return false;

updateView();
Expand Down

0 comments on commit 90e689b

Please sign in to comment.