Audacity 3.2.0
Public Member Functions | List of all members
BatchEvalCommand Class Referencefinal

Given a string representing a command, pass it to the MacroCommands system. More...

#include <BatchEvalCommand.h>

Inheritance diagram for BatchEvalCommand:
[legend]
Collaboration diagram for BatchEvalCommand:
[legend]

Public Member Functions

 BatchEvalCommand (AudacityProject &project, OldStyleCommandType &type)
 
virtual ~BatchEvalCommand ()
 
bool Apply (const CommandContext &context) override
 
- Public Member Functions inherited from CommandImplementation
 CommandImplementation (AudacityProject &project, OldStyleCommandType &type)
 
virtual ~CommandImplementation ()
 
ComponentInterfaceSymbol GetSymbol () override
 An instance method for getting the command name (for consistency) More...
 
CommandSignatureGetSignature () override
 Get the signature of the command. More...
 
bool SetParameter (const wxString &paramName, const wxVariant &paramValue) override
 
bool Apply () override
 
bool Apply (const CommandContext &context) override
 
- Public Member Functions inherited from OldStyleCommand
 OldStyleCommand (AudacityProject &project)
 
virtual ~OldStyleCommand ()
 
virtual ComponentInterfaceSymbol GetSymbol ()=0
 
virtual CommandSignatureGetSignature ()=0
 
virtual bool SetParameter (const wxString &paramName, const wxVariant &paramValue)
 
virtual bool Apply ()=0
 
virtual bool Apply (const CommandContext &context)=0
 

Additional Inherited Members

- Public Attributes inherited from OldStyleCommand
AudacityProjectmProject
 
- Protected Member Functions inherited from CommandImplementation
void TypeCheck (const wxString &typeName, const wxString &paramName, const wxVariant &param)
 
void CheckParam (const wxString &paramName)
 
bool HasParam (const wxString &paramName)
 
bool GetBool (const wxString &paramName)
 
long GetLong (const wxString &paramName)
 
double GetDouble (const wxString &paramName)
 
wxString GetString (const wxString &paramName)
 

Detailed Description

Given a string representing a command, pass it to the MacroCommands system.

Command to make processing of macros available to scripting. It can either make a one command macro, or invoke an existing macro. It will become redundant when menu commands are integrated into scripting.

The eventual aim is to move the code from MacroCommands out into separate command classes, but until this happens, BatchEvalCommand can act as a 'bridge' to that system.

Definition at line 40 of file BatchEvalCommand.h.

Constructor & Destructor Documentation

◆ BatchEvalCommand()

BatchEvalCommand::BatchEvalCommand ( AudacityProject project,
OldStyleCommandType type 
)
inline

Definition at line 43 of file BatchEvalCommand.h.

45 { }
const auto project
CommandImplementation(AudacityProject &project, OldStyleCommandType &type)
Definition: Command.cpp:171

◆ ~BatchEvalCommand()

BatchEvalCommand::~BatchEvalCommand ( )
virtual

Definition at line 83 of file BatchEvalCommand.cpp.

84{ }

Member Function Documentation

◆ Apply()

bool BatchEvalCommand::Apply ( const CommandContext context)
overridevirtual

Implements OldStyleCommand.

Definition at line 48 of file BatchEvalCommand.cpp.

49{
50 // Uh oh, I need to build a catalog, expensively
51 // Maybe it can be built in one long-lived place and shared among command
52 // objects instead?
53 // The catalog though may change during a session, as it includes the
54 // names of macro commands - so the long-lived copy will need to
55 // be refreshed after macros are added/deleted.
56 MacroCommandsCatalog catalog(&context.project);
57
58 wxString macroName = GetString(wxT("MacroName"));
59 if (!macroName.empty())
60 {
61 MacroCommands batch{ context.project };
62 batch.ReadMacro(macroName);
63 return batch.ApplyMacro(catalog);
64 }
65
66 auto cmdName = GetString(wxT("CommandName"));
67 wxString cmdParams = GetString(wxT("ParamString"));
68 auto iter = catalog.ByCommandId(cmdName);
69 const auto friendly = (iter == catalog.end())
70 ? Verbatim( cmdName ) // Expose internal name to user, in default of a better one!
71 : iter->name.Msgid().Stripped();
72
73 // Create a Batch that will have just one command in it...
74 MacroCommands Batch{ context.project };
75 bool bResult = Batch.ApplyCommandInBatchMode(friendly, cmdName, cmdParams, &context);
76 // Relay messages, if any.
77 wxString Message = Batch.GetMessage();
78 if( !Message.empty() )
79 context.Status( Message );
80 return bResult;
81}
wxT("CloseDown"))
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
virtual void Status(const wxString &message, bool bFlush=false) const
AudacityProject & project
wxString GetString(const wxString &paramName)
Definition: Command.cpp:240
Maintains the list of commands for batch/macro processing. See also MacrosWindow and ApplyMacroDialog...
Definition: BatchCommands.h:60
TranslatableString Stripped(unsigned options=MenuCodes) const
non-mutating, constructs another TranslatableString object
TranslatableString Message(unsigned trackCount)

References MacroCommandsCatalog::ByCommandId(), TranslatableString::empty(), MacroCommandsCatalog::end(), CommandImplementation::GetString(), anonymous_namespace{TrackSelectHandle.cpp}::Message(), CommandContext::project, CommandContext::Status(), TranslatableString::Stripped(), Verbatim(), and wxT().

Here is the call graph for this function:

The documentation for this class was generated from the following files: