Fix for bug #887

A little overkill, but low risk since the majority of the source
changed isn't actually used.
This commit is contained in:
Leland Lucius 2015-05-16 17:57:01 -05:00
parent f98d9ce712
commit cbcc78b183
14 changed files with 85 additions and 72 deletions

View File

@ -285,7 +285,7 @@ ScreenFrame::ScreenFrame(wxWindow * parent, wxWindowID id)
// Note that the audio could be playing.
// The monitoring will switch off temporarily
// because we've switched monitor mid play.
mContext.proj->mToolManager->Reset();
mContext.GetProject()->mToolManager->Reset();
}
ScreenFrame::~ScreenFrame()
@ -447,7 +447,7 @@ void ScreenFrame::PopulateOrExchange(ShuttleGui & S)
CentreOnParent();
}
SetIcon(mContext.proj->GetIcon());
SetIcon(mContext.GetProject()->GetIcon());
}
bool ScreenFrame::ProcessEvent(wxEvent & e)
@ -541,9 +541,9 @@ void ScreenFrame::SizeMainWindow(int w, int h)
{
int top = 20;
mContext.proj->Maximize(false);
mContext.proj->SetSize(16, 16 + top, w, h);
mContext.proj->mToolManager->Reset();
mContext.GetProject()->Maximize(false);
mContext.GetProject()->SetSize(16, 16 + top, w, h);
mContext.GetProject()->mToolManager->Reset();
}
void ScreenFrame::OnMainWindowSmall(wxCommandEvent & WXUNUSED(event))
@ -660,9 +660,9 @@ void ScreenFrame::OnCaptureSecondTrack(wxCommandEvent & WXUNUSED(event))
void ScreenFrame::TimeZoom(double seconds)
{
int width, height;
mContext.proj->GetClientSize(&width, &height);
mContext.proj->mViewInfo.zoom = (0.75 * width) / seconds;
mContext.proj->RedrawProject();
mContext.GetProject()->GetClientSize(&width, &height);
mContext.GetProject()->mViewInfo.zoom = (0.75 * width) / seconds;
mContext.GetProject()->RedrawProject();
}
void ScreenFrame::OnOneSec(wxCommandEvent & WXUNUSED(event))
@ -692,7 +692,7 @@ void ScreenFrame::OnOneHour(wxCommandEvent & WXUNUSED(event))
void ScreenFrame::SizeTracks(int h)
{
TrackListIterator iter(mContext.proj->GetTracks());
TrackListIterator iter(mContext.GetProject()->GetTracks());
for (Track * t = iter.First(); t; t = iter.Next()) {
if (t->GetKind() == Track::Wave) {
if (t->GetLink()) {
@ -703,18 +703,18 @@ void ScreenFrame::SizeTracks(int h)
}
}
}
mContext.proj->RedrawProject();
mContext.GetProject()->RedrawProject();
}
void ScreenFrame::OnShortTracks(wxCommandEvent & WXUNUSED(event))
{
TrackListIterator iter(mContext.proj->GetTracks());
TrackListIterator iter(mContext.GetProject()->GetTracks());
for (Track * t = iter.First(); t; t = iter.Next()) {
if (t->GetKind() == Track::Wave) {
t->SetHeight(t->GetMinimizedHeight());
}
}
mContext.proj->RedrawProject();
mContext.GetProject()->RedrawProject();
}
void ScreenFrame::OnMedTracks(wxCommandEvent & WXUNUSED(event))

View File

@ -27,6 +27,8 @@ be controlled by a script should be separated out into its own Command class.
#ifndef __COMMAND__
#define __COMMAND__
#include <wx/app.h>
#include "CommandMisc.h"
#include "CommandSignature.h"
@ -36,11 +38,21 @@ class CommandOutputTarget;
class CommandExecutionContext
{
public:
AudacityApp *app;
AudacityProject *proj;
CommandExecutionContext(AudacityApp *app, AudacityProject *proj)
: app(app), proj(proj) {}
public:
CommandExecutionContext(AudacityApp *WXUNUSED(app), AudacityProject *WXUNUSED(proj))
{
};
AudacityApp *GetApp() const
{
return (AudacityApp *) wxTheApp;
};
AudacityProject *GetProject() const
{
// TODO: Presumably, this would be different if running in a command context.
// So, if this command system is ever actually enabled, then this will need to
// be reviewed.
return GetActiveProject();
};
};
// Interface

