mirror of
https://github.com/cookiengineer/audacity
synced 2026-03-10 00:15:31 +01:00
Change class hierarchy of MenuTable::BaseItem...
... There are now four immediate subclasses (SharedItem and Computed Item, which are final, and SingleItem and GroupItem, which are abstract), which may serve future purposes more general than menu items. There are further subclasses specific to menu management. The former concrete class GroupItem is renamed TransparentGroupItem. Also allows direct construction of items in lists from shared pointers.
This commit is contained in:
@@ -104,8 +104,12 @@ namespace MenuTable {
|
||||
|
||||
BaseItem::~BaseItem() {}
|
||||
|
||||
SharedItem::~SharedItem() {}
|
||||
|
||||
ComputedItem::~ComputedItem() {}
|
||||
|
||||
SingleItem::~SingleItem() {}
|
||||
|
||||
GroupItem::GroupItem( BaseItemPtrs &&items_ )
|
||||
: items{ std::move( items_ ) }
|
||||
{
|
||||
@@ -116,6 +120,11 @@ void GroupItem::AppendOne( BaseItemPtr&& ptr )
|
||||
}
|
||||
GroupItem::~GroupItem() {}
|
||||
|
||||
TransparentGroupItem::~TransparentGroupItem() {}
|
||||
}
|
||||
|
||||
namespace MenuTable {
|
||||
|
||||
MenuItem::MenuItem( const TranslatableString &title_, BaseItemPtrs &&items_ )
|
||||
: GroupItem{ std::move( items_ ) }, title{ title_ }
|
||||
{
|
||||
@@ -188,6 +197,12 @@ void VisitItem( AudacityProject &project, MenuTable::BaseItem *pItem )
|
||||
auto &manager = CommandManager::Get( project );
|
||||
|
||||
using namespace MenuTable;
|
||||
if (const auto pShared =
|
||||
dynamic_cast<SharedItem*>( pItem )) {
|
||||
auto delegate = pShared->ptr;
|
||||
VisitItem( project, delegate.get() );
|
||||
}
|
||||
else
|
||||
if (const auto pComputed =
|
||||
dynamic_cast<ComputedItem*>( pItem )) {
|
||||
// TODO maybe? memo-ize the results of the function, but that requires
|
||||
@@ -235,7 +250,7 @@ void VisitItem( AudacityProject &project, MenuTable::BaseItem *pItem )
|
||||
}
|
||||
else
|
||||
if (const auto pGroup =
|
||||
dynamic_cast<GroupItem*>( pItem )) {
|
||||
dynamic_cast<TransparentGroupItem*>( pItem )) {
|
||||
// recursion
|
||||
VisitItems( project, pGroup->items );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user