1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 16:49:41 +02:00

PopupMenuTable supports registration

This commit is contained in:
Paul Licameli 2020-02-08 16:19:47 -05:00
parent 63c7f6b722
commit cfd07af245
2 changed files with 24 additions and 2 deletions

View File

@ -142,7 +142,14 @@ void PopupMenuTable::ExtendMenu( wxMenu &menu, PopupMenuTable &table )
theMenu.tables.push_back( &table );
PopupMenuBuilder visitor{ table, theMenu, theMenu.pUserData };
Registry::Visit( visitor, table.Get( theMenu.pUserData ).get() );
Registry::Visit(
visitor, table.Get( theMenu.pUserData ).get(), table.GetRegistry() );
}
void PopupMenuTable::RegisterItem(
const Registry::Placement &placement, Registry::BaseItemPtr pItem )
{
Registry::RegisterItem( *mRegistry, placement, std::move( pItem ) );
}
void PopupMenuTable::Append( Registry::BaseItemPtr pItem )
@ -195,7 +202,8 @@ void PopupMenu::DisconnectTable(PopupMenuTable *pTable)
};
PopupMenuDestroyer visitor{ *pTable, *this };
Registry::Visit( visitor, pTable->Get( nullptr ).get() );
Registry::Visit( visitor, pTable->Get( nullptr ).get(),
pTable->GetRegistry() );
}
void PopupMenu::Disconnect()

View File

@ -109,6 +109,7 @@ public:
PopupMenuTable( const Identifier &id, const TranslatableString &caption = {} )
: mId{ id }
, mCaption{ caption }
, mRegistry{ std::make_unique<Registry::TransparentGroupItem<>>( mId ) }
{}
// Optional pUserData gets passed to the InitUserData routines of tables.
@ -118,6 +119,14 @@ public:
const Identifier &Id() const { return mId; }
const TranslatableString &Caption() const { return mCaption; }
const Registry::GroupItem *GetRegistry() const { return mRegistry.get(); }
// Typically statically constructed:
struct AttachedItem {
AttachedItem( PopupMenuTable &table,
const Registry::Placement &placement, Registry::BaseItemPtr pItem )
{ table.RegisterItem( placement, std::move( pItem ) ); }
};
// menu must have been built by BuildMenu
// More items get added to the end of it
@ -132,6 +141,10 @@ public:
return mTop;
}
private:
void RegisterItem(
const Registry::Placement &placement, Registry::BaseItemPtr pItem );
protected:
virtual void Populate() = 0;
@ -168,6 +181,7 @@ protected:
std::vector< Registry::GroupItem* > mStack;
Identifier mId;
TranslatableString mCaption;
std::unique_ptr<Registry::GroupItem> mRegistry;
};
// A "CRTP" class that injects a convenience function, which appends a menu item