Audacity  2.2.2
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:
DecoratedCommand OldStyleCommand

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 ()
 
IdentInterfaceSymbol GetSymbol () override
 
CommandSignatureGetSignature () override
 
bool SetParameter (const wxString &paramName, const wxVariant &paramValue) override
 
- Public Member Functions inherited from OldStyleCommand
 OldStyleCommand ()
 
virtual ~OldStyleCommand ()
 

Public Attributes

std::unique_ptr< CommandContextmCtx
 

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 67 of file Command.h.

Constructor & Destructor Documentation

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

Definition at line 125 of file Command.cpp.

126  : DecoratedCommand(cmd),
127  mCtx( std::make_unique<CommandContext>( *GetActiveProject(), std::move(target) ) )
128 {
129 }
DecoratedCommand(const OldStyleCommandPointer &cmd)
Definition: Command.h:54
std::unique_ptr< CommandContext > mCtx
Definition: Command.h:73
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308

Member Function Documentation

bool ApplyAndSendResponse::Apply ( )
overridevirtual

Implements OldStyleCommand.

Definition at line 139 of file Command.cpp.

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

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

Implements OldStyleCommand.

Member Data Documentation

std::unique_ptr<CommandContext> ApplyAndSendResponse::mCtx

Definition at line 73 of file Command.h.

Referenced by Apply().


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