View File

@ -34,7 +34,8 @@ CommandHandler::~CommandHandler()
void CommandHandler::SetProject(AudacityProject *proj)
{
mCurrentContext->proj = proj;
// TODO: Review if the extend command handling is ever utilized
// mCurrentContext->proj = proj;
}
void CommandHandler::OnReceiveCommand(AppCommandEvent &event)
@ -56,5 +57,5 @@ void CommandHandler::OnReceiveCommand(AppCommandEvent &event)
delete cmd;
// Redraw the project
mCurrentContext->proj->RedrawProject();
mCurrentContext->GetProject()->RedrawProject();
}

View File

@ -83,7 +83,7 @@ inline int min(int a, int b)
bool CompareAudioCommand::Apply(CommandExecutionContext context)
{
if (!GetSelection(*context.proj))
if (!GetSelection(*context.GetProject()))
{
return false;
}

View File

@ -35,7 +35,7 @@ Command *ExecMenuCommandType::Create(CommandOutputTarget *target)
bool ExecMenuCommand::Apply(CommandExecutionContext context)
{
CommandManager *cmdManager = context.proj->GetCommandManager();
CommandManager *cmdManager = context.GetProject()->GetCommandManager();
wxString cmdName = GetString(wxT("CommandName"));
wxUint32 cmdFlags = 0; // TODO ?

View File

@ -37,7 +37,7 @@ bool GetAllMenuCommands::Apply(CommandExecutionContext context)
{
bool showStatus = GetBool(wxT("ShowStatus"));
wxArrayString names;
CommandManager *cmdManager = context.proj->GetCommandManager();
CommandManager *cmdManager = context.GetProject()->GetCommandManager();
cmdManager->GetAllCommandNames(names, false);
wxArrayString::iterator iter;
for (iter = names.begin(); iter != names.end(); ++iter)

View File

@ -50,11 +50,11 @@ Command *GetProjectInfoCommandType::Create(CommandOutputTarget *target)
bool GetProjectInfoCommand::Apply(CommandExecutionContext context)
{
wxString mode = GetString(wxT("Type"));
TrackList *projTracks = context.proj->GetTracks();
TrackList *projTracks = context.GetProject()->GetTracks();
if (mode.IsSameAs(wxT("Name")))
{
Status(context.proj->GetFileName());
Status(context.GetProject()->GetFileName());
}
else if (mode.IsSameAs(wxT("FocusedTrackID")))
{
@ -94,7 +94,7 @@ int GetProjectInfoCommand::SendNumberOfTracks(CommandExecutionContext context)
{
int returnVal=0;
TrackListIterator iter(context.proj->GetTracks());
TrackListIterator iter(context.GetProject()->GetTracks());
Track *t = iter.First();
while (t)
{
@ -111,10 +111,10 @@ int GetProjectInfoCommand::SendFocusedTrackIndex(CommandExecutionContext context
{
int returnVal=0;
int focusTrackIndex=0;
TrackPanel *panel = context.proj->GetTrackPanel();
TrackPanel *panel = context.GetProject()->GetTrackPanel();
Track* focusedTrack = panel->GetFocusedTrack();
TrackListIterator iter(context.proj->GetTracks());
TrackListIterator iter(context.GetProject()->GetTracks());
Track *t = iter.First();
while (t)
{

View File

@ -77,7 +77,7 @@ bool GetTrackInfoCommand::Apply(CommandExecutionContext context)
// Get the track indicated by the TrackIndex parameter
// (Note: this ought to be somewhere else)
long i = 0;
TrackListIterator iter(context.proj->GetTracks());
TrackListIterator iter(context.GetProject()->GetTracks());
Track *t = iter.First();
while (t && i != trackIndex)
{
@ -115,7 +115,7 @@ bool GetTrackInfoCommand::Apply(CommandExecutionContext context)
}
else if (mode.IsSameAs(wxT("Focused")))
{
TrackPanel *panel = context.proj->GetTrackPanel();
TrackPanel *panel = context.GetProject()->GetTrackPanel();
SendBooleanStatus(panel->GetFocusedTrack() == t);
}
else if (mode.IsSameAs(wxT("Selected")))

View File

@ -38,7 +38,7 @@ Command *ImportCommandType::Create(CommandOutputTarget *target)
bool ImportCommand::Apply(CommandExecutionContext context)
{
wxString filename = GetString(wxT("Filename"));
return context.proj->Import(filename);
return context.GetProject()->Import(filename);
}
ImportCommand::~ImportCommand()
@ -81,13 +81,13 @@ bool ExportCommand::Apply(CommandExecutionContext context)
double t0, t1;
if (selection)
{
t0 = context.proj->mViewInfo.selectedRegion.t0();
t1 = context.proj->mViewInfo.selectedRegion.t1();
t0 = context.GetProject()->mViewInfo.selectedRegion.t0();
t1 = context.GetProject()->mViewInfo.selectedRegion.t1();
}
else
{
t0 = 0.0;
t1 = context.proj->GetTracks()->GetEndTime();
t1 = context.GetProject()->GetTracks()->GetEndTime();
}
// Find the extension and check it's valid
@ -101,7 +101,7 @@ bool ExportCommand::Apply(CommandExecutionContext context)
Exporter exporter;
bool exportSuccess = exporter.Process(context.proj, numChannels,
bool exportSuccess = exporter.Process(context.GetProject(), numChannels,
extension.c_str(), filename,
selection, t0, t1);

View File

@ -41,16 +41,16 @@ bool OpenProjectCommand::Apply(CommandExecutionContext context)
{
wxString fileName = GetString(wxT("Filename"));
bool addToHistory = GetBool(wxT("AddToHistory"));
wxString oldFileName = context.proj->GetFileName();
wxString oldFileName = context.GetProject()->GetFileName();
if(fileName == wxEmptyString)
{
context.proj->OnOpen();
context.GetProject()->OnOpen();
}
else
{
context.proj->OpenFile(fileName,addToHistory);
context.GetProject()->OpenFile(fileName,addToHistory);
}
wxString newFileName = context.proj->GetFileName();
wxString newFileName = context.GetProject()->GetFileName();
// Because Open does not return a success or failure, we have to guess
// at this point, based on whether the project file name has
@ -91,9 +91,9 @@ bool SaveProjectCommand::Apply(CommandExecutionContext context)
bool saveCompressed = GetBool(wxT("Compress"));
bool addToHistory = GetBool(wxT("AddToHistory"));
if(fileName == wxEmptyString)
return context.proj->SaveAs(saveCompressed);
return context.GetProject()->SaveAs(saveCompressed);
else
return context.proj->SaveAs(fileName,saveCompressed,addToHistory);
return context.GetProject()->SaveAs(fileName,saveCompressed,addToHistory);
}
SaveProjectCommand::~SaveProjectCommand()

View File

@ -354,9 +354,9 @@ bool ScreenshotCommand::Apply(CommandExecutionContext context)
}
// Reset the toolbars to a known state
context.proj->mToolManager->Reset();
context.GetProject()->mToolManager->Reset();
wxTopLevelWindow *w = GetFrontWindow(context.proj);
wxTopLevelWindow *w = GetFrontWindow(context.GetProject());
if (!w)
{
return false;
@ -370,7 +370,7 @@ bool ScreenshotCommand::Apply(CommandExecutionContext context)
w->ClientToScreen(&x, &y);
w->GetClientSize(&width, &height);
if (w != context.proj && w->GetTitle() != wxT("")) {
if (w != context.GetProject() && w->GetTitle() != wxT("")) {
fileName = MakeFileName(filePath,
captureMode + (wxT("-") + w->GetTitle() + wxT("-")));
}
@ -385,7 +385,7 @@ bool ScreenshotCommand::Apply(CommandExecutionContext context)
r.SetPosition(w->GetScreenPosition());
r = w->GetScreenRect();
if (w != context.proj && w->GetTitle() != wxT("")) {
if (w != context.GetProject() && w->GetTitle() != wxT("")) {
fileName = MakeFileName(filePath,
captureMode + (wxT("-") + w->GetTitle() + wxT("-")));
}
@ -417,43 +417,43 @@ bool ScreenshotCommand::Apply(CommandExecutionContext context)
}
else if (captureMode.IsSameAs(wxT("toolbars")))
{
CaptureDock(context.proj->mToolManager->GetTopDock(), fileName);
CaptureDock(context.GetProject()->mToolManager->GetTopDock(), fileName);
}
else if (captureMode.IsSameAs(wxT("selectionbar")))
{
CaptureDock(context.proj->mToolManager->GetBotDock(), fileName);
CaptureDock(context.GetProject()->mToolManager->GetBotDock(), fileName);
}
else if (captureMode.IsSameAs(wxT("tools")))
{
CaptureToolbar(context.proj->mToolManager, ToolsBarID, fileName);
CaptureToolbar(context.GetProject()->mToolManager, ToolsBarID, fileName);
}
else if (captureMode.IsSameAs(wxT("transport")))
{
CaptureToolbar(context.proj->mToolManager, TransportBarID, fileName);
CaptureToolbar(context.GetProject()->mToolManager, TransportBarID, fileName);
}
else if (captureMode.IsSameAs(wxT("mixer")))
{
CaptureToolbar(context.proj->mToolManager, MixerBarID, fileName);
CaptureToolbar(context.GetProject()->mToolManager, MixerBarID, fileName);
}
else if (captureMode.IsSameAs(wxT("meter")))
{
CaptureToolbar(context.proj->mToolManager, MeterBarID, fileName);
CaptureToolbar(context.GetProject()->mToolManager, MeterBarID, fileName);
}
else if (captureMode.IsSameAs(wxT("edit")))
{
CaptureToolbar(context.proj->mToolManager, EditBarID, fileName);
CaptureToolbar(context.GetProject()->mToolManager, EditBarID, fileName);
}
else if (captureMode.IsSameAs(wxT("device")))
{
CaptureToolbar(context.proj->mToolManager, DeviceBarID, fileName);
CaptureToolbar(context.GetProject()->mToolManager, DeviceBarID, fileName);
}
else if (captureMode.IsSameAs(wxT("transcription")))
{
CaptureToolbar(context.proj->mToolManager, TranscriptionBarID, fileName);
CaptureToolbar(context.GetProject()->mToolManager, TranscriptionBarID, fileName);
}
else if (captureMode.IsSameAs(wxT("trackpanel")))
{
TrackPanel *panel = context.proj->mTrackPanel;
TrackPanel *panel = context.GetProject()->mTrackPanel;
//AdornedRulerPanel *ruler = panel->mRuler;
int h = panel->mRuler->GetRulerHeight();
@ -468,7 +468,7 @@ bool ScreenshotCommand::Apply(CommandExecutionContext context)
}
else if (captureMode.IsSameAs(wxT("ruler")))
{
TrackPanel *panel = context.proj->mTrackPanel;
TrackPanel *panel = context.GetProject()->mTrackPanel;
AdornedRulerPanel *ruler = panel->mRuler;
int x = 0, y = 0;
@ -483,7 +483,7 @@ bool ScreenshotCommand::Apply(CommandExecutionContext context)
}
else if (captureMode.IsSameAs(wxT("tracks")))
{
TrackPanel *panel = context.proj->mTrackPanel;
TrackPanel *panel = context.GetProject()->mTrackPanel;
int x = 0, y = 0;
int width, height;
@ -496,8 +496,8 @@ bool ScreenshotCommand::Apply(CommandExecutionContext context)
}
else if (captureMode.IsSameAs(wxT("firsttrack")))
{
TrackPanel *panel = context.proj->mTrackPanel;
TrackListIterator iter(context.proj->GetTracks());
TrackPanel *panel = context.GetProject()->mTrackPanel;
TrackListIterator iter(context.GetProject()->GetTracks());
Track * t = iter.First();
if (!t) {
return false;
@ -516,8 +516,8 @@ bool ScreenshotCommand::Apply(CommandExecutionContext context)
}
else if (captureMode.IsSameAs(wxT("secondtrack")))
{
TrackPanel *panel = context.proj->mTrackPanel;
TrackListIterator iter(context.proj->GetTracks());
TrackPanel *panel = context.GetProject()->mTrackPanel;
TrackListIterator iter(context.GetProject()->GetTracks());
Track * t = iter.First();
if (!t) {
return false;

View File

@ -59,12 +59,12 @@ bool SelectCommand::Apply(CommandExecutionContext context)
if (mode.IsSameAs(wxT("None")))
{
// select none
context.proj->OnSelectNone();
context.GetProject()->OnSelectNone();
}
else if (mode.IsSameAs(wxT("All")))
{
// select all
context.proj->OnSelectAll();
context.GetProject()->OnSelectAll();
}
else if (mode.IsSameAs(wxT("Range")))
{
@ -72,14 +72,14 @@ bool SelectCommand::Apply(CommandExecutionContext context)
double t0 = GetDouble(wxT("StartTime"));
double t1 = GetDouble(wxT("EndTime"));
TrackList *tracks = context.proj->GetTracks();
TrackList *tracks = context.GetProject()->GetTracks();
if (t0 < context.proj->GetTracks()->GetMinOffset())
if (t0 < context.GetProject()->GetTracks()->GetMinOffset())
{
Error(wxT("Start time is before start of track!"));
return false;
}
if (t1 > context.proj->GetTracks()->GetEndTime())
if (t1 > context.GetProject()->GetTracks()->GetEndTime())
{
Error(wxT("End time is after end of track!"));
return false;
@ -90,9 +90,9 @@ bool SelectCommand::Apply(CommandExecutionContext context)
// defaulted, as in the second branch?
// Or should this command take more parameters?
#if 1
context.proj->mViewInfo.selectedRegion.setTimes(t0, t1);
context.GetProject()->mViewInfo.selectedRegion.setTimes(t0, t1);
#else
context.proj->mViewInfo.selectedRegion = SelectedRegion(t0, t1);
context.GetProject()->mViewInfo.selectedRegion = SelectedRegion(t0, t1);
#endif
// select specified tracks
@ -128,7 +128,7 @@ bool SelectCommand::Apply(CommandExecutionContext context)
else if (mode.IsSameAs(wxT("Name")))
{
wxString name = GetString(wxT("TrackName"));
TrackList *tracks = context.proj->GetTracks();
TrackList *tracks = context.GetProject()->GetTracks();
TrackListIterator iter(tracks);
Track *t = iter.First();
while (t) {

View File

@ -57,14 +57,14 @@ bool SetProjectInfoCommand::Apply(CommandExecutionContext context)
wxString settingsString = GetString(wxT(kSetOfTracksStr));
if (mode.IsSameAs(wxT("SelectedTracks")))
SetAllTracksParam( context.proj->GetTracks(), settingsString,
SetAllTracksParam( context.GetProject()->GetTracks(), settingsString,
&SetProjectInfoCommand::setSelected);
else if (mode.IsSameAs(wxT("SoloTracks")))
SetAllTracksParam( context.proj->GetTracks(), settingsString, &SetProjectInfoCommand::setSolo);
SetAllTracksParam( context.GetProject()->GetTracks(), settingsString, &SetProjectInfoCommand::setSolo);
else if (mode.IsSameAs(wxT("MuteTracks")))
SetAllTracksParam( context.proj->GetTracks(), settingsString, &SetProjectInfoCommand::setMute);
SetAllTracksParam( context.GetProject()->GetTracks(), settingsString, &SetProjectInfoCommand::setMute);
else
{
Error(wxT("Invalid info type!"));

View File

@ -50,7 +50,7 @@ bool SetTrackInfoCommand::Apply(CommandExecutionContext context)
// (Note: track selection ought to be somewhere else)
long i = 0;
TrackListIterator iter(context.proj->GetTracks());
TrackListIterator iter(context.GetProject()->GetTracks());
Track *t = iter.First();
while (t && i != trackIndex)
{