1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-17 17:17:40 +02:00

Pass AudacityProject * into preference panel factories

This commit is contained in:
Paul Licameli 2020-01-04 12:24:14 -05:00
parent 72f66b7096
commit c9a9c06bd0
29 changed files with 56 additions and 40 deletions

@ -1658,8 +1658,9 @@ bool AudacityApp::OnInit()
// Only want one page of the preferences // Only want one page of the preferences
PrefsDialog::Factories factories; PrefsDialog::Factories factories;
factories.push_back(KeyConfigPrefsFactory( id )); factories.push_back(KeyConfigPrefsFactory( id ));
auto pWindow = FindProjectFrame( GetActiveProject() ); const auto pProject = GetActiveProject();
GlobalPrefsDialog dialog( pWindow, factories ); auto pWindow = FindProjectFrame( pProject );
GlobalPrefsDialog dialog( pWindow, pProject, factories );
dialog.ShowModal(); dialog.ShowModal();
MenuCreator::RebuildAllMenuBars(); MenuCreator::RebuildAllMenuBars();
return true; return true;
@ -1796,7 +1797,7 @@ bool AudacityApp::InitTempDir()
// Only want one page of the preferences // Only want one page of the preferences
PrefsDialog::Factories factories; PrefsDialog::Factories factories;
factories.push_back(DirectoriesPrefsFactory()); factories.push_back(DirectoriesPrefsFactory());
GlobalPrefsDialog dialog(NULL, factories); GlobalPrefsDialog dialog(nullptr, nullptr, factories);
dialog.ShowModal(); dialog.ShowModal();
AudacityMessageBox(XO( AudacityMessageBox(XO(
@ -2248,7 +2249,7 @@ void AudacityApp::OnMenuPreferences(wxCommandEvent & event)
// all platforms. // all platforms.
if(AllProjects{}.empty()) { if(AllProjects{}.empty()) {
GlobalPrefsDialog dialog(NULL /* parent */ ); GlobalPrefsDialog dialog(nullptr /* parent */, nullptr );
dialog.ShowModal(); dialog.ShowModal();
} }
else else

@ -362,7 +362,7 @@ bool GetInfoCommand::SendPreferences(const CommandContext &context)
{ {
context.StartArray(); context.StartArray();
auto pWin = &GetProjectFrame( context.project ); auto pWin = &GetProjectFrame( context.project );
GlobalPrefsDialog dialog( pWin ); GlobalPrefsDialog dialog( pWin, &context.project );
// wxCommandEvent Evt; // wxCommandEvent Evt;
//dialog.Show(); //dialog.Show();
ShuttleGuiGetDefinition S(pWin, *((context.pOutput)->mStatusTarget) ); ShuttleGuiGetDefinition S(pWin, *((context.pOutput)->mStatusTarget) );

@ -933,7 +933,7 @@ void OnPreferences(const CommandContext &context)
{ {
auto &project = context.project; auto &project = context.project;
GlobalPrefsDialog dialog(&GetProjectFrame( project ) /* parent */ ); GlobalPrefsDialog dialog(&GetProjectFrame( project ) /* parent */, &project );
if( ScreenshotCommand::MayCapture( &dialog ) ) if( ScreenshotCommand::MayCapture( &dialog ) )
return; return;

@ -96,7 +96,7 @@ BatchPrefs::~BatchPrefs()
} }
PrefsPanel::Factory PrefsPanel::Factory
BatchPrefsFactory = [](wxWindow *parent, wxWindowID winid) BatchPrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew BatchPrefs(parent, winid); return safenew BatchPrefs(parent, winid);

@ -423,7 +423,7 @@ bool DevicePrefs::Commit()
} }
PrefsPanel::Factory PrefsPanel::Factory
DevicePrefsFactory = [](wxWindow *parent, wxWindowID winid) DevicePrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew

@ -292,7 +292,7 @@ bool DirectoriesPrefs::Commit()
PrefsPanel::Factory PrefsPanel::Factory
DirectoriesPrefsFactory() { DirectoriesPrefsFactory() {
return [](wxWindow *parent, wxWindowID winid) return [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew DirectoriesPrefs(parent, winid); return safenew DirectoriesPrefs(parent, winid);

@ -251,7 +251,7 @@ bool EffectsPrefs::Commit()
} }
PrefsPanel::Factory PrefsPanel::Factory
EffectsPrefsFactory = [](wxWindow *parent, wxWindowID winid) EffectsPrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew EffectsPrefs(parent, winid); return safenew EffectsPrefs(parent, winid);

@ -827,7 +827,7 @@ void ExtImportPrefsDropTarget::OnLeave()
} }
PrefsPanel::Factory PrefsPanel::Factory
ExtImportPrefsFactory = [](wxWindow *parent, wxWindowID winid) ExtImportPrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew ExtImportPrefs(parent, winid); return safenew ExtImportPrefs(parent, winid);

@ -378,7 +378,7 @@ int ShowClippingPrefsID()
} }
PrefsPanel::Factory PrefsPanel::Factory
GUIPrefsFactory = [](wxWindow *parent, wxWindowID winid) GUIPrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew GUIPrefs(parent, winid); return safenew GUIPrefs(parent, winid);

@ -150,7 +150,7 @@ bool ImportExportPrefs::Commit()
} }
PrefsPanel::Factory PrefsPanel::Factory
ImportExportPrefsFactory = [](wxWindow *parent, wxWindowID winid) ImportExportPrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew ImportExportPrefs(parent, winid); return safenew ImportExportPrefs(parent, winid);

