diff --git a/src/Menus.cpp b/src/Menus.cpp index 756fd2db6..7755e2e46 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -123,6 +123,7 @@ void Visitor::Visit(SingleItem &, const Path &) {} void MenuVisitor::BeginGroup( Registry::GroupItem &item, const Path &path ) { bool isMenu = false; + bool isExtension = false; auto pItem = &item; if ( pItem->Transparent() ) { } @@ -130,8 +131,9 @@ void MenuVisitor::BeginGroup( Registry::GroupItem &item, const Path &path ) if ( !needSeparator.empty() ) needSeparator.back() = true; } - else { + else if ( auto pWhole = dynamic_cast( pItem ) ) { isMenu = true; + isExtension = pWhole->extension; MaybeDoSeparator(); } @@ -139,7 +141,7 @@ void MenuVisitor::BeginGroup( Registry::GroupItem &item, const Path &path ) if ( isMenu ) { needSeparator.push_back( false ); - firstItem.push_back( true ); + firstItem.push_back( !isExtension ); } } @@ -152,7 +154,7 @@ void MenuVisitor::EndGroup( Registry::GroupItem &item, const Path &path ) if ( !needSeparator.empty() ) needSeparator.back() = true; } - else { + else if ( dynamic_cast( pItem ) ) { firstItem.pop_back(); needSeparator.pop_back(); } @@ -241,6 +243,7 @@ CommandGroupItem::~CommandGroupItem() {} SpecialItem::~SpecialItem() {} MenuSection::~MenuSection() {} +WholeMenu::~WholeMenu() {} CommandHandlerFinder FinderScope::sFinder = [](AudacityProject &project) -> CommandHandlerObject & { diff --git a/src/commands/CommandManager.h b/src/commands/CommandManager.h index 932c37400..e073c6cec 100644 --- a/src/commands/CommandManager.h +++ b/src/commands/CommandManager.h @@ -695,8 +695,19 @@ struct ToolbarMenuVisitor : MenuVisitor namespace MenuTable { using namespace Registry; + // These are found by dynamic_cast + struct MenuSection { + virtual ~MenuSection(); + }; + struct WholeMenu { + WholeMenu( bool extend = false ) : extension{ extend } {} + virtual ~WholeMenu(); + bool extension; + }; + // Describes a main menu in the toolbar, or a sub-menu - struct MenuItem final : ConcreteGroupItem< false, ToolbarMenuVisitor > { + struct MenuItem final : ConcreteGroupItem< false, ToolbarMenuVisitor > + , WholeMenu { // Construction from an internal name and a previously built-up // vector of pointers MenuItem( const Identifier &internalName, @@ -842,11 +853,6 @@ namespace MenuTable { Appender fn; }; - // This exists only so that dynamic_cast can find it - struct MenuSection { - virtual ~MenuSection(); - }; - struct MenuPart : ConcreteGroupItem< false, ToolbarMenuVisitor >, MenuSection { template< typename... Args > diff --git a/src/widgets/PopupMenuTable.cpp b/src/widgets/PopupMenuTable.cpp index 9755868b9..b3b7356dc 100644 --- a/src/widgets/PopupMenuTable.cpp +++ b/src/widgets/PopupMenuTable.cpp @@ -20,6 +20,7 @@ PopupSubMenu::~PopupSubMenu() PopupSubMenu::PopupSubMenu( const Identifier &stringId, const TranslatableString &caption_, PopupMenuTable &table ) : ConcreteGroupItem< false >{ stringId } + , WholeMenu{ caption_.empty() } , caption{ caption_ } { } diff --git a/src/widgets/PopupMenuTable.h b/src/widgets/PopupMenuTable.h index e4baa2b30..cd4a5d85c 100644 --- a/src/widgets/PopupMenuTable.h +++ b/src/widgets/PopupMenuTable.h @@ -53,6 +53,7 @@ struct PopupMenuTableEntry : Registry::SingleItem }; struct PopupSubMenu : Registry::ConcreteGroupItem< false > + , MenuTable::WholeMenu { TranslatableString caption; @@ -103,8 +104,7 @@ public: // More items get added to the end of it static void ExtendMenu( wxMenu &menu, PopupMenuTable &otherTable ); - using Entries = std::vector; - const std::shared_ptr< PopupSubMenu > &Get() + const std::shared_ptr< Registry::GroupItem > &Get() { if (!mTop) Populate(); @@ -115,7 +115,7 @@ protected: virtual void Populate() = 0; void Clear() { mTop.reset(); } - std::shared_ptr< PopupSubMenu > mTop; + std::shared_ptr< Registry::GroupItem > mTop; std::vector< Registry::GroupItem* > mStack; Identifier mId; TranslatableString mCaption;