1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-23 17:30:17 +01:00

Delay evaluation of checkmark states...

... so that more menu item descriptions can be statically constructed once only
This commit is contained in:
Paul Licameli
2019-01-09 14:14:40 -05:00
parent 512c27d422
commit 93c2bb9322
11 changed files with 57 additions and 24 deletions

View File

@@ -141,6 +141,9 @@ class AUDACITY_DLL_API CommandManager final
// For specifying unusual arguments in AddItem
struct Options
{
// type of a function that determines checkmark state
using CheckFn = std::function< bool(AudacityProject&) >;
Options() {}
// Allow implicit construction from an accelerator string, which is
// a very common case
@@ -153,8 +156,6 @@ class AUDACITY_DLL_API CommandManager final
Options &&Accel (const wxChar *value) &&
{ accel = value; return std::move(*this); }
Options &&CheckState (bool value) &&
{ check = value ? 1 : 0; return std::move(*this); }
Options &&IsEffect (bool value = true) &&
{ bIsEffect = value; return std::move(*this); }
Options &&Parameter (const CommandParameter &value) &&
@@ -168,14 +169,35 @@ class AUDACITY_DLL_API CommandManager final
Options &&AllowInMacros ( int value = 1 ) &&
{ allowInMacros = value; return std::move(*this); }
// Specify a constant check state
Options &&CheckState (bool value) && {
checker = value
? [](AudacityProject&){ return true; }
: [](AudacityProject&){ return false; }
;
return std::move(*this);
}
// CheckTest is overloaded
// Take arbitrary predicate
Options &&CheckTest (const CheckFn &fn) &&
{ checker = fn; return std::move(*this); }
// Take a preference path
Options &&CheckTest (const wxChar *key, bool defaultValue) && {
checker = MakeCheckFn( key, defaultValue );
return std::move(*this);
}
const wxChar *accel{ wxT("") };
int check{ -1 }; // 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{};
bool global{ false };
bool useStrictFlags{ false };
int allowInMacros{ -1 }; // 0 = never, 1 = always, -1 = deduce from label
private:
static CheckFn MakeCheckFn( const wxString key, bool defaultValue );
};
void AddItemList(const CommandID & name,
@@ -186,7 +208,8 @@ class AUDACITY_DLL_API CommandManager final
CommandFlag flags,
bool bIsEffect = false);
void AddItem(const CommandID & name,
void AddItem(AudacityProject &project,
const CommandID & name,
const TranslatableString &label_in,
CommandHandlerFinder finder,
CommandFunctorPointer callback,