@ -714,7 +714,7 @@ void KeyConfigPrefs::Cancel()
PrefsPanel::Factory PrefsPanel::Factory
KeyConfigPrefsFactory( const CommandID &name ) KeyConfigPrefsFactory( const CommandID &name )
{ {
return [=](wxWindow *parent, wxWindowID winid) return [=](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
auto result = safenew KeyConfigPrefs{ parent, winid, name }; auto result = safenew KeyConfigPrefs{ parent, winid, name };

@ -262,7 +262,7 @@ bool LibraryPrefs::Commit()
} }
PrefsPanel::Factory PrefsPanel::Factory
LibraryPrefsFactory = [](wxWindow *parent, wxWindowID winid) LibraryPrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew LibraryPrefs(parent, winid); return safenew LibraryPrefs(parent, winid);

@ -302,7 +302,7 @@ bool MidiIOPrefs::Validate()
} }
PrefsPanel::Factory PrefsPanel::Factory
MidiIOPrefsFactory = [](wxWindow *parent, wxWindowID winid) MidiIOPrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew MidiIOPrefs(parent, winid); return safenew MidiIOPrefs(parent, winid);

@ -188,7 +188,7 @@ void ModulePrefs::SetModuleStatus(const FilePath &fname, int iStatus){
} }
PrefsPanel::Factory PrefsPanel::Factory
ModulePrefsFactory = [](wxWindow *parent, wxWindowID winid) ModulePrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew ModulePrefs(parent, winid); return safenew ModulePrefs(parent, winid);

@ -223,7 +223,7 @@ bool MousePrefs::Commit()
} }
PrefsPanel::Factory PrefsPanel::Factory
MousePrefsFactory = [](wxWindow *parent, wxWindowID winid) MousePrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew MousePrefs(parent, winid); return safenew MousePrefs(parent, winid);

@ -183,7 +183,7 @@ bool PlaybackPrefs::Commit()
} }
PrefsPanel::Factory PrefsPanel::Factory
PlaybackPrefsFactory = [](wxWindow *parent, wxWindowID winid) PlaybackPrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew PlaybackPrefs(parent, winid); return safenew PlaybackPrefs(parent, winid);

