1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-04-24 23:13:42 +02:00

Accessors to get the project window...

... as a preparation for splitting up class AudacityProject.

Use ProjectWindow as an alias for AudacityProject, and fetch it from the
project with a static member function, where certain of its services are used;
pretending they are not the same class.

Use global accessor functions to get wxFrame from the project where only
wxFrame's member functions are needed, so there will be less dependency on
ProjectWindow when it becomes a distinct class.
This commit is contained in:
Paul Licameli
2019-05-28 13:12:56 -04:00
parent 02afcbca8c
commit 82663892dc
49 changed files with 451 additions and 296 deletions

View File

@@ -37,6 +37,7 @@ bool DoPasteText(AudacityProject &project)
auto &tracks = TrackList::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
for (auto pLabelTrack : tracks.Any<LabelTrack>())
{
@@ -56,7 +57,7 @@ bool DoPasteText(AudacityProject &project)
}
// Redraw everyting (is that necessary???) and bail
project.RedrawProject();
window.RedrawProject();
return true;
}
}
@@ -73,6 +74,7 @@ bool DoPasteNothingSelected(AudacityProject &project)
auto &trackFactory = TrackFactory::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
// First check whether anything's selected.
if (tracks.Selected())
@@ -147,7 +149,7 @@ bool DoPasteNothingSelected(AudacityProject &project)
project.PushState(_("Pasted from the clipboard"), _("Paste"));
project.RedrawProject();
window.RedrawProject();
if (pFirstNewTrack)
trackPanel.EnsureVisible(pFirstNewTrack);
@@ -168,7 +170,7 @@ void DoReloadPreferences( AudacityProject &project )
SpectrogramSettings::defaults().LoadPrefs();
WaveformSettings::defaults().LoadPrefs();
GlobalPrefsDialog dialog(&project /* parent */ );
GlobalPrefsDialog dialog(&GetProjectFrame( project ) /* parent */ );
wxCommandEvent Evt;
//dialog.Show();
dialog.OnOK(Evt);
@@ -189,9 +191,10 @@ void DoReloadPreferences( AudacityProject &project )
//
// This workaround should be removed when Audacity updates to wxWidgets
// 3.x which has a fix.
wxRect r = p->GetRect();
p->SetSize(wxSize(1,1));
p->SetSize(r.GetSize());
auto &window = GetProjectFrame( *p );
wxRect r = window.GetRect();
window.SetSize(wxSize(1,1));
window.SetSize(r.GetSize());
#endif
}
}
@@ -209,7 +212,7 @@ bool DoEditMetadata
// BEFORE doing any editing of it!
auto newTags = tags.Duplicate();
if (newTags->ShowEditDialog(&project, title, force)) {
if (newTags->ShowEditDialog(&GetProjectFrame( project ), title, force)) {
if (tags != *newTags) {
// Commit the change to project state only now.
Tags::Set( project, newTags );
@@ -228,6 +231,7 @@ void DoUndo(AudacityProject &project)
{
auto &trackPanel = TrackPanel::Get( project );
auto &undoManager = UndoManager::Get( project );
auto &window = ProjectWindow::Get( project );
if (!project.UndoAvailable()) {
AudacityMessageBox(_("Nothing to undo"));
@@ -244,7 +248,7 @@ void DoUndo(AudacityProject &project)
trackPanel.EnsureVisible(trackPanel.GetFirstSelectedTrack());
project.RedrawProject();
window.RedrawProject();
MenuManager::ModifyUndoMenuItems(project);
}
@@ -263,6 +267,7 @@ void OnRedo(const CommandContext &context)
auto &project = context.project;
auto &trackPanel = TrackPanel::Get( project );
auto &undoManager = UndoManager::Get( project );
auto &window = ProjectWindow::Get( project );
if (!project.RedoAvailable()) {
AudacityMessageBox(_("Nothing to redo"));
@@ -278,7 +283,7 @@ void OnRedo(const CommandContext &context)
trackPanel.EnsureVisible(trackPanel.GetFirstSelectedTrack());
project.RedrawProject();
window.RedrawProject();
MenuManager::ModifyUndoMenuItems(project);
}
@@ -290,6 +295,7 @@ void OnCut(const CommandContext &context)
auto &trackPanel = TrackPanel::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &ruler = AdornedRulerPanel::Get( project );
auto &window = ProjectWindow::Get( project );
// This doesn't handle cutting labels, it handles
// cutting the _text_ inside of labels, i.e. if you're
@@ -366,7 +372,7 @@ void OnCut(const CommandContext &context)
//mRuler->ClearPlayRegion();
ruler.DrawOverlays( true );
project.RedrawProject();
window.RedrawProject();
}
void OnDelete(const CommandContext &context)
@@ -374,6 +380,7 @@ void OnDelete(const CommandContext &context)
auto &project = context.project;
auto &tracks = TrackList::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
for (auto n : tracks.Any()) {
if (n->GetSelected() || n->IsSyncLockSelected()) {
@@ -390,7 +397,7 @@ void OnDelete(const CommandContext &context)
selectedRegion.t0()),
_("Delete"));
project.RedrawProject();
window.RedrawProject();
}
@@ -435,6 +442,8 @@ void OnPaste(const CommandContext &context)
auto &trackPanel = TrackPanel::Get( project );
auto &trackFactory = TrackFactory::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
auto isSyncLocked = project.IsSyncLocked();
// Handle text paste (into active label) first.
@@ -684,7 +693,7 @@ void OnPaste(const CommandContext &context)
project.PushState(_("Pasted from the clipboard"), _("Paste"));
project.RedrawProject();
window.RedrawProject();
if (ff)
trackPanel.EnsureVisible(ff);
@@ -696,6 +705,7 @@ void OnDuplicate(const CommandContext &context)
auto &project = context.project;
auto &tracks = TrackList::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
// This iteration is unusual because we add to the list inside the loop
auto range = tracks.Selected();
@@ -715,7 +725,7 @@ void OnDuplicate(const CommandContext &context)
project.PushState(_("Duplicated"), _("Duplicate"));
project.RedrawProject();
window.RedrawProject();
}
void OnSplitCut(const CommandContext &context)
@@ -723,6 +733,7 @@ void OnSplitCut(const CommandContext &context)
auto &project = context.project;
auto &tracks = TrackList::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
auto &clipboard = Clipboard::Get();
clipboard.Clear();
@@ -756,7 +767,7 @@ void OnSplitCut(const CommandContext &context)
project.PushState(_("Split-cut to the clipboard"), _("Split Cut"));
project.RedrawProject();
window.RedrawProject();
}
void OnSplitDelete(const CommandContext &context)
@@ -764,6 +775,7 @@ void OnSplitDelete(const CommandContext &context)
auto &project = context.project;
auto &tracks = TrackList::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
tracks.Selected().Visit(
[&](WaveTrack *wt) {
@@ -782,7 +794,7 @@ void OnSplitDelete(const CommandContext &context)
selectedRegion.t0()),
_("Split Delete"));
project.RedrawProject();
window.RedrawProject();
}
void OnSilence(const CommandContext &context)
@@ -809,6 +821,7 @@ void OnTrim(const CommandContext &context)
auto &project = context.project;
auto &tracks = TrackList::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
if (selectedRegion.isPoint())
return;
@@ -833,7 +846,7 @@ void OnTrim(const CommandContext &context)
selectedRegion.t0(), selectedRegion.t1()),
_("Trim Audio"));
project.RedrawProject();
window.RedrawProject();
}
void OnSplit(const CommandContext &context)
@@ -907,6 +920,7 @@ void OnSplitNew(const CommandContext &context)
auto &project = context.project;
auto &tracks = TrackList::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
Track::Holder dest;
@@ -950,7 +964,7 @@ void OnSplitNew(const CommandContext &context)
project.PushState(_("Split to new track"), _("Split New"));
project.RedrawProject();
window.RedrawProject();
}
void OnJoin(const CommandContext &context)
@@ -958,6 +972,7 @@ void OnJoin(const CommandContext &context)
auto &project = context.project;
auto &tracks = TrackList::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
for (auto wt : tracks.Selected< WaveTrack >())
wt->Join(selectedRegion.t0(),
@@ -969,7 +984,7 @@ void OnJoin(const CommandContext &context)
selectedRegion.t0()),
_("Join"));
project.RedrawProject();
window.RedrawProject();
}
void OnDisjoin(const CommandContext &context)
@@ -977,6 +992,7 @@ void OnDisjoin(const CommandContext &context)
auto &project = context.project;
auto &tracks = TrackList::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
for (auto wt : tracks.Selected< WaveTrack >())
wt->Disjoin(selectedRegion.t0(),
@@ -988,7 +1004,7 @@ void OnDisjoin(const CommandContext &context)
selectedRegion.t0()),
_("Detach"));
project.RedrawProject();
window.RedrawProject();
}
void OnEditMetadata(const CommandContext &context)
@@ -1002,7 +1018,7 @@ void OnPreferences(const CommandContext &context)
{
auto &project = context.project;
GlobalPrefsDialog dialog(&project /* parent */ );
GlobalPrefsDialog dialog(&GetProjectFrame( project ) /* parent */ );
if( ScreenshotCommand::MayCapture( &dialog ) )
return;
@@ -1027,9 +1043,10 @@ void OnPreferences(const CommandContext &context)
//
// This workaround should be removed when Audacity updates to wxWidgets
// 3.x which has a fix.
wxRect r = p->GetRect();
p->SetSize(wxSize(1,1));
p->SetSize(r.GetSize());
auto &window = GetProjectFrame( *p );
wxRect r = window.GetRect();
window.SetSize(wxSize(1,1));
window.SetSize(r.GetSize());
#endif
}
}