1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 23:59:37 +02:00

Move helper structure definitions out of CommandManager.h...

... and remove an indirection in handling one of them
This commit is contained in:
Paul Licameli 2020-05-03 11:21:01 -04:00
parent 4c3dda596d
commit 3313b33050
3 changed files with 73 additions and 73 deletions

View File

@ -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<wxMenuBar> menubar; // This structure does not assume memory ownership!
};
struct SubMenuListEntry
{
SubMenuListEntry( const TranslatableString &name_ );
SubMenuListEntry( SubMenuListEntry&& ) = default;
~SubMenuListEntry();
TranslatableString name;
std::unique_ptr<wxMenu> 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<wxMenu> 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<wxMenu>() ));
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<CommandListEntry>();
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.

View File

@ -32,69 +32,16 @@
#include <unordered_map>
class wxMenu;
class wxMenuBar;
class wxMenu;
class wxMenuBar;
using CommandParameter = CommandID;
struct MenuBarListEntry
{
MenuBarListEntry(const wxString &name_, wxMenuBar *menubar_);
~MenuBarListEntry();
wxString name;
wxWeakRef<wxMenuBar> menubar; // This structure does not assume memory ownership!
};
struct SubMenuListEntry
{
SubMenuListEntry(const TranslatableString &name_, std::unique_ptr<wxMenu> menu_);
SubMenuListEntry( SubMenuListEntry&& ) = default;
~SubMenuListEntry();
TranslatableString name;
std::unique_ptr<wxMenu> 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<SubMenuListEntry> >;
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 );
};

View File

@ -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 );