2010-01-23 19:44:49 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity - A Digital Audio Editor
|
|
|
|
Copyright 1999-2009 Audacity Team
|
|
|
|
File License: wxWidgets
|
|
|
|
|
|
|
|
Dan Horgan
|
|
|
|
|
|
|
|
******************************************************************//**
|
|
|
|
|
|
|
|
\file CommandHandler.cpp
|
|
|
|
\brief Contains definitions for the CommandHandler class.
|
|
|
|
|
|
|
|
\class CommandHandler
|
|
|
|
\brief Contains methods for applying commands that are passed to it.
|
|
|
|
|
|
|
|
*//*******************************************************************/
|
|
|
|
|
|
|
|
#include <wx/event.h>
|
|
|
|
#include "CommandHandler.h"
|
|
|
|
#include "../Project.h"
|
|
|
|
#include "Command.h"
|
|
|
|
#include "AppCommandEvent.h"
|
|
|
|
#include "ScriptCommandRelay.h"
|
|
|
|
|
|
|
|
CommandHandler::CommandHandler(AudacityApp &app)
|
|
|
|
: mCurrentContext(new CommandExecutionContext(&app, GetActiveProject()))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
CommandHandler::~CommandHandler()
|
|
|
|
{
|
|
|
|
delete mCurrentContext;
|
|
|
|
}
|
|
|
|
|
2015-06-10 06:04:07 +00:00
|
|
|
void CommandHandler::SetProject(AudacityProject *)
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2015-05-16 22:57:01 +00:00
|
|
|
// TODO: Review if the extend command handling is ever utilized
|
|
|
|
// mCurrentContext->proj = proj;
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandHandler::OnReceiveCommand(AppCommandEvent &event)
|
|
|
|
{
|
|
|
|
// First retrieve the actual command from the event 'envelope'.
|
|
|
|
Command *cmd = event.GetCommand();
|
|
|
|
|
2013-12-16 21:24:21 +00:00
|
|
|
// JKC: In case the user changed the project, let us track that.
|
2016-02-13 15:43:16 +00:00
|
|
|
// This saves us the embarrassment (crash) of a NEW project
|
2014-06-03 20:30:19 +00:00
|
|
|
// being opened, the old one closed and still trying to act
|
2013-12-16 21:24:21 +00:00
|
|
|
// on the old one.
|
|
|
|
SetProject( GetActiveProject() );
|
2010-01-23 19:44:49 +00:00
|
|
|
// Then apply it to current application & project. Note that the
|
|
|
|
// command may change the context - for example, switching to a
|
|
|
|
// different project.
|
|
|
|
cmd->Apply(*mCurrentContext);
|
|
|
|
|
2016-02-14 23:50:45 +00:00
|
|
|
// Done with the command so DELETE it.
|
2010-01-23 19:44:49 +00:00
|
|
|
delete cmd;
|
|
|
|
|
|
|
|
// Redraw the project
|
2015-05-16 22:57:01 +00:00
|
|
|
mCurrentContext->GetProject()->RedrawProject();
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|