1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-01 00:19:27 +02:00

CommandEntry stores a string parameter, passed in CommandContext

This commit is contained in:
Paul Licameli 2017-08-19 06:40:27 -04:00
parent 0a711d8b26
commit 05984e8bfb
3 changed files with 20 additions and 9 deletions

View File

@ -16,20 +16,25 @@
class AudacityProject;
class wxEvent;
using CommandParameter = wxString;
struct CommandContext {
CommandContext(
AudacityProject &p
, const wxEvent *e = nullptr
, int ii = 0
, const CommandParameter &param = {}
)
: project{ p }
, pEvt{ e }
, index{ ii }
, parameter{ param }
{}
AudacityProject &project;
const wxEvent *pEvt;
int index;
CommandParameter parameter;
};
class wxEvent;

View File

@ -794,9 +794,10 @@ void CommandManager::AddItem(const wxChar *name,
const wxChar *accel,
CommandFlag flags,
CommandMask mask,
int checkmark)
int checkmark,
const CommandParameter &parameter)
{
CommandListEntry *entry = NewIdentifier(name, label_in, accel, CurrentMenu(), callback, false, 0, 0);
CommandListEntry *entry = NewIdentifier(name, label_in, accel, CurrentMenu(), callback, false, 0, 0, parameter);
int ID = entry->id;
wxString label = GetLabelWithDisabledAccel(entry);
@ -858,7 +859,7 @@ void CommandManager::AddCommand(const wxChar *name,
CommandFlag flags,
CommandMask mask)
{
NewIdentifier(name, label_in, accel, NULL, callback, false, 0, 0);
NewIdentifier(name, label_in, accel, NULL, callback, false, 0, 0, {});
if (flags != NoFlagsSpecifed || mask != NoFlagsSpecifed) {
SetCommandFlags(name, flags, mask);
@ -870,7 +871,7 @@ void CommandManager::AddGlobalCommand(const wxChar *name,
const CommandFunctorPointer &callback,
const wxChar *accel)
{
CommandListEntry *entry = NewIdentifier(name, label_in, accel, NULL, callback, false, 0, 0);
CommandListEntry *entry = NewIdentifier(name, label_in, accel, NULL, callback, false, 0, 0, {});
entry->enabled = false;
entry->isGlobal = true;
@ -916,7 +917,7 @@ CommandListEntry *CommandManager::NewIdentifier(const wxString & name,
callback,
multi,
index,
count);
count, {});
}
CommandListEntry *CommandManager::NewIdentifier(const wxString & name,
@ -926,7 +927,8 @@ CommandListEntry *CommandManager::NewIdentifier(const wxString & name,
const CommandFunctorPointer &callback,
bool multi,
int index,
int count)
int count,
const CommandParameter &parameter)
{
// If we have the identifier already, reuse it.
CommandListEntry *prev = mCommandNameHash[name];
@ -956,6 +958,7 @@ CommandListEntry *CommandManager::NewIdentifier(const wxString & name,
mCurrentID = NextIdentifier(mCurrentID);
entry->id = mCurrentID;
entry->parameter = parameter;
#if defined(__WXMAC__)
if (name == wxT("Preferences"))
@ -1469,7 +1472,7 @@ bool CommandManager::HandleCommandEntry(const CommandListEntry * entry,
return true;
}
CommandContext context{ *proj, evt, entry->index };
CommandContext context{ *proj, evt, entry->index, entry->parameter };
(*(entry->callback))(context);
return true;

View File

@ -65,6 +65,7 @@ struct CommandListEntry
wxString labelTop;
wxMenu *menu;
CommandFunctorPointer callback;
CommandParameter parameter;
bool multi;
int index;
int count;
@ -156,7 +157,8 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
const wxChar *accel,
CommandFlag flags = NoFlagsSpecifed,
CommandMask mask = NoFlagsSpecifed,
int checkmark = -1);
int checkmark = -1,
const CommandParameter &parameter = {});
void AddSeparator();
@ -293,7 +295,8 @@ protected:
const CommandFunctorPointer &callback,
bool multi,
int index,
int count);
int count,
const CommandParameter &parameter);
//
// Executing commands