@ -533,7 +533,7 @@ PrefsDialog::Factories
PrefsDialog::PrefsDialog( PrefsDialog::PrefsDialog(
wxWindow * parent, wxWindow * parent, AudacityProject *pProject,
const TranslatableString &titlePrefix, Factories &factories) const TranslatableString &titlePrefix, Factories &factories)
: wxDialogWrapper(parent, wxID_ANY, XO("Audacity Preferences"), : wxDialogWrapper(parent, wxID_ANY, XO("Audacity Preferences"),
wxDefaultPosition, wxDefaultPosition,
@ -575,7 +575,7 @@ PrefsDialog::PrefsDialog(
{ {
const PrefsNode &node = *it; const PrefsNode &node = *it;
const PrefsPanel::Factory &factory = node.factory; const PrefsPanel::Factory &factory = node.factory;
wxWindow *const w = factory(mCategories, wxID_ANY); wxWindow *const w = factory(mCategories, wxID_ANY, pProject);
if (stack.empty()) if (stack.empty())
// Parameters are: AddPage(page, name, IsSelected, imageId). // Parameters are: AddPage(page, name, IsSelected, imageId).
mCategories->AddPage(w, w->GetName(), false, 0); mCategories->AddPage(w, w->GetName(), false, 0);
@ -603,7 +603,7 @@ PrefsDialog::PrefsDialog(
// Unique page, don't show the factory // Unique page, don't show the factory
const PrefsNode &node = factories[0]; const PrefsNode &node = factories[0];
const PrefsPanel::Factory &factory = node.factory; const PrefsPanel::Factory &factory = node.factory;
mUniquePage = factory(S.GetParent(), wxID_ANY); mUniquePage = factory(S.GetParent(), wxID_ANY, pProject);
wxWindow * uniquePageWindow = S.Prop(1) wxWindow * uniquePageWindow = S.Prop(1)
.Position(wxEXPAND) .Position(wxEXPAND)
.AddWindow(mUniquePage); .AddWindow(mUniquePage);
@ -888,8 +888,9 @@ int PrefsDialog::GetSelectedPage() const
return 0; return 0;
} }
GlobalPrefsDialog::GlobalPrefsDialog(wxWindow * parent, Factories &factories) GlobalPrefsDialog::GlobalPrefsDialog(
: PrefsDialog(parent, XO("Preferences:"), factories) wxWindow * parent, AudacityProject *pProject, Factories &factories)
: PrefsDialog(parent, pProject, XO("Preferences:"), factories)
{ {
} }
@ -951,7 +952,8 @@ void DoReloadPreferences( AudacityProject &project )
SpectrogramSettings::defaults().LoadPrefs(); SpectrogramSettings::defaults().LoadPrefs();
WaveformSettings::defaults().LoadPrefs(); WaveformSettings::defaults().LoadPrefs();
GlobalPrefsDialog dialog(&GetProjectFrame( project ) /* parent */ ); GlobalPrefsDialog dialog(
&GetProjectFrame( project ) /* parent */, &project );
wxCommandEvent Evt; wxCommandEvent Evt;
//dialog.Show(); //dialog.Show();
dialog.OnOK(Evt); dialog.OnOK(Evt);

@ -16,6 +16,7 @@
#include <vector> #include <vector>
#include "../widgets/wxPanelWrapper.h" // to inherit #include "../widgets/wxPanelWrapper.h" // to inherit
class AudacityProject;
class wxTreebook; class wxTreebook;
class wxTreeEvent; class wxTreeEvent;
class PrefsPanel; class PrefsPanel;
@ -27,13 +28,16 @@ class ShuttleGui;
#define CONST const #define CONST const
#endif #endif
class AudacityProject;
class PrefsDialog /* not final */ : public wxDialogWrapper class PrefsDialog /* not final */ : public wxDialogWrapper
{ {
public: public:
// An array of PrefsNode specifies the tree of pages in pre-order traversal. // An array of PrefsNode specifies the tree of pages in pre-order traversal.
struct PrefsNode { struct PrefsNode {
using Factory = using Factory =
std::function< PrefsPanel * (wxWindow *parent, wxWindowID winid) >; std::function< PrefsPanel * (
wxWindow *parent, wxWindowID winid, AudacityProject *) >;
Factory factory; Factory factory;
CONST int nChildren; CONST int nChildren;
bool expanded; bool expanded;
@ -48,6 +52,7 @@ class PrefsDialog /* not final */ : public wxDialogWrapper
static Factories &DefaultFactories(); static Factories &DefaultFactories();
PrefsDialog(wxWindow * parent, PrefsDialog(wxWindow * parent,
AudacityProject *pProject, // may be null
const TranslatableString &titlePrefix = XO("Preferences:"), const TranslatableString &titlePrefix = XO("Preferences:"),
Factories &factories = DefaultFactories()); Factories &factories = DefaultFactories());
virtual ~PrefsDialog(); virtual ~PrefsDialog();
@ -92,7 +97,9 @@ private:
class GlobalPrefsDialog final : public PrefsDialog class GlobalPrefsDialog final : public PrefsDialog
{ {
public: public:
GlobalPrefsDialog(wxWindow * parent, Factories &factories = DefaultFactories()); GlobalPrefsDialog(
wxWindow * parent, AudacityProject *pProject,
Factories &factories = DefaultFactories());
virtual ~GlobalPrefsDialog(); virtual ~GlobalPrefsDialog();
long GetPreferredPage() override; long GetPreferredPage() override;
void SavePreferredPage() override; void SavePreferredPage() override;

@ -42,6 +42,7 @@ MousePrefs, QualityPrefs, SpectrumPrefs and ThemePrefs.
#define TOP_LEVEL_BORDER 5 #define TOP_LEVEL_BORDER 5
#define GENERIC_CONTROL_BORDER 5 #define GENERIC_CONTROL_BORDER 5
class AudacityProject;
class ShuttleGui; class ShuttleGui;
class PrefsPanel /* not final */ : public wxPanelWrapper, ComponentInterface class PrefsPanel /* not final */ : public wxPanelWrapper, ComponentInterface
@ -49,8 +50,12 @@ class PrefsPanel /* not final */ : public wxPanelWrapper, ComponentInterface
public: public:
// \brief Type alias for factories such as GUIPrefsFactory that produce a // \brief Type alias for factories such as GUIPrefsFactory that produce a
// PrefsPanel. // PrefsPanel.
// The project pointer may be null. Usually it's not needed because
// preferences are global. But sometimes you need a project, such as to
// preview the preference changes for spectrograms.
using Factory = using Factory =
std::function< PrefsPanel * (wxWindow *parent, wxWindowID winid) >; std::function< PrefsPanel * (
wxWindow *parent, wxWindowID winid, AudacityProject *) >;
PrefsPanel( PrefsPanel(
wxWindow * parent, wxWindowID winid, const TranslatableString &title) wxWindow * parent, wxWindowID winid, const TranslatableString &title)

@ -96,7 +96,7 @@ bool ProjectsPrefs::Commit()
} }
PrefsPanel::Factory PrefsPanel::Factory
ProjectsPrefsFactory = [](wxWindow *parent, wxWindowID winid) ProjectsPrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew ProjectsPrefs(parent, winid); return safenew ProjectsPrefs(parent, winid);

@ -234,7 +234,7 @@ bool QualityPrefs::Commit()
} }
PrefsPanel::Factory PrefsPanel::Factory
QualityPrefsFactory = [](wxWindow *parent, wxWindowID winid) QualityPrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew QualityPrefs(parent, winid); return safenew QualityPrefs(parent, winid);

@ -305,7 +305,7 @@ void RecordingPrefs::OnToggleCustomName(wxCommandEvent & /* Evt */)
} }
PrefsPanel::Factory PrefsPanel::Factory
RecordingPrefsFactory = [](wxWindow *parent, wxWindowID winid) RecordingPrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew RecordingPrefs(parent, winid); return safenew RecordingPrefs(parent, winid);

@ -588,7 +588,7 @@ END_EVENT_TABLE()
PrefsPanel::Factory PrefsPanel::Factory
SpectrumPrefsFactory( WaveTrack *wt ) SpectrumPrefsFactory( WaveTrack *wt )
{ {
return [=](wxWindow *parent, wxWindowID winid) return [=](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew SpectrumPrefs(parent, winid, wt); return safenew SpectrumPrefs(parent, winid, wt);

@ -230,7 +230,7 @@ bool ThemePrefs::Commit()
} }
PrefsPanel::Factory PrefsPanel::Factory
ThemePrefsFactory = [](wxWindow *parent, wxWindowID winid) ThemePrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew ThemePrefs(parent, winid); return safenew ThemePrefs(parent, winid);

@ -132,7 +132,7 @@ bool TracksBehaviorsPrefs::Commit()
} }
PrefsPanel::Factory PrefsPanel::Factory
TracksBehaviorsPrefsFactory = [](wxWindow *parent, wxWindowID winid) TracksBehaviorsPrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew TracksBehaviorsPrefs(parent, winid); return safenew TracksBehaviorsPrefs(parent, winid);

@ -396,7 +396,7 @@ bool TracksPrefs::Commit()
} }
PrefsPanel::Factory PrefsPanel::Factory
TracksPrefsFactory = [](wxWindow *parent, wxWindowID winid) TracksPrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew TracksPrefs(parent, winid); return safenew TracksPrefs(parent, winid);

@ -107,7 +107,7 @@ bool WarningsPrefs::Commit()
} }
PrefsPanel::Factory PrefsPanel::Factory
WarningsPrefsFactory = [](wxWindow *parent, wxWindowID winid) WarningsPrefsFactory = [](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew WarningsPrefs(parent, winid); return safenew WarningsPrefs(parent, winid);

@ -256,7 +256,7 @@ END_EVENT_TABLE()
PrefsPanel::Factory PrefsPanel::Factory
WaveformPrefsFactory(WaveTrack *wt) WaveformPrefsFactory(WaveTrack *wt)
{ {
return [=](wxWindow *parent, wxWindowID winid) return [=](wxWindow *parent, wxWindowID winid, AudacityProject *)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew WaveformPrefs(parent, winid, wt); return safenew WaveformPrefs(parent, winid, wt);

@ -828,10 +828,10 @@ void WaveTrackMenuTable::OnSpectrogramSettings(wxCommandEvent &)
class ViewSettingsDialog final : public PrefsDialog class ViewSettingsDialog final : public PrefsDialog
{ {
public: public:
ViewSettingsDialog(wxWindow *parent, ViewSettingsDialog(wxWindow *parent, AudacityProject &project,
const TranslatableString &title, PrefsDialog::Factories &factories, const TranslatableString &title, PrefsDialog::Factories &factories,
int page) int page)
: PrefsDialog(parent, title, factories) : PrefsDialog(parent, &project, title, factories)
, mPage(page) , mPage(page)
{ {
} }
@ -869,7 +869,8 @@ void WaveTrackMenuTable::OnSpectrogramSettings(wxCommandEvent &)
0; 0;
auto title = XO("%s:").Format( pTrack->GetName() ); auto title = XO("%s:").Format( pTrack->GetName() );
ViewSettingsDialog dialog(mpData->pParent, title, factories, page); ViewSettingsDialog dialog(
mpData->pParent, mpData->project, title, factories, page);
if (0 != dialog.ShowModal()) { if (0 != dialog.ShowModal()) {
// Redraw // Redraw