From 3313b3305086438dfa8a627dd5a710259cbe4857 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sun, 3 May 2020 11:21:01 -0400 Subject: [PATCH] Move helper structure definitions out of CommandManager.h... ... and remove an indirection in handling one of them --- src/commands/CommandManager.cpp | 74 +++++++++++++++++++++++++++------ src/commands/CommandManager.h | 70 +++++-------------------------- src/menus/ToolbarMenus.cpp | 2 +- 3 files changed, 73 insertions(+), 73 deletions(-) diff --git a/src/commands/CommandManager.cpp b/src/commands/CommandManager.cpp index a2c5fdee4..565b94c73 100644 --- a/src/commands/CommandManager.cpp +++ b/src/commands/CommandManager.cpp @@ -115,6 +115,59 @@ CommandManager. It holds the callback for one command. #define COMMAND XO("Command") +struct MenuBarListEntry +{ + MenuBarListEntry(const wxString &name_, wxMenuBar *menubar_); + ~MenuBarListEntry(); + + wxString name; + wxWeakRef menubar; // This structure does not assume memory ownership! +}; + +struct SubMenuListEntry +{ + SubMenuListEntry( const TranslatableString &name_ ); + SubMenuListEntry( SubMenuListEntry&& ) = default; + ~SubMenuListEntry(); + + TranslatableString name; + std::unique_ptr menu; +}; + +struct CommandListEntry +{ + int id; + CommandID name; + TranslatableString longLabel; + NormalizedKeyString key; + NormalizedKeyString defaultKey; + TranslatableString label; + TranslatableString labelPrefix; + TranslatableString labelTop; + wxMenu *menu; + CommandHandlerFinder finder; + CommandFunctorPointer callback; + CommandParameter parameter; + + // type of a function that determines checkmark state + using CheckFn = std::function< bool(AudacityProject&) >; + CheckFn checkmarkFn; + + bool multi; + int index; + int count; + bool enabled; + bool skipKeydown; + bool wantKeyup; + bool allowDup; + bool isGlobal; + bool isOccult; + bool isEffect; + bool excludeFromMacros; + CommandFlag flags; + bool useStrictFlags{ false }; +}; + NonKeystrokeInterceptingWindow::~NonKeystrokeInterceptingWindow() { } @@ -132,9 +185,8 @@ MenuBarListEntry::~MenuBarListEntry() { } -SubMenuListEntry::SubMenuListEntry( - const TranslatableString &name_, std::unique_ptr menu_ ) - : name(name_), menu( std::move(menu_) ) +SubMenuListEntry::SubMenuListEntry( const TranslatableString &name_ ) + : name(name_), menu( std::make_unique< wxMenu >() ) { } @@ -420,10 +472,9 @@ void CommandManager::EndMainMenu() /// the function's argument. wxMenu* CommandManager::BeginSubMenu(const TranslatableString & tName) { - mSubMenuList.push_back - (std::make_unique< SubMenuListEntry > ( tName, std::make_unique() )); + mSubMenuList.emplace_back( tName ); mbSeparatorAllowed = false; - return mSubMenuList.back()->menu.get(); + return mSubMenuList.back().menu.get(); } @@ -434,7 +485,7 @@ wxMenu* CommandManager::BeginSubMenu(const TranslatableString & tName) void CommandManager::EndSubMenu() { //Save the submenu's information - SubMenuListEntry tmpSubMenu { std::move( *mSubMenuList.back() ) }; + SubMenuListEntry tmpSubMenu{ std::move( mSubMenuList.back() ) }; //Pop off the NEW submenu so CurrentMenu returns the parent of the submenu mSubMenuList.pop_back(); @@ -455,7 +506,7 @@ wxMenu * CommandManager::CurrentSubMenu() const if(mSubMenuList.empty()) return NULL; - return mSubMenuList.back()->menu.get(); + return mSubMenuList.back().menu.get(); } /// @@ -531,7 +582,7 @@ void CommandManager::AddItem(AudacityProject &project, } auto CommandManager::Options::MakeCheckFn( - const wxString key, bool defaultValue ) -> CommandListEntry::CheckFn + const wxString key, bool defaultValue ) -> CheckFn { return [=](AudacityProject&){ return gPrefs->ReadBool( key, defaultValue ); }; } @@ -642,9 +693,8 @@ CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn, auto entry = std::make_unique(); TranslatableString labelPrefix; - if (!mSubMenuList.empty()) { - labelPrefix = mSubMenuList.back()->name.Stripped(); - } + if (!mSubMenuList.empty()) + labelPrefix = mSubMenuList.back().name.Stripped(); // For key bindings for commands with a list, such as align, // the name in prefs is the category name plus the effect name. diff --git a/src/commands/CommandManager.h b/src/commands/CommandManager.h index f8b0eb07a..648085c5e 100644 --- a/src/commands/CommandManager.h +++ b/src/commands/CommandManager.h @@ -32,69 +32,16 @@ #include -class wxMenu; -class wxMenuBar; class wxMenu; class wxMenuBar; using CommandParameter = CommandID; -struct MenuBarListEntry -{ - MenuBarListEntry(const wxString &name_, wxMenuBar *menubar_); - ~MenuBarListEntry(); - - wxString name; - wxWeakRef menubar; // This structure does not assume memory ownership! -}; - -struct SubMenuListEntry -{ - SubMenuListEntry(const TranslatableString &name_, std::unique_ptr menu_); - SubMenuListEntry( SubMenuListEntry&& ) = default; - ~SubMenuListEntry(); - - TranslatableString name; - std::unique_ptr menu; -}; - -struct CommandListEntry -{ - int id; - CommandID name; - TranslatableString longLabel; - NormalizedKeyString key; - NormalizedKeyString defaultKey; - TranslatableString label; - TranslatableString labelPrefix; - TranslatableString labelTop; - wxMenu *menu; - CommandHandlerFinder finder; - CommandFunctorPointer callback; - CommandParameter parameter; - - // type of a function that determines checkmark state - using CheckFn = std::function< bool(AudacityProject&) >; - CheckFn checkmarkFn; - - bool multi; - int index; - int count; - bool enabled; - bool skipKeydown; - bool wantKeyup; - bool allowDup; - bool isGlobal; - bool isOccult; - bool isEffect; - bool excludeFromMacros; - CommandFlag flags; - bool useStrictFlags{ false }; -}; +struct MenuBarListEntry; +struct SubMenuListEntry; +struct CommandListEntry; using MenuBarList = std::vector < MenuBarListEntry >; - -// to do: remove the extra indirection when Mac compiler moves to newer version -using SubMenuList = std::vector < std::unique_ptr >; +using SubMenuList = std::vector < SubMenuListEntry >; // This is an array of pointers, not structures, because the hash maps also point to them, // so we don't want the structures to relocate with vector operations. @@ -144,6 +91,9 @@ class AUDACITY_DLL_API CommandManager final wxMenu *BeginMenu(const TranslatableString & tName); void EndMenu(); + // type of a function that determines checkmark state + using CheckFn = std::function< bool(AudacityProject&) >; + // For specifying unusual arguments in AddItem struct Options { @@ -183,7 +133,7 @@ class AUDACITY_DLL_API CommandManager final // CheckTest is overloaded // Take arbitrary predicate - Options &&CheckTest (const CommandListEntry::CheckFn &fn) && + Options &&CheckTest (const CheckFn &fn) && { checker = fn; return std::move(*this); } // Take a preference path Options &&CheckTest (const wxChar *key, bool defaultValue) && { @@ -192,7 +142,7 @@ class AUDACITY_DLL_API CommandManager final } const wxChar *accel{ wxT("") }; - CommandListEntry::CheckFn checker; // default value means it's not a check item + CheckFn checker; // default value means it's not a check item bool bIsEffect{ false }; CommandParameter parameter{}; TranslatableString longName{}; @@ -204,7 +154,7 @@ class AUDACITY_DLL_API CommandManager final int allowInMacros{ -1 }; // 0 = never, 1 = always, -1 = deduce from label private: - static CommandListEntry::CheckFn + static CheckFn MakeCheckFn( const wxString key, bool defaultValue ); }; diff --git a/src/menus/ToolbarMenus.cpp b/src/menus/ToolbarMenus.cpp index 6b7d52a2e..07131aa52 100644 --- a/src/menus/ToolbarMenus.cpp +++ b/src/menus/ToolbarMenus.cpp @@ -43,7 +43,7 @@ static CommandHandlerObject &findCommandHandler(AudacityProject &) { namespace{ using namespace MenuTable; -auto ToolbarCheckFn( int toolbarId ) -> CommandListEntry::CheckFn +auto ToolbarCheckFn( int toolbarId ) -> CommandManager::CheckFn { return [toolbarId](AudacityProject &project){ auto &toolManager = ToolManager::Get( project );