mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-14 09:03:54 +01:00
Move helper structure definitions out of CommandManager.h...
... and remove an indirection in handling one of them
This commit is contained in:
@@ -115,6 +115,59 @@ CommandManager. It holds the callback for one command.
|
|||||||
#define COMMAND XO("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()
|
NonKeystrokeInterceptingWindow::~NonKeystrokeInterceptingWindow()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -132,9 +185,8 @@ MenuBarListEntry::~MenuBarListEntry()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SubMenuListEntry::SubMenuListEntry(
|
SubMenuListEntry::SubMenuListEntry( const TranslatableString &name_ )
|
||||||
const TranslatableString &name_, std::unique_ptr<wxMenu> menu_ )
|
: name(name_), menu( std::make_unique< wxMenu >() )
|
||||||
: name(name_), menu( std::move(menu_) )
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,10 +472,9 @@ void CommandManager::EndMainMenu()
|
|||||||
/// the function's argument.
|
/// the function's argument.
|
||||||
wxMenu* CommandManager::BeginSubMenu(const TranslatableString & tName)
|
wxMenu* CommandManager::BeginSubMenu(const TranslatableString & tName)
|
||||||
{
|
{
|
||||||
mSubMenuList.push_back
|
mSubMenuList.emplace_back( tName );
|
||||||
(std::make_unique< SubMenuListEntry > ( tName, std::make_unique<wxMenu>() ));
|
|
||||||
mbSeparatorAllowed = false;
|
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()
|
void CommandManager::EndSubMenu()
|
||||||
{
|
{
|
||||||
//Save the submenu's information
|
//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
|
//Pop off the NEW submenu so CurrentMenu returns the parent of the submenu
|
||||||
mSubMenuList.pop_back();
|
mSubMenuList.pop_back();
|
||||||
@@ -455,7 +506,7 @@ wxMenu * CommandManager::CurrentSubMenu() const
|
|||||||
if(mSubMenuList.empty())
|
if(mSubMenuList.empty())
|
||||||
return NULL;
|
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(
|
auto CommandManager::Options::MakeCheckFn(
|
||||||
const wxString key, bool defaultValue ) -> CommandListEntry::CheckFn
|
const wxString key, bool defaultValue ) -> CheckFn
|
||||||
{
|
{
|
||||||
return [=](AudacityProject&){ return gPrefs->ReadBool( key, defaultValue ); };
|
return [=](AudacityProject&){ return gPrefs->ReadBool( key, defaultValue ); };
|
||||||
}
|
}
|
||||||
@@ -642,9 +693,8 @@ CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn,
|
|||||||
auto entry = std::make_unique<CommandListEntry>();
|
auto entry = std::make_unique<CommandListEntry>();
|
||||||
|
|
||||||
TranslatableString labelPrefix;
|
TranslatableString labelPrefix;
|
||||||
if (!mSubMenuList.empty()) {
|
if (!mSubMenuList.empty())
|
||||||
labelPrefix = mSubMenuList.back()->name.Stripped();
|
labelPrefix = mSubMenuList.back().name.Stripped();
|
||||||
}
|
|
||||||
|
|
||||||
// For key bindings for commands with a list, such as align,
|
// For key bindings for commands with a list, such as align,
|
||||||
// the name in prefs is the category name plus the effect name.
|
// the name in prefs is the category name plus the effect name.
|
||||||
|
|||||||
@@ -32,69 +32,16 @@
|
|||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
class wxMenu;
|
|
||||||
class wxMenuBar;
|
|
||||||
class wxMenu;
|
class wxMenu;
|
||||||
class wxMenuBar;
|
class wxMenuBar;
|
||||||
using CommandParameter = CommandID;
|
using CommandParameter = CommandID;
|
||||||
|
|
||||||
struct MenuBarListEntry
|
struct MenuBarListEntry;
|
||||||
{
|
struct SubMenuListEntry;
|
||||||
MenuBarListEntry(const wxString &name_, wxMenuBar *menubar_);
|
struct CommandListEntry;
|
||||||
~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 };
|
|
||||||
};
|
|
||||||
|
|
||||||
using MenuBarList = std::vector < MenuBarListEntry >;
|
using MenuBarList = std::vector < MenuBarListEntry >;
|
||||||
|
using SubMenuList = std::vector < SubMenuListEntry >;
|
||||||
// to do: remove the extra indirection when Mac compiler moves to newer version
|
|
||||||
using SubMenuList = std::vector < std::unique_ptr<SubMenuListEntry> >;
|
|
||||||
|
|
||||||
// This is an array of pointers, not structures, because the hash maps also point to them,
|
// 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.
|
// 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);
|
wxMenu *BeginMenu(const TranslatableString & tName);
|
||||||
void EndMenu();
|
void EndMenu();
|
||||||
|
|
||||||
|
// type of a function that determines checkmark state
|
||||||
|
using CheckFn = std::function< bool(AudacityProject&) >;
|
||||||
|
|
||||||
// For specifying unusual arguments in AddItem
|
// For specifying unusual arguments in AddItem
|
||||||
struct Options
|
struct Options
|
||||||
{
|
{
|
||||||
@@ -183,7 +133,7 @@ class AUDACITY_DLL_API CommandManager final
|
|||||||
|
|
||||||
// CheckTest is overloaded
|
// CheckTest is overloaded
|
||||||
// Take arbitrary predicate
|
// Take arbitrary predicate
|
||||||
Options &&CheckTest (const CommandListEntry::CheckFn &fn) &&
|
Options &&CheckTest (const CheckFn &fn) &&
|
||||||
{ checker = fn; return std::move(*this); }
|
{ checker = fn; return std::move(*this); }
|
||||||
// Take a preference path
|
// Take a preference path
|
||||||
Options &&CheckTest (const wxChar *key, bool defaultValue) && {
|
Options &&CheckTest (const wxChar *key, bool defaultValue) && {
|
||||||
@@ -192,7 +142,7 @@ class AUDACITY_DLL_API CommandManager final
|
|||||||
}
|
}
|
||||||
|
|
||||||
const wxChar *accel{ wxT("") };
|
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 };
|
bool bIsEffect{ false };
|
||||||
CommandParameter parameter{};
|
CommandParameter parameter{};
|
||||||
TranslatableString longName{};
|
TranslatableString longName{};
|
||||||
@@ -204,7 +154,7 @@ class AUDACITY_DLL_API CommandManager final
|
|||||||
int allowInMacros{ -1 }; // 0 = never, 1 = always, -1 = deduce from label
|
int allowInMacros{ -1 }; // 0 = never, 1 = always, -1 = deduce from label
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static CommandListEntry::CheckFn
|
static CheckFn
|
||||||
MakeCheckFn( const wxString key, bool defaultValue );
|
MakeCheckFn( const wxString key, bool defaultValue );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ static CommandHandlerObject &findCommandHandler(AudacityProject &) {
|
|||||||
namespace{
|
namespace{
|
||||||
using namespace MenuTable;
|
using namespace MenuTable;
|
||||||
|
|
||||||
auto ToolbarCheckFn( int toolbarId ) -> CommandListEntry::CheckFn
|
auto ToolbarCheckFn( int toolbarId ) -> CommandManager::CheckFn
|
||||||
{
|
{
|
||||||
return [toolbarId](AudacityProject &project){
|
return [toolbarId](AudacityProject &project){
|
||||||
auto &toolManager = ToolManager::Get( project );
|
auto &toolManager = ToolManager::Get( project );
|
||||||
|
|||||||
Reference in New Issue
Block a user