Audacity 3.2.0
Public Member Functions | Public Attributes | List of all members
ApplyAndSendResponse Class Reference

ApplyAndSendResponse is a DecoratoredCommand that performs the given command and then outputs a status message according to the result. It manages a CommandContext which is passed into its mCommand, so that result messages are routed back to the right place. More...

#include <Command.h>

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

Public Member Functions

 ApplyAndSendResponse (const OldStyleCommandPointer &cmd, std::unique_ptr< CommandOutputTargets > &target)
 
bool Apply () override
 
bool Apply (const CommandContext &context) override
 
- Public Member Functions inherited from DecoratedCommand
 DecoratedCommand (const OldStyleCommandPointer &cmd)
 
virtual ~DecoratedCommand ()
 
ComponentInterfaceSymbol GetSymbol () override
 
CommandSignatureGetSignature () override
 
bool SetParameter (const wxString &paramName, const wxVariant &paramValue) 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
 

Public Attributes

std::unique_ptr< const CommandContextmCtx
 
- Public Attributes inherited from OldStyleCommand
AudacityProjectmProject
 

Additional Inherited Members

- Protected Attributes inherited from DecoratedCommand
OldStyleCommandPointer mCommand
 

Detailed Description

ApplyAndSendResponse is a DecoratoredCommand that performs the given command and then outputs a status message according to the result. It manages a CommandContext which is passed into its mCommand, so that result messages are routed back to the right place.

Definition at line 65 of file Command.h.

Constructor & Destructor Documentation

◆ ApplyAndSendResponse()

ApplyAndSendResponse::ApplyAndSendResponse ( const OldStyleCommandPointer cmd,
std::unique_ptr< CommandOutputTargets > &  target 
)

Definition at line 122 of file Command.cpp.

124 : DecoratedCommand(cmd),
125 mCtx( std::make_unique<CommandContext>( cmd->mProject, std::move(target) ) )
126{
127}
std::unique_ptr< const CommandContext > mCtx
Definition: Command.h:72
DecoratedCommand(const OldStyleCommandPointer &cmd)
Definition: Command.h:52

Member Function Documentation

◆ Apply() [1/2]

bool ApplyAndSendResponse::Apply ( )
overridevirtual

Implements OldStyleCommand.

Definition at line 137 of file Command.cpp.

138{
139 // ApplyAndSendResponse IS a command.
140 // It also HOLDS a command.
141
142 // Mostly its functions forward to the recipient.
143 // However it uses its OWN context, not the one of
144 // the command it holds.
145 auto result = GuardedCall<bool>(
146 [&] {
147 bool bResult = mCommand->Apply(*( mCtx.get()));
148 return bResult; }
149 );
150 wxString response = wxT( "\n" );
151
152 // PRL: it's all right to send untranslated strings to this channel
153 // I don't see _("") used with literal strings.
154 response += GetSymbol().Internal();
155
156 // These three strings are deliberately not localised.
157 // They are used in script responses and always happen in English.
158 response += wxT(" finished: ");
159 if (result)
160 {
161 response += wxT("OK");
162 }
163 else
164 {
165 response += wxT("Failed!");
166 }
167 mCtx->Status(response, true);
168 return result;
169}
wxT("CloseDown"))
const wxString & Internal() const
OldStyleCommandPointer mCommand
Definition: Command.h:50
ComponentInterfaceSymbol GetSymbol() override
Definition: Command.cpp:106

References DecoratedCommand::GetSymbol(), ComponentInterfaceSymbol::Internal(), DecoratedCommand::mCommand, mCtx, and wxT().

Here is the call graph for this function:

◆ Apply() [2/2]

bool ApplyAndSendResponse::Apply ( const CommandContext context)
overridevirtual

Implements OldStyleCommand.

Member Data Documentation

◆ mCtx

std::unique_ptr<const CommandContext> ApplyAndSendResponse::mCtx

Definition at line 72 of file Command.h.

Referenced by Apply().


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