diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index ee732c880..313f5731e 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -1829,9 +1829,8 @@ bool AudacityApp::InitTempDir() } // Only want one page of the preferences - DirectoriesPrefsFactory directoriesPrefsFactory; PrefsDialog::Factories factories; - factories.push_back(&directoriesPrefsFactory); + factories.push_back(DirectoriesPrefsFactory()); GlobalPrefsDialog dialog(NULL, factories); dialog.ShowModal(); diff --git a/src/commands/CommandManager.cpp b/src/commands/CommandManager.cpp index c54fe8e99..2a4f11902 100644 --- a/src/commands/CommandManager.cpp +++ b/src/commands/CommandManager.cpp @@ -1555,9 +1555,8 @@ bool CommandManager::HandleMenuID(int id, CommandFlag flags, CommandMask mask) #ifdef EXPERIMENTAL_EASY_CHANGE_KEY_BINDINGS if (::wxGetMouseState().ShiftDown()) { // Only want one page of the preferences - KeyConfigPrefsFactory keyConfigPrefsFactory{ entry->name }; PrefsDialog::Factories factories; - factories.push_back(&keyConfigPrefsFactory); + factories.push_back(KeyConfigPrefsFactory( entry->name )); GlobalPrefsDialog dialog(GetActiveProject(), factories); dialog.ShowModal(); MenuCreator::RebuildAllMenuBars(); diff --git a/src/prefs/BatchPrefs.cpp b/src/prefs/BatchPrefs.cpp index a1f4e1f69..e6d599377 100644 --- a/src/prefs/BatchPrefs.cpp +++ b/src/prefs/BatchPrefs.cpp @@ -95,8 +95,9 @@ BatchPrefs::~BatchPrefs() { } -PrefsPanel *BatchPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +BatchPrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew BatchPrefs(parent, winid); -} +}; diff --git a/src/prefs/BatchPrefs.h b/src/prefs/BatchPrefs.h index e5ff5eb7e..49d5d000f 100644 --- a/src/prefs/BatchPrefs.h +++ b/src/prefs/BatchPrefs.h @@ -39,10 +39,6 @@ private: }; -/// A PrefsPanelFactory that creates one BatchPrefs panel. -class BatchPrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one BatchPrefs panel. +extern PrefsPanel::Factory BatchPrefsFactory; #endif diff --git a/src/prefs/DevicePrefs.cpp b/src/prefs/DevicePrefs.cpp index da02b6621..1b6d07c01 100644 --- a/src/prefs/DevicePrefs.cpp +++ b/src/prefs/DevicePrefs.cpp @@ -420,8 +420,10 @@ bool DevicePrefs::Commit() return true; } -PrefsPanel *DevicePrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +DevicePrefsFactory = [](wxWindow *parent, wxWindowID winid) + { wxASSERT(parent); // to justify safenew return safenew DevicePrefs(parent, winid); -} +}; diff --git a/src/prefs/DevicePrefs.h b/src/prefs/DevicePrefs.h index e51c069f5..6957d07e7 100644 --- a/src/prefs/DevicePrefs.h +++ b/src/prefs/DevicePrefs.h @@ -57,11 +57,7 @@ class DevicePrefs final : public PrefsPanel DECLARE_EVENT_TABLE() }; -/// A PrefsPanelFactory that creates one DevicePrefs panel. -class DevicePrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one DevicePrefs panel. +extern PrefsPanel::Factory DevicePrefsFactory; #endif diff --git a/src/prefs/DirectoriesPrefs.cpp b/src/prefs/DirectoriesPrefs.cpp index ad8cefb3f..f9713d1d8 100644 --- a/src/prefs/DirectoriesPrefs.cpp +++ b/src/prefs/DirectoriesPrefs.cpp @@ -287,8 +287,11 @@ bool DirectoriesPrefs::Commit() return true; } -PrefsPanel *DirectoriesPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) -{ - wxASSERT(parent); // to justify safenew - return safenew DirectoriesPrefs(parent, winid); +PrefsPanel::Factory +DirectoriesPrefsFactory() { + return [](wxWindow *parent, wxWindowID winid) + { + wxASSERT(parent); // to justify safenew + return safenew DirectoriesPrefs(parent, winid); + }; } diff --git a/src/prefs/DirectoriesPrefs.h b/src/prefs/DirectoriesPrefs.h index 3dac185c2..bf4681f1f 100644 --- a/src/prefs/DirectoriesPrefs.h +++ b/src/prefs/DirectoriesPrefs.h @@ -44,10 +44,7 @@ class DirectoriesPrefs final : public PrefsPanel DECLARE_EVENT_TABLE() }; -/// A PrefsPanelFactory that creates one DirectoriesPrefs panel. -class DirectoriesPrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one DirectoriesPrefs panel. +/// This one is used not only in the Preferences command. +extern PrefsPanel::Factory DirectoriesPrefsFactory(); #endif diff --git a/src/prefs/EffectsPrefs.cpp b/src/prefs/EffectsPrefs.cpp index a5f7721f5..350644ca8 100644 --- a/src/prefs/EffectsPrefs.cpp +++ b/src/prefs/EffectsPrefs.cpp @@ -200,8 +200,9 @@ bool EffectsPrefs::Commit() return true; } -PrefsPanel *EffectsPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +EffectsPrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew EffectsPrefs(parent, winid); -} +}; diff --git a/src/prefs/EffectsPrefs.h b/src/prefs/EffectsPrefs.h index 3c7b71363..6c5ba3a6d 100644 --- a/src/prefs/EffectsPrefs.h +++ b/src/prefs/EffectsPrefs.h @@ -37,10 +37,6 @@ class EffectsPrefs final : public PrefsPanel void Populate(); }; -/// A PrefsPanelFactory that creates one EffectsPrefs panel. -class EffectsPrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one EffectsPrefs panel. +extern PrefsPanel::Factory EffectsPrefsFactory; #endif diff --git a/src/prefs/ExtImportPrefs.cpp b/src/prefs/ExtImportPrefs.cpp index aab12e37f..d99855b4d 100644 --- a/src/prefs/ExtImportPrefs.cpp +++ b/src/prefs/ExtImportPrefs.cpp @@ -822,8 +822,9 @@ void ExtImportPrefsDropTarget::OnLeave() { } -PrefsPanel *ExtImportPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +ExtImportPrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew ExtImportPrefs(parent, winid); -} +}; diff --git a/src/prefs/ExtImportPrefs.h b/src/prefs/ExtImportPrefs.h index 5ded7040f..20b83555f 100644 --- a/src/prefs/ExtImportPrefs.h +++ b/src/prefs/ExtImportPrefs.h @@ -114,10 +114,6 @@ class ExtImportPrefs final : public PrefsPanel }; -/// A PrefsPanelFactory that creates one ExtImportPrefs panel. -class ExtImportPrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one ExtImportPrefs panel. +extern PrefsPanel::Factory ExtImportPrefsFactory; #endif diff --git a/src/prefs/GUIPrefs.cpp b/src/prefs/GUIPrefs.cpp index 5b153c371..5c60ab2d8 100644 --- a/src/prefs/GUIPrefs.cpp +++ b/src/prefs/GUIPrefs.cpp @@ -268,8 +268,9 @@ bool GUIPrefs::Commit() return true; } -PrefsPanel *GUIPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +GUIPrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew GUIPrefs(parent, winid); -} +}; diff --git a/src/prefs/GUIPrefs.h b/src/prefs/GUIPrefs.h index b4dbe48c2..b738289d5 100644 --- a/src/prefs/GUIPrefs.h +++ b/src/prefs/GUIPrefs.h @@ -53,10 +53,6 @@ class GUIPrefs final : public PrefsPanel wxArrayStringEx mRangeChoices; }; -/// A PrefsPanelFactory that creates one GUIPrefs panel. -class GUIPrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one GUIPrefs panel. +extern PrefsPanel::Factory GUIPrefsFactory; #endif diff --git a/src/prefs/ImportExportPrefs.cpp b/src/prefs/ImportExportPrefs.cpp index 07a724743..bbf0a5c91 100644 --- a/src/prefs/ImportExportPrefs.cpp +++ b/src/prefs/ImportExportPrefs.cpp @@ -128,8 +128,9 @@ bool ImportExportPrefs::Commit() return true; } -PrefsPanel *ImportExportPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +ImportExportPrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew ImportExportPrefs(parent, winid); -} +}; diff --git a/src/prefs/ImportExportPrefs.h b/src/prefs/ImportExportPrefs.h index bcdc0f7ac..223c9e2b8 100644 --- a/src/prefs/ImportExportPrefs.h +++ b/src/prefs/ImportExportPrefs.h @@ -37,10 +37,6 @@ class ImportExportPrefs final : public PrefsPanel void Populate(); }; -/// A PrefsPanelFactory that creates one ImportExportPrefs panel. -class ImportExportPrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one ImportExportPrefs panel. +extern PrefsPanel::Factory ImportExportPrefsFactory; #endif diff --git a/src/prefs/KeyConfigPrefs.cpp b/src/prefs/KeyConfigPrefs.cpp index d687d2089..269b6be4f 100644 --- a/src/prefs/KeyConfigPrefs.cpp +++ b/src/prefs/KeyConfigPrefs.cpp @@ -688,9 +688,13 @@ void KeyConfigPrefs::Cancel() return; } -PrefsPanel *KeyConfigPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +KeyConfigPrefsFactory( const CommandID &name ) { - wxASSERT(parent); // to justify safenew - auto result = safenew KeyConfigPrefs{ parent, winid, mName }; - return result; + return [=](wxWindow *parent, wxWindowID winid) + { + wxASSERT(parent); // to justify safenew + auto result = safenew KeyConfigPrefs{ parent, winid, name }; + return result; + }; } diff --git a/src/prefs/KeyConfigPrefs.h b/src/prefs/KeyConfigPrefs.h index 64513e246..8c8e236df 100644 --- a/src/prefs/KeyConfigPrefs.h +++ b/src/prefs/KeyConfigPrefs.h @@ -93,15 +93,9 @@ private: }; -/// A PrefsPanelFactory that creates one KeyConfigPrefs panel. -class KeyConfigPrefsFactory final : public PrefsPanelFactory -{ -public: - KeyConfigPrefsFactory(const CommandID &name = {}) - : mName{ name } {} - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; - -private: - CommandID mName; -}; +/// A PrefsPanel::Factory that creates one KeyConfigPrefs panel. +/// This factory can be parametrized by name, which specifies a command to be +/// focused initially +extern PrefsPanel::Factory KeyConfigPrefsFactory( + const CommandID &name = {} ); #endif diff --git a/src/prefs/LibraryPrefs.cpp b/src/prefs/LibraryPrefs.cpp index edef7ed55..8f47d3b89 100644 --- a/src/prefs/LibraryPrefs.cpp +++ b/src/prefs/LibraryPrefs.cpp @@ -267,8 +267,9 @@ bool LibraryPrefs::Commit() return true; } -PrefsPanel *LibraryPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +LibraryPrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew LibraryPrefs(parent, winid); -} +}; diff --git a/src/prefs/LibraryPrefs.h b/src/prefs/LibraryPrefs.h index e90a2f13d..2aa8fa960 100644 --- a/src/prefs/LibraryPrefs.h +++ b/src/prefs/LibraryPrefs.h @@ -50,10 +50,6 @@ class LibraryPrefs final : public PrefsPanel DECLARE_EVENT_TABLE() }; -/// A PrefsPanelFactory that creates one LibraryPrefs panel. -class LibraryPrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one LibraryPrefs panel. +extern PrefsPanel::Factory LibraryPrefsFactory; #endif diff --git a/src/prefs/MidiIOPrefs.cpp b/src/prefs/MidiIOPrefs.cpp index 5e2315a2d..43b052e0a 100644 --- a/src/prefs/MidiIOPrefs.cpp +++ b/src/prefs/MidiIOPrefs.cpp @@ -299,10 +299,11 @@ bool MidiIOPrefs::Validate() return true; } -PrefsPanel *MidiIOPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +MidiIOPrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew MidiIOPrefs(parent, winid); -} +}; #endif diff --git a/src/prefs/MidiIOPrefs.h b/src/prefs/MidiIOPrefs.h index 51d448ff4..d0627e43f 100644 --- a/src/prefs/MidiIOPrefs.h +++ b/src/prefs/MidiIOPrefs.h @@ -68,12 +68,8 @@ class MidiIOPrefs final : public PrefsPanel DECLARE_EVENT_TABLE() }; -/// A PrefsPanelFactory that creates one MidiIOPrefs panel. -class MidiIOPrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one MidiIOPrefs panel. +extern PrefsPanel::Factory MidiIOPrefsFactory; #endif #endif diff --git a/src/prefs/ModulePrefs.cpp b/src/prefs/ModulePrefs.cpp index ab5c763fc..9b315dbc2 100644 --- a/src/prefs/ModulePrefs.cpp +++ b/src/prefs/ModulePrefs.cpp @@ -180,8 +180,9 @@ void ModulePrefs::SetModuleStatus(const FilePath &fname, int iStatus){ gPrefs->Flush(); } -PrefsPanel *ModulePrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +ModulePrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew ModulePrefs(parent, winid); -} +}; diff --git a/src/prefs/ModulePrefs.h b/src/prefs/ModulePrefs.h index a20845e93..c99cd3bdd 100644 --- a/src/prefs/ModulePrefs.h +++ b/src/prefs/ModulePrefs.h @@ -55,10 +55,6 @@ class ModulePrefs final : public PrefsPanel FilePaths mPaths; }; -/// A PrefsPanelFactory that creates one ModulePrefs panel. -class ModulePrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one ModulePrefs panel. +extern PrefsPanel::Factory ModulePrefsFactory; #endif diff --git a/src/prefs/MousePrefs.cpp b/src/prefs/MousePrefs.cpp index 5eccce472..57fd4ccb6 100644 --- a/src/prefs/MousePrefs.cpp +++ b/src/prefs/MousePrefs.cpp @@ -218,8 +218,9 @@ bool MousePrefs::Commit() return true; } -PrefsPanel *MousePrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +MousePrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew MousePrefs(parent, winid); -} +}; diff --git a/src/prefs/MousePrefs.h b/src/prefs/MousePrefs.h index 318576dfe..1ccf8bd74 100644 --- a/src/prefs/MousePrefs.h +++ b/src/prefs/MousePrefs.h @@ -41,10 +41,6 @@ class MousePrefs final : public PrefsPanel wxListCtrl * mList; }; -/// A PrefsPanelFactory that creates one MousePrefs panel. -class MousePrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one MousePrefs panel. +extern PrefsPanel::Factory MousePrefsFactory; #endif diff --git a/src/prefs/PlaybackPrefs.cpp b/src/prefs/PlaybackPrefs.cpp index ab60f9013..9daef6182 100644 --- a/src/prefs/PlaybackPrefs.cpp +++ b/src/prefs/PlaybackPrefs.cpp @@ -183,9 +183,10 @@ bool PlaybackPrefs::Commit() return true; } -PrefsPanel *PlaybackPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +PlaybackPrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew PlaybackPrefs(parent, winid); -} +}; diff --git a/src/prefs/PlaybackPrefs.h b/src/prefs/PlaybackPrefs.h index d36d1e27e..0cc917c74 100644 --- a/src/prefs/PlaybackPrefs.h +++ b/src/prefs/PlaybackPrefs.h @@ -39,11 +39,7 @@ class PlaybackPrefs final : public PrefsPanel }; -/// A PrefsPanelFactory that creates one PlaybackPrefs panel. -class PlaybackPrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one PlaybackPrefs panel. +extern PrefsPanel::Factory PlaybackPrefsFactory; #endif diff --git a/src/prefs/PrefsDialog.cpp b/src/prefs/PrefsDialog.cpp index a8bf4ca7d..0b1e57ac8 100644 --- a/src/prefs/PrefsDialog.cpp +++ b/src/prefs/PrefsDialog.cpp @@ -487,72 +487,42 @@ PrefsDialog::Factories { // To do, perhaps: create this table by registration, without including each PrefsPanel // class... and thus allowing a plug-in protocol - static DevicePrefsFactory devicePrefsFactory; - static PlaybackPrefsFactory playbackPrefsFactory; - static RecordingPrefsFactory recordingPrefsFactory; -#ifdef EXPERIMENTAL_MIDI_OUT - static MidiIOPrefsFactory midiIOPrefsFactory; -#endif - static QualityPrefsFactory qualityPrefsFactory; - static GUIPrefsFactory guiPrefsFactory; - static TracksPrefsFactory tracksPrefsFactory; - static ImportExportPrefsFactory importExportPrefsFactory; - static ExtImportPrefsFactory extImportPrefsFactory; - static ProjectsPrefsFactory projectsPrefsFactory; -#if !defined(DISABLE_DYNAMIC_LOADING_FFMPEG) || !defined(DISABLE_DYNAMIC_LOADING_LAME) - static LibraryPrefsFactory libraryPrefsFactory; -#endif - // static WaveformPrefsFactory waveformPrefsFactory; - static TracksBehaviorsPrefsFactory tracksBehaviorsPrefsFactory; - static SpectrumPrefsFactory spectrumPrefsFactory; - static DirectoriesPrefsFactory directoriesPrefsFactory; - static WarningsPrefsFactory warningsPrefsFactory; - static EffectsPrefsFactory effectsPrefsFactory; -#ifdef EXPERIMENTAL_THEME_PREFS - static ThemePrefsFactory themePrefsFactory; -#endif - // static BatchPrefsFactory batchPrefsFactory; - static KeyConfigPrefsFactory keyConfigPrefsFactory; - static MousePrefsFactory mousePrefsFactory; -#ifdef EXPERIMENTAL_MODULE_PREFS - static ModulePrefsFactory modulePrefsFactory; -#endif static PrefsNode nodes[] = { - &devicePrefsFactory, - &playbackPrefsFactory, - &recordingPrefsFactory, + DevicePrefsFactory, + PlaybackPrefsFactory, + RecordingPrefsFactory, #ifdef EXPERIMENTAL_MIDI_OUT - &midiIOPrefsFactory, + MidiIOPrefsFactory, #endif - &qualityPrefsFactory, - &guiPrefsFactory, + QualityPrefsFactory, + GUIPrefsFactory, // Group other page(s) - PrefsNode(&tracksPrefsFactory, 2), - // &waveformPrefsFactory, - &tracksBehaviorsPrefsFactory, - &spectrumPrefsFactory, + PrefsNode(TracksPrefsFactory, 2), + // WaveformPrefsFactory(), + TracksBehaviorsPrefsFactory, + SpectrumPrefsFactory(), // Group one other page - PrefsNode(&importExportPrefsFactory, 1), - &extImportPrefsFactory, + PrefsNode(ImportExportPrefsFactory, 1), + ExtImportPrefsFactory, - &projectsPrefsFactory, + ProjectsPrefsFactory, #if !defined(DISABLE_DYNAMIC_LOADING_FFMPEG) || !defined(DISABLE_DYNAMIC_LOADING_LAME) - &libraryPrefsFactory, + LibraryPrefsFactory, #endif - &directoriesPrefsFactory, - &warningsPrefsFactory, - &effectsPrefsFactory, + DirectoriesPrefsFactory(), + WarningsPrefsFactory, + EffectsPrefsFactory, #ifdef EXPERIMENTAL_THEME_PREFS - &themePrefsFactory, + ThemePrefsFactory, #endif // &batchPrefsFactory, - &keyConfigPrefsFactory, - &mousePrefsFactory, + KeyConfigPrefsFactory(), + MousePrefsFactory, #ifdef EXPERIMENTAL_MODULE_PREFS - &modulePrefsFactory, + ModulePrefsFactory, #endif }; @@ -601,7 +571,7 @@ PrefsDialog::PrefsDialog it != end; ++it, ++iPage) { const PrefsNode &node = *it; - PrefsPanelFactory &factory = *node.pFactory; + const PrefsPanel::Factory &factory = node.factory; wxWindow *const w = factory(mCategories, wxID_ANY); if (stack.empty()) // Parameters are: AddPage(page, name, IsSelected, imageId). @@ -629,7 +599,7 @@ PrefsDialog::PrefsDialog // Unique page, don't show the factory const PrefsNode &node = factories[0]; - PrefsPanelFactory &factory = *node.pFactory; + const PrefsPanel::Factory &factory = node.factory; mUniquePage = factory(this, wxID_ANY); wxWindow * uniquePageWindow = S.Prop(1).AddWindow(mUniquePage, wxEXPAND); // We're not in the wxTreebook, so add the accelerator here diff --git a/src/prefs/PrefsDialog.h b/src/prefs/PrefsDialog.h index 49942c193..4945ce032 100644 --- a/src/prefs/PrefsDialog.h +++ b/src/prefs/PrefsDialog.h @@ -12,6 +12,7 @@ #ifndef __AUDACITY_PREFS_DIALOG__ #define __AUDACITY_PREFS_DIALOG__ +#include #include #include "../widgets/wxPanelWrapper.h" // to inherit #include "../Internat.h" @@ -19,7 +20,6 @@ class wxTreebook; class wxTreeEvent; class PrefsPanel; -class PrefsPanelFactory; class ShuttleGui; #ifdef __GNUC__ @@ -33,14 +33,16 @@ class PrefsDialog /* not final */ : public wxDialogWrapper public: // An array of PrefsNode specifies the tree of pages in pre-order traversal. struct PrefsNode { - PrefsPanelFactory * CONST pFactory; + using Factory = + std::function< PrefsPanel * (wxWindow *parent, wxWindowID winid) >; + Factory factory; CONST int nChildren; bool expanded; - PrefsNode(PrefsPanelFactory *pFactory_, + PrefsNode(const Factory &factory_, int nChildren_ = 0, bool expanded_ = true) - : pFactory(pFactory_), nChildren(nChildren_), expanded(expanded_) + : factory(factory_), nChildren(nChildren_), expanded(expanded_) {} }; typedef std::vector Factories; diff --git a/src/prefs/PrefsPanel.h b/src/prefs/PrefsPanel.h index fc743702f..ccde697de 100644 --- a/src/prefs/PrefsPanel.h +++ b/src/prefs/PrefsPanel.h @@ -22,17 +22,12 @@ MousePrefs, QualityPrefs, SpectrumPrefs and ThemePrefs. To actually add the new panel, edit the PrefsDialog constructor to append the panel to its list of panels. -*******************************************************************//** - -\class PrefsPanelFactory -\brief Base class for factories such as GUIPrefsFactory that produce a -PrefsPanel. - *//*******************************************************************/ #ifndef __AUDACITY_PREFS_PANEL__ #define __AUDACITY_PREFS_PANEL__ +#include #include "../widgets/wxPanelWrapper.h" // to inherit #include "../include/audacity/ComponentInterface.h" @@ -52,6 +47,11 @@ class ShuttleGui; class PrefsPanel /* not final */ : public wxPanelWrapper, ComponentInterface { public: + // \brief Type alias for factories such as GUIPrefsFactory that produce a + // PrefsPanel. + using Factory = + std::function< PrefsPanel * (wxWindow *parent, wxWindowID winid) >; + PrefsPanel(wxWindow * parent, wxWindowID winid, const wxString &title) : wxPanelWrapper(parent, winid) { @@ -86,11 +86,4 @@ class PrefsPanel /* not final */ : public wxPanelWrapper, ComponentInterface virtual void Cancel(); }; -class PrefsPanelFactory /* not final */ -{ -public: - // Precondition: parent != NULL - virtual PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) = 0; -}; - #endif diff --git a/src/prefs/ProjectsPrefs.cpp b/src/prefs/ProjectsPrefs.cpp index 61f628d20..e379039bd 100644 --- a/src/prefs/ProjectsPrefs.cpp +++ b/src/prefs/ProjectsPrefs.cpp @@ -99,8 +99,9 @@ bool ProjectsPrefs::Commit() return true; } -PrefsPanel *ProjectsPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +ProjectsPrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew ProjectsPrefs(parent, winid); -} +}; diff --git a/src/prefs/ProjectsPrefs.h b/src/prefs/ProjectsPrefs.h index 6d088d006..d5f23f5c5 100644 --- a/src/prefs/ProjectsPrefs.h +++ b/src/prefs/ProjectsPrefs.h @@ -37,10 +37,6 @@ class ProjectsPrefs final : public PrefsPanel void Populate(); }; -/// A PrefsPanelFactory that creates one ProjectPrefs panel. -class ProjectsPrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one ProjectPrefs panel. +extern PrefsPanel::Factory ProjectsPrefsFactory; #endif diff --git a/src/prefs/QualityPrefs.cpp b/src/prefs/QualityPrefs.cpp index e8e8f16d6..c3d073bde 100644 --- a/src/prefs/QualityPrefs.cpp +++ b/src/prefs/QualityPrefs.cpp @@ -277,11 +277,12 @@ bool QualityPrefs::Commit() return true; } -PrefsPanel *QualityPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +QualityPrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew QualityPrefs(parent, winid); -} +}; sampleFormat QualityPrefs::SampleFormatChoice() { diff --git a/src/prefs/QualityPrefs.h b/src/prefs/QualityPrefs.h index b8dc3af92..57ec35707 100644 --- a/src/prefs/QualityPrefs.h +++ b/src/prefs/QualityPrefs.h @@ -59,10 +59,6 @@ class QualityPrefs final : public PrefsPanel DECLARE_EVENT_TABLE() }; -/// A PrefsPanelFactory that creates one QualityPrefs panel. -class QualityPrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one QualityPrefs panel. +extern PrefsPanel::Factory QualityPrefsFactory; #endif diff --git a/src/prefs/RecordingPrefs.cpp b/src/prefs/RecordingPrefs.cpp index 643a0b775..7176eb387 100644 --- a/src/prefs/RecordingPrefs.cpp +++ b/src/prefs/RecordingPrefs.cpp @@ -305,8 +305,9 @@ void RecordingPrefs::OnToggleCustomName(wxCommandEvent & /* Evt */) mToggleCustomName->Enable(mUseCustomTrackName); } -PrefsPanel *RecordingPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +RecordingPrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew RecordingPrefs(parent, winid); -} +}; diff --git a/src/prefs/RecordingPrefs.h b/src/prefs/RecordingPrefs.h index 9349c749a..b39dae7a7 100644 --- a/src/prefs/RecordingPrefs.h +++ b/src/prefs/RecordingPrefs.h @@ -44,10 +44,6 @@ class RecordingPrefs final : public PrefsPanel DECLARE_EVENT_TABLE() }; -/// A PrefsPanelFactory that creates one RecordingPrefs panel. -class RecordingPrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one RecordingPrefs panel. +extern PrefsPanel::Factory RecordingPrefsFactory; #endif diff --git a/src/prefs/SpectrumPrefs.cpp b/src/prefs/SpectrumPrefs.cpp index 6d9df4315..3924b08cd 100644 --- a/src/prefs/SpectrumPrefs.cpp +++ b/src/prefs/SpectrumPrefs.cpp @@ -575,13 +575,12 @@ BEGIN_EVENT_TABLE(SpectrumPrefs, PrefsPanel) END_EVENT_TABLE() -SpectrumPrefsFactory::SpectrumPrefsFactory(WaveTrack *wt) -: mWt(wt) +PrefsPanel::Factory +SpectrumPrefsFactory( WaveTrack *wt ) { -} - -PrefsPanel *SpectrumPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) -{ - wxASSERT(parent); // to justify safenew - return safenew SpectrumPrefs(parent, winid, mWt); + return [=](wxWindow *parent, wxWindowID winid) + { + wxASSERT(parent); // to justify safenew + return safenew SpectrumPrefs(parent, winid, wt); + }; } diff --git a/src/prefs/SpectrumPrefs.h b/src/prefs/SpectrumPrefs.h index 2059c766a..fa64c4523 100644 --- a/src/prefs/SpectrumPrefs.h +++ b/src/prefs/SpectrumPrefs.h @@ -105,14 +105,8 @@ class SpectrumPrefs final : public PrefsPanel bool mCommitted{}; }; -/// A PrefsPanelFactory that creates one SpectrumPrefs panel. -class SpectrumPrefsFactory final : public PrefsPanelFactory -{ -public: - explicit SpectrumPrefsFactory(WaveTrack *wt = 0); - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; - -private: - WaveTrack *const mWt; -}; +/// A PrefsPanel::Factory that creates one SpectrumPrefs panel. +/// This factory can be parametrized by a single track, to change settings +/// non-globally +extern PrefsPanel::Factory SpectrumPrefsFactory( WaveTrack *wt = 0 ); #endif diff --git a/src/prefs/ThemePrefs.cpp b/src/prefs/ThemePrefs.cpp index 900ab3f37..47388aaf8 100644 --- a/src/prefs/ThemePrefs.cpp +++ b/src/prefs/ThemePrefs.cpp @@ -216,8 +216,9 @@ bool ThemePrefs::Commit() return true; } -PrefsPanel *ThemePrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +ThemePrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew ThemePrefs(parent, winid); -} +}; diff --git a/src/prefs/ThemePrefs.h b/src/prefs/ThemePrefs.h index d1f6fd938..1e0d24718 100644 --- a/src/prefs/ThemePrefs.h +++ b/src/prefs/ThemePrefs.h @@ -46,10 +46,6 @@ class ThemePrefs final : public PrefsPanel DECLARE_EVENT_TABLE() }; -/// A PrefsPanelFactory that creates one ThemePrefs panel. -class ThemePrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one ThemePrefs panel. +extern PrefsPanel::Factory ThemePrefsFactory; #endif diff --git a/src/prefs/TracksBehaviorsPrefs.cpp b/src/prefs/TracksBehaviorsPrefs.cpp index 9655380dc..88ecee536 100644 --- a/src/prefs/TracksBehaviorsPrefs.cpp +++ b/src/prefs/TracksBehaviorsPrefs.cpp @@ -134,12 +134,9 @@ bool TracksBehaviorsPrefs::Commit() return true; } -TracksBehaviorsPrefsFactory::TracksBehaviorsPrefsFactory() -{ -} - -PrefsPanel *TracksBehaviorsPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +TracksBehaviorsPrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew TracksBehaviorsPrefs(parent, winid); -} +}; diff --git a/src/prefs/TracksBehaviorsPrefs.h b/src/prefs/TracksBehaviorsPrefs.h index f5948a494..7d62e3f5a 100644 --- a/src/prefs/TracksBehaviorsPrefs.h +++ b/src/prefs/TracksBehaviorsPrefs.h @@ -43,12 +43,6 @@ class TracksBehaviorsPrefs final : public PrefsPanel wxArrayStringEx mSoloChoices; }; -/// A PrefsPanelFactory that creates one TracksBehaviorsPrefs panel. -class TracksBehaviorsPrefsFactory final : public PrefsPanelFactory -{ -public: - explicit TracksBehaviorsPrefsFactory(); - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; - -}; +/// A PrefsPanel::Factory that creates one TracksBehaviorsPrefs panel. +extern PrefsPanel::Factory TracksBehaviorsPrefsFactory; #endif diff --git a/src/prefs/TracksPrefs.cpp b/src/prefs/TracksPrefs.cpp index e5e9f7c59..f1624f19f 100644 --- a/src/prefs/TracksPrefs.cpp +++ b/src/prefs/TracksPrefs.cpp @@ -406,8 +406,9 @@ bool TracksPrefs::Commit() return true; } -PrefsPanel *TracksPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +TracksPrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew TracksPrefs(parent, winid); -} +}; diff --git a/src/prefs/TracksPrefs.h b/src/prefs/TracksPrefs.h index 37e4ffe0c..d5c3c1e94 100644 --- a/src/prefs/TracksPrefs.h +++ b/src/prefs/TracksPrefs.h @@ -54,10 +54,6 @@ class TracksPrefs final : public PrefsPanel static int iPreferencePinned; }; -/// A PrefsPanelFactory that creates one TracksPrefs panel. -class TracksPrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one TracksPrefs panel. +extern PrefsPanel::Factory TracksPrefsFactory; #endif diff --git a/src/prefs/WarningsPrefs.cpp b/src/prefs/WarningsPrefs.cpp index 5e35603b0..19424d741 100644 --- a/src/prefs/WarningsPrefs.cpp +++ b/src/prefs/WarningsPrefs.cpp @@ -106,8 +106,9 @@ bool WarningsPrefs::Commit() return true; } -PrefsPanel *WarningsPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) +PrefsPanel::Factory +WarningsPrefsFactory = [](wxWindow *parent, wxWindowID winid) { wxASSERT(parent); // to justify safenew return safenew WarningsPrefs(parent, winid); -} +}; diff --git a/src/prefs/WarningsPrefs.h b/src/prefs/WarningsPrefs.h index f92223bc3..36e8e402d 100644 --- a/src/prefs/WarningsPrefs.h +++ b/src/prefs/WarningsPrefs.h @@ -37,10 +37,6 @@ class WarningsPrefs final : public PrefsPanel void PopulateOrExchange(ShuttleGui & S) override; }; -/// A PrefsPanelFactory that creates one WarningPrefs panel. -class WarningsPrefsFactory final : public PrefsPanelFactory -{ -public: - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; -}; +/// A PrefsPanel::Factory that creates one WarningPrefs panel. +extern PrefsPanel::Factory WarningsPrefsFactory; #endif diff --git a/src/prefs/WaveformPrefs.cpp b/src/prefs/WaveformPrefs.cpp index 5bd350bde..d5bc0b1e8 100644 --- a/src/prefs/WaveformPrefs.cpp +++ b/src/prefs/WaveformPrefs.cpp @@ -247,13 +247,12 @@ EVT_CHOICE(ID_RANGE, WaveformPrefs::OnControl) EVT_CHECKBOX(ID_DEFAULTS, WaveformPrefs::OnDefaults) END_EVENT_TABLE() -WaveformPrefsFactory::WaveformPrefsFactory(WaveTrack *wt) -: mWt(wt) +PrefsPanel::Factory +WaveformPrefsFactory(WaveTrack *wt) { -} - -PrefsPanel *WaveformPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) -{ - wxASSERT(parent); // to justify safenew - return safenew WaveformPrefs(parent, winid, mWt); + return [=](wxWindow *parent, wxWindowID winid) + { + wxASSERT(parent); // to justify safenew + return safenew WaveformPrefs(parent, winid, wt); + }; } diff --git a/src/prefs/WaveformPrefs.h b/src/prefs/WaveformPrefs.h index 3f98f0d6b..b79f6122a 100644 --- a/src/prefs/WaveformPrefs.h +++ b/src/prefs/WaveformPrefs.h @@ -63,14 +63,8 @@ private: bool mPopulating; }; -/// A PrefsPanelFactory that creates one WaveformPrefs panel. -class WaveformPrefsFactory final : public PrefsPanelFactory -{ -public: - explicit WaveformPrefsFactory(WaveTrack *wt = 0); - PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override; - -private: - WaveTrack *const mWt; -}; +/// A PrefsPanel::Factory that creates one WaveformPrefs panel. +/// This factory can be parametrized by a single track, to change settings +/// non-globally +extern PrefsPanel::Factory WaveformPrefsFactory(WaveTrack *wt); #endif diff --git a/src/tracks/playabletrack/wavetrack/ui/WaveTrackControls.cpp b/src/tracks/playabletrack/wavetrack/ui/WaveTrackControls.cpp index fc8592d4a..67579d9e1 100644 --- a/src/tracks/playabletrack/wavetrack/ui/WaveTrackControls.cpp +++ b/src/tracks/playabletrack/wavetrack/ui/WaveTrackControls.cpp @@ -781,13 +781,10 @@ void WaveTrackMenuTable::OnSpectrogramSettings(wxCommandEvent &) } WaveTrack *const pTrack = static_cast(mpData->pTrack); - // WaveformPrefsFactory waveformFactory(pTrack); - // TracksBehaviorsPrefsFactory tracksBehaviorsFactory(); - SpectrumPrefsFactory spectrumFactory(pTrack); PrefsDialog::Factories factories; - // factories.push_back(&waveformFactory); - factories.push_back(&spectrumFactory); + // factories.push_back(WaveformPrefsFactory( pTrack )); + factories.push_back(SpectrumPrefsFactory( pTrack )); const int page = // (pTrack->GetDisplay() == WaveTrack::Spectrum) ? 1 : 0;