mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-01 16:19:43 +02:00
Command.cpp does not depend on Project.cpp...
... To do that, hoist the call to GetActiveProject() into the factory that makes BatchEvalCommand Also remove unnecessary inclusion of CommandBuilder.h. This frees Command.cpp from dependency cycles; CommandBuilder and ScriptCommandRelay are now in a small cycle of only two.
This commit is contained in:
parent
ae0cd061c6
commit
74c53efadc
@ -18,6 +18,7 @@
|
||||
|
||||
#include "CommandContext.h"
|
||||
#include "CommandDirectory.h"
|
||||
#include "../Project.h"
|
||||
|
||||
static CommandDirectory::RegisterType sRegisterType{
|
||||
std::make_unique<BatchEvalCommandType>()
|
||||
@ -40,7 +41,7 @@ void BatchEvalCommandType::BuildSignature(CommandSignature &signature)
|
||||
|
||||
OldStyleCommandPointer BatchEvalCommandType::Create(std::unique_ptr<CommandOutputTargets> && WXUNUSED(target))
|
||||
{
|
||||
return std::make_shared<BatchEvalCommand>(*this);
|
||||
return std::make_shared<BatchEvalCommand>(*GetActiveProject(), *this);
|
||||
}
|
||||
|
||||
bool BatchEvalCommand::Apply(const CommandContext & context)
|
||||
|
@ -26,6 +26,8 @@ to that system.
|
||||
#include "CommandType.h"
|
||||
#include "../BatchCommands.h"
|
||||
|
||||
class AudacityProject;
|
||||
|
||||
class BatchEvalCommandType final : public OldStyleCommandType
|
||||
{
|
||||
public:
|
||||
@ -37,8 +39,8 @@ public:
|
||||
class BatchEvalCommand final : public CommandImplementation
|
||||
{
|
||||
public:
|
||||
BatchEvalCommand(OldStyleCommandType &type)
|
||||
: CommandImplementation(type)
|
||||
BatchEvalCommand(AudacityProject &project, OldStyleCommandType &type)
|
||||
: CommandImplementation(project, type)
|
||||
{ }
|
||||
|
||||
virtual ~BatchEvalCommand();
|
||||
|
@ -79,16 +79,17 @@ classes derived from it.
|
||||
#include "Command.h"
|
||||
|
||||
#include <map>
|
||||
#include <wx/log.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/variant.h>
|
||||
#include <wx/arrstr.h>
|
||||
|
||||
#include "CommandBuilder.h"
|
||||
#include "CommandTargets.h"
|
||||
#include "CommandDirectory.h"
|
||||
|
||||
#include "CommandContext.h"
|
||||
#include "../Project.h"
|
||||
|
||||
#include "../AudacityException.h"
|
||||
|
||||
|
||||
|
||||
@ -119,9 +120,10 @@ bool DecoratedCommand::SetParameter(const wxString ¶mName,
|
||||
return mCommand->SetParameter(paramName, paramValue);
|
||||
}
|
||||
|
||||
ApplyAndSendResponse::ApplyAndSendResponse(const OldStyleCommandPointer &cmd, std::unique_ptr<CommandOutputTargets> &target)
|
||||
ApplyAndSendResponse::ApplyAndSendResponse(
|
||||
const OldStyleCommandPointer &cmd, std::unique_ptr<CommandOutputTargets> &target)
|
||||
: DecoratedCommand(cmd),
|
||||
mCtx( std::make_unique<CommandContext>( *GetActiveProject(), std::move(target) ) )
|
||||
mCtx( std::make_unique<CommandContext>( cmd->mProject, std::move(target) ) )
|
||||
{
|
||||
}
|
||||
|
||||
@ -167,8 +169,10 @@ bool ApplyAndSendResponse::Apply()
|
||||
return result;
|
||||
}
|
||||
|
||||
CommandImplementation::CommandImplementation(OldStyleCommandType &type)
|
||||
: mType(type),
|
||||
CommandImplementation::CommandImplementation(
|
||||
AudacityProject &project, OldStyleCommandType &type)
|
||||
: OldStyleCommand{ project },
|
||||
mType(type),
|
||||
mParams(type.GetSignature().GetDefaults()),
|
||||
mSetParams()
|
||||
{
|
||||
@ -257,7 +261,7 @@ CommandSignature &CommandImplementation::GetSignature()
|
||||
bool CommandImplementation::SetParameter(const wxString ¶mName, const wxVariant ¶mValue)
|
||||
{
|
||||
wxASSERT(!paramValue.IsType(wxT("null")));
|
||||
CommandContext context( * GetActiveProject());
|
||||
CommandContext context( mProject );
|
||||
ParamValueMap::iterator iter = mParams.find(paramName);
|
||||
if (iter == mParams.end())
|
||||
{
|
||||
|
@ -28,7 +28,9 @@ class CommandOutputTargets;
|
||||
class OldStyleCommand /* not final */
|
||||
{
|
||||
public:
|
||||
OldStyleCommand() {};
|
||||
AudacityProject &mProject;
|
||||
|
||||
OldStyleCommand(AudacityProject &project) : mProject{ project } {};
|
||||
virtual ~OldStyleCommand() { }
|
||||
virtual ComponentInterfaceSymbol GetSymbol() = 0;
|
||||
virtual CommandSignature &GetSignature() = 0;
|
||||
@ -47,7 +49,7 @@ protected:
|
||||
OldStyleCommandPointer mCommand;
|
||||
public:
|
||||
DecoratedCommand(const OldStyleCommandPointer &cmd)
|
||||
: mCommand(cmd)
|
||||
: OldStyleCommand{ cmd->mProject }, mCommand(cmd)
|
||||
{
|
||||
wxASSERT(cmd != NULL);
|
||||
}
|
||||
@ -62,7 +64,8 @@ public:
|
||||
class ApplyAndSendResponse : public DecoratedCommand
|
||||
{
|
||||
public:
|
||||
ApplyAndSendResponse(const OldStyleCommandPointer &cmd, std::unique_ptr<CommandOutputTargets> &target);
|
||||
ApplyAndSendResponse(
|
||||
const OldStyleCommandPointer &cmd, std::unique_ptr<CommandOutputTargets> &target);
|
||||
bool Apply() override;
|
||||
bool Apply(const CommandContext &context) override;// Error to use this.
|
||||
std::unique_ptr<const CommandContext> mCtx;
|
||||
@ -95,7 +98,7 @@ protected:
|
||||
public:
|
||||
/// Constructor should not be called directly; only by a factory which
|
||||
/// ensures name and params are set appropriately for the command.
|
||||
CommandImplementation(OldStyleCommandType &type);
|
||||
CommandImplementation(AudacityProject &project, OldStyleCommandType &type);
|
||||
|
||||
virtual ~CommandImplementation();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user