diff --git a/src/commands/CommandFunctors.h b/src/commands/CommandFunctors.h index 2d12c418e..4fdfcf550 100644 --- a/src/commands/CommandFunctors.h +++ b/src/commands/CommandFunctors.h @@ -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 ¶m = {} ) : project{ p } , pEvt{ e } , index{ ii } + , parameter{ param } {} AudacityProject &project; const wxEvent *pEvt; int index; + CommandParameter parameter; }; class wxEvent; diff --git a/src/commands/CommandManager.cpp b/src/commands/CommandManager.cpp index b41dd11fd..caa88b7ab 100644 --- a/src/commands/CommandManager.cpp +++ b/src/commands/CommandManager.cpp @@ -794,9 +794,10 @@ void CommandManager::AddItem(const wxChar *name, const wxChar *accel, CommandFlag flags, CommandMask mask, - int checkmark) + int checkmark, + const CommandParameter ¶meter) { - 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 ¶meter) { // 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; diff --git a/src/commands/CommandManager.h b/src/commands/CommandManager.h index 0b3fad11d..44f927154 100644 --- a/src/commands/CommandManager.h +++ b/src/commands/CommandManager.h @@ -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 ¶meter = {}); void AddSeparator(); @@ -293,7 +295,8 @@ protected: const CommandFunctorPointer &callback, bool multi, int index, - int count); + int count, + const CommandParameter ¶meter); // // Executing commands