1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-21 16:37:12 +01:00

Separate subclass ToolbarMenuVisitor from MenuVisitor

This commit is contained in:
Paul Licameli
2020-02-04 12:10:17 -05:00
parent a43c9a5337
commit 446ee8ef6e
4 changed files with 33 additions and 25 deletions

View File

@@ -199,7 +199,7 @@ namespace MenuTable {
MenuItem::MenuItem( const Identifier &internalName, MenuItem::MenuItem( const Identifier &internalName,
const TranslatableString &title_, BaseItemPtrs &&items_ ) const TranslatableString &title_, BaseItemPtrs &&items_ )
: ConcreteGroupItem< false, MenuVisitor >{ : ConcreteGroupItem< false, ToolbarMenuVisitor >{
internalName, std::move( items_ ) }, title{ title_ } internalName, std::move( items_ ) }, title{ title_ }
{ {
wxASSERT( !title.empty() ); wxASSERT( !title.empty() );
@@ -208,7 +208,7 @@ MenuItem::~MenuItem() {}
ConditionalGroupItem::ConditionalGroupItem( ConditionalGroupItem::ConditionalGroupItem(
const Identifier &internalName, Condition condition_, BaseItemPtrs &&items_ ) const Identifier &internalName, Condition condition_, BaseItemPtrs &&items_ )
: ConcreteGroupItem< false, MenuVisitor >{ : ConcreteGroupItem< false, ToolbarMenuVisitor >{
internalName, std::move( items_ ) }, condition{ condition_ } internalName, std::move( items_ ) }, condition{ condition_ }
{ {
} }
@@ -240,6 +240,8 @@ CommandGroupItem::~CommandGroupItem() {}
SpecialItem::~SpecialItem() {} SpecialItem::~SpecialItem() {}
MenuSection::~MenuSection() {}
CommandHandlerFinder FinderScope::sFinder = CommandHandlerFinder FinderScope::sFinder =
[](AudacityProject &project) -> CommandHandlerObject & { [](AudacityProject &project) -> CommandHandlerObject & {
// If this default finder function is reached, then FinderScope should // If this default finder function is reached, then FinderScope should
@@ -1058,10 +1060,10 @@ namespace {
using namespace MenuTable; using namespace MenuTable;
struct MenuItemVisitor : MenuVisitor struct MenuItemVisitor : ToolbarMenuVisitor
{ {
MenuItemVisitor( AudacityProject &proj, CommandManager &man ) MenuItemVisitor( AudacityProject &proj, CommandManager &man )
: MenuVisitor(proj), manager( man ) {} : ToolbarMenuVisitor(proj), manager( man ) {}
void DoBeginGroup( GroupItem &item, const Path& ) override void DoBeginGroup( GroupItem &item, const Path& ) override
{ {
@@ -1209,7 +1211,7 @@ void MenuCreator::CreateMenusAndCommands(AudacityProject &project)
#endif #endif
} }
void MenuManager::Visit( MenuVisitor &visitor ) void MenuManager::Visit( ToolbarMenuVisitor &visitor )
{ {
static const auto menuTree = MenuTable::Items( MenuPathStart ); static const auto menuTree = MenuTable::Items( MenuPathStart );
Registry::Visit( visitor, menuTree.get(), &sRegistry() ); Registry::Visit( visitor, menuTree.get(), &sRegistry() );

View File

@@ -54,7 +54,7 @@ public:
PluginID mLastEffect{}; PluginID mLastEffect{};
}; };
struct MenuVisitor; struct ToolbarMenuVisitor;
class MenuManager final class MenuManager final
: public MenuCreator : public MenuCreator
@@ -72,7 +72,7 @@ public:
MenuManager &operator=( const MenuManager & ) PROHIBITED; MenuManager &operator=( const MenuManager & ) PROHIBITED;
~MenuManager(); ~MenuManager();
static void Visit( MenuVisitor &visitor ); static void Visit( ToolbarMenuVisitor &visitor );
static void ModifyUndoMenuItems(AudacityProject &project); static void ModifyUndoMenuItems(AudacityProject &project);
static void ModifyToolbarMenus(AudacityProject &project); static void ModifyToolbarMenus(AudacityProject &project);

View File

@@ -667,9 +667,6 @@ namespace Registry {
struct MenuVisitor : Registry::Visitor struct MenuVisitor : Registry::Visitor
{ {
explicit MenuVisitor( AudacityProject &p ) : project{ p } {}
operator AudacityProject & () const { return project; }
// final overrides // final overrides
void BeginGroup( Registry::GroupItem &item, const Path &path ) final; void BeginGroup( Registry::GroupItem &item, const Path &path ) final;
void EndGroup( Registry::GroupItem &item, const Path& ) final; void EndGroup( Registry::GroupItem &item, const Path& ) final;
@@ -681,20 +678,25 @@ struct MenuVisitor : Registry::Visitor
virtual void DoVisit( Registry::SingleItem &item, const Path &path ); virtual void DoVisit( Registry::SingleItem &item, const Path &path );
virtual void DoSeparator(); virtual void DoSeparator();
AudacityProject &project;
private: private:
void MaybeDoSeparator(); void MaybeDoSeparator();
std::vector<bool> firstItem; std::vector<bool> firstItem;
std::vector<bool> needSeparator; std::vector<bool> needSeparator;
}; };
struct ToolbarMenuVisitor : MenuVisitor
{
explicit ToolbarMenuVisitor( AudacityProject &p ) : project{ p } {}
operator AudacityProject & () const { return project; }
AudacityProject &project;
};
// Define items that populate tables that specifically describe menu trees // Define items that populate tables that specifically describe menu trees
namespace MenuTable { namespace MenuTable {
using namespace Registry; using namespace Registry;
// Describes a main menu in the toolbar, or a sub-menu // Describes a main menu in the toolbar, or a sub-menu
struct MenuItem final : ConcreteGroupItem< false, MenuVisitor > { struct MenuItem final : ConcreteGroupItem< false, ToolbarMenuVisitor > {
// Construction from an internal name and a previously built-up // Construction from an internal name and a previously built-up
// vector of pointers // vector of pointers
MenuItem( const Identifier &internalName, MenuItem( const Identifier &internalName,
@@ -703,7 +705,7 @@ namespace MenuTable {
template< typename... Args > template< typename... Args >
MenuItem( const Identifier &internalName, MenuItem( const Identifier &internalName,
const TranslatableString &title_, Args&&... args ) const TranslatableString &title_, Args&&... args )
: ConcreteGroupItem< false, MenuVisitor >{ : ConcreteGroupItem< false, ToolbarMenuVisitor >{
internalName, std::forward<Args>(args)... } internalName, std::forward<Args>(args)... }
, title{ title_ } , title{ title_ }
{} {}
@@ -714,7 +716,8 @@ namespace MenuTable {
// Collects other items that are conditionally shown or hidden, but are // Collects other items that are conditionally shown or hidden, but are
// always available to macro programming // always available to macro programming
struct ConditionalGroupItem final : ConcreteGroupItem< false, MenuVisitor > { struct ConditionalGroupItem final
: ConcreteGroupItem< false, ToolbarMenuVisitor > {
using Condition = std::function< bool() >; using Condition = std::function< bool() >;
// Construction from an internal name and a previously built-up // Construction from an internal name and a previously built-up
@@ -725,7 +728,7 @@ namespace MenuTable {
template< typename... Args > template< typename... Args >
ConditionalGroupItem( const Identifier &internalName, ConditionalGroupItem( const Identifier &internalName,
Condition condition_, Args&&... args ) Condition condition_, Args&&... args )
: ConcreteGroupItem< false, MenuVisitor >{ : ConcreteGroupItem< false, ToolbarMenuVisitor >{
internalName, std::forward<Args>(args)... } internalName, std::forward<Args>(args)... }
, condition{ condition_ } , condition{ condition_ }
{} {}
@@ -839,18 +842,21 @@ namespace MenuTable {
Appender fn; Appender fn;
}; };
template< bool Transparent > // This exists only so that dynamic_cast can find it
struct MenuPart : ConcreteGroupItem< Transparent, MenuVisitor > struct MenuSection {
virtual ~MenuSection();
};
struct MenuPart : ConcreteGroupItem< false, ToolbarMenuVisitor >, MenuSection
{ {
template< typename... Args > template< typename... Args >
explicit explicit
MenuPart( const Identifier &internalName, Args&&... args ) MenuPart( const Identifier &internalName, Args&&... args )
: ConcreteGroupItem< Transparent, MenuVisitor >{ : ConcreteGroupItem< false, ToolbarMenuVisitor >{
internalName, std::forward< Args >( args )... } internalName, std::forward< Args >( args )... }
{} {}
}; };
using MenuItems = MenuPart< true >; using MenuItems = ConcreteGroupItem< true, ToolbarMenuVisitor >;
using MenuSection = MenuPart< false >;
// The following, and Shared(), are the functions to use directly // The following, and Shared(), are the functions to use directly
// in writing table definitions. // in writing table definitions.
@@ -874,9 +880,9 @@ namespace MenuTable {
// It's not necessary that the sisters of sections be other sections, but it // It's not necessary that the sisters of sections be other sections, but it
// might clarify the logical groupings. // might clarify the logical groupings.
template< typename... Args > template< typename... Args >
inline std::unique_ptr< MenuSection > Section( inline std::unique_ptr< MenuPart > Section(
const Identifier &internalName, Args&&... args ) const Identifier &internalName, Args&&... args )
{ return std::make_unique< MenuSection >( { return std::make_unique< MenuPart >(
internalName, std::forward<Args>(args)... ); } internalName, std::forward<Args>(args)... ); }
// Menu items can be constructed two ways, as for group items // Menu items can be constructed two ways, as for group items

View File

@@ -380,9 +380,9 @@ void OnMenuTree(const CommandContext &context)
auto &project = context.project; auto &project = context.project;
using namespace MenuTable; using namespace MenuTable;
struct MyVisitor : MenuVisitor struct MyVisitor : ToolbarMenuVisitor
{ {
using MenuVisitor::MenuVisitor; using ToolbarMenuVisitor::ToolbarMenuVisitor;
enum : unsigned { TAB = 3 }; enum : unsigned { TAB = 3 };
void DoBeginGroup( GroupItem &item, const Path& ) override void DoBeginGroup( GroupItem &item, const Path& ) override