1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-20 17:41:13 +02:00

CommandManager::NewIdentifier bundles some arguments in Options

This commit is contained in:
Paul Licameli
2019-01-07 13:08:32 -05:00
parent 6f28f228a1
commit e4968761ad
2 changed files with 30 additions and 28 deletions

View File

@@ -514,25 +514,19 @@ void CommandManager::AddItem(const CommandID &name,
if (options.global) { if (options.global) {
wxASSERT( flags == AlwaysEnabledFlag ); wxASSERT( flags == AlwaysEnabledFlag );
AddGlobalCommand( AddGlobalCommand(
name, label_in, hasDialog, finder, callback, options.accel ); name, label_in, hasDialog, finder, callback, options );
return; return;
} }
wxASSERT( flags != NoFlagsSpecified ); wxASSERT( flags != NoFlagsSpecified );
CommandParameter cookedParameter;
const auto &parameter = options.parameter;
if( parameter.empty() )
cookedParameter = name;
else
cookedParameter = parameter;
CommandListEntry *entry = CommandListEntry *entry =
NewIdentifier(name, NewIdentifier(name,
label_in, label_in,
options.longName,
hasDialog, hasDialog,
options.accel, CurrentMenu(), finder, callback, CurrentMenu(), finder, callback,
{}, 0, 0, options.bIsEffect, cookedParameter); {}, 0, 0,
options);
entry->useStrictFlags = options.useStrictFlags; entry->useStrictFlags = options.useStrictFlags;
int ID = entry->id; int ID = entry->id;
wxString label = GetLabelWithDisabledAccel(entry); wxString label = GetLabelWithDisabledAccel(entry);
@@ -572,19 +566,18 @@ void CommandManager::AddItemList(const CommandID & name,
auto accel = translated.AfterFirst(wxT('\t')); auto accel = translated.AfterFirst(wxT('\t'));
CommandListEntry *entry = CommandListEntry *entry =
NewIdentifier(name, NewIdentifier(name,
stripped,
stripped, stripped,
// No means yet to specify hasDialog ! // No means yet to specify hasDialog !
false, false,
accel,
CurrentMenu(), CurrentMenu(),
finder, finder,
callback, callback,
items[i].Internal(), items[i].Internal(),
i, i,
cnt, cnt,
bIsEffect, Options{}
{}); .Accel(accel)
.IsEffect(bIsEffect));
entry->flags = flags; entry->flags = flags;
CurrentMenu()->Append(entry->id, GetLabel(entry)); CurrentMenu()->Append(entry->id, GetLabel(entry));
mbSeparatorAllowed = true; mbSeparatorAllowed = true;
@@ -596,11 +589,11 @@ void CommandManager::AddGlobalCommand(const CommandID &name,
bool hasDialog, bool hasDialog,
CommandHandlerFinder finder, CommandHandlerFinder finder,
CommandFunctorPointer callback, CommandFunctorPointer callback,
const wxChar *accel) const Options &options)
{ {
CommandListEntry *entry = CommandListEntry *entry =
NewIdentifier(name, label_in, label_in, hasDialog, accel, NULL, finder, callback, NewIdentifier(name, label_in, hasDialog, NULL, finder, callback,
{}, 0, 0, false, {}); {}, 0, 0, options);
entry->enabled = false; entry->enabled = false;
entry->isGlobal = true; entry->isGlobal = true;
@@ -632,18 +625,27 @@ int CommandManager::NextIdentifier(int ID)
///and keep menus above wxID_HIGHEST ///and keep menus above wxID_HIGHEST
CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn, CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn,
const wxString & label, const wxString & label,
const wxString & longLabel,
bool hasDialog, bool hasDialog,
const wxString & accel,
wxMenu *menu, wxMenu *menu,
CommandHandlerFinder finder, CommandHandlerFinder finder,
CommandFunctorPointer callback, CommandFunctorPointer callback,
const CommandID &nameSuffix, const CommandID &nameSuffix,
int index, int index,
int count, int count,
bool bIsEffect, const Options &options)
const CommandParameter &parameter)
{ {
// if empty, new identifier's long label will be same as label, below:
const auto &longLabel = options.longName;
const wxString & accel = options.accel;
bool bIsEffect = options.bIsEffect;
CommandID cookedParameter;
const auto &parameter = options.parameter;
if( parameter == "" )
cookedParameter = nameIn;
else
cookedParameter = parameter;
const bool multi = !nameSuffix.empty(); const bool multi = !nameSuffix.empty();
auto name = nameIn; auto name = nameIn;
@@ -693,7 +695,10 @@ CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn,
entry->name = name; entry->name = name;
entry->label = label; entry->label = label;
// long label is the same as label unless options specified otherwise:
entry->longLabel = longLabel.empty() ? label : longLabel; entry->longLabel = longLabel.empty() ? label : longLabel;
entry->hasDialog = hasDialog; entry->hasDialog = hasDialog;
entry->key = NormalizedKeyString{ accel.BeforeFirst(wxT('\t')) }; entry->key = NormalizedKeyString{ accel.BeforeFirst(wxT('\t')) };
entry->defaultKey = entry->key; entry->defaultKey = entry->key;

View File

@@ -154,8 +154,8 @@ class AUDACITY_DLL_API CommandManager final
{ accel = value; return std::move(*this); } { accel = value; return std::move(*this); }
Options &&CheckState (bool value) && Options &&CheckState (bool value) &&
{ check = value ? 1 : 0; return std::move(*this); } { check = value ? 1 : 0; return std::move(*this); }
Options &&IsEffect () && Options &&IsEffect (bool value = true) &&
{ bIsEffect = true; return std::move(*this); } { bIsEffect = value; return std::move(*this); }
Options &&Parameter (const CommandParameter &value) && Options &&Parameter (const CommandParameter &value) &&
{ parameter = value; return std::move(*this); } { parameter = value; return std::move(*this); }
Options &&LongName (const wxString &value) && Options &&LongName (const wxString &value) &&
@@ -302,24 +302,21 @@ private:
int NextIdentifier(int ID); int NextIdentifier(int ID);
CommandListEntry *NewIdentifier(const CommandID & name, CommandListEntry *NewIdentifier(const CommandID & name,
const wxString & label, const wxString & label,
const wxString & longLabel,
bool hasDialog, bool hasDialog,
const wxString & accel,
wxMenu *menu, wxMenu *menu,
CommandHandlerFinder finder, CommandHandlerFinder finder,
CommandFunctorPointer callback, CommandFunctorPointer callback,
const CommandID &nameSuffix, const CommandID &nameSuffix,
int index, int index,
int count, int count,
bool bIsEffect, const Options &options);
const CommandParameter &parameter);
void AddGlobalCommand(const CommandID &name, void AddGlobalCommand(const CommandID &name,
const wxChar *label, const wxChar *label,
bool hasDialog, bool hasDialog,
CommandHandlerFinder finder, CommandHandlerFinder finder,
CommandFunctorPointer callback, CommandFunctorPointer callback,
const wxChar *accel); const Options &options = {});
// //
// Executing commands // Executing commands