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

PrefsPanel::Factory is a specialization of std::function...

... We don't need to define a class for it
This commit is contained in:
Paul Licameli 2019-01-13 20:55:52 -05:00
parent 8117ca8823
commit bf005c0dec
50 changed files with 175 additions and 290 deletions

View File

@ -1829,9 +1829,8 @@ bool AudacityApp::InitTempDir()
} }
// Only want one page of the preferences // Only want one page of the preferences
DirectoriesPrefsFactory directoriesPrefsFactory;
PrefsDialog::Factories factories; PrefsDialog::Factories factories;
factories.push_back(&directoriesPrefsFactory); factories.push_back(DirectoriesPrefsFactory());
GlobalPrefsDialog dialog(NULL, factories); GlobalPrefsDialog dialog(NULL, factories);
dialog.ShowModal(); dialog.ShowModal();

View File

@ -1555,9 +1555,8 @@ bool CommandManager::HandleMenuID(int id, CommandFlag flags, CommandMask mask)
#ifdef EXPERIMENTAL_EASY_CHANGE_KEY_BINDINGS #ifdef EXPERIMENTAL_EASY_CHANGE_KEY_BINDINGS
if (::wxGetMouseState().ShiftDown()) { if (::wxGetMouseState().ShiftDown()) {
// Only want one page of the preferences // Only want one page of the preferences
KeyConfigPrefsFactory keyConfigPrefsFactory{ entry->name };
PrefsDialog::Factories factories; PrefsDialog::Factories factories;
factories.push_back(&keyConfigPrefsFactory); factories.push_back(KeyConfigPrefsFactory( entry->name ));
GlobalPrefsDialog dialog(GetActiveProject(), factories); GlobalPrefsDialog dialog(GetActiveProject(), factories);
dialog.ShowModal(); dialog.ShowModal();
MenuCreator::RebuildAllMenuBars(); MenuCreator::RebuildAllMenuBars();

View File

@ -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 wxASSERT(parent); // to justify safenew
return safenew BatchPrefs(parent, winid); return safenew BatchPrefs(parent, winid);
} };

View File

@ -39,10 +39,6 @@ private:
}; };
/// A PrefsPanelFactory that creates one BatchPrefs panel. /// A PrefsPanel::Factory that creates one BatchPrefs panel.
class BatchPrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory BatchPrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -420,8 +420,10 @@ bool DevicePrefs::Commit()
return true; return true;
} }
PrefsPanel *DevicePrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
DevicePrefsFactory = [](wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew DevicePrefs(parent, winid); return safenew DevicePrefs(parent, winid);
} };

View File

@ -57,11 +57,7 @@ class DevicePrefs final : public PrefsPanel
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
/// A PrefsPanelFactory that creates one DevicePrefs panel. /// A PrefsPanel::Factory that creates one DevicePrefs panel.
class DevicePrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory DevicePrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -287,8 +287,11 @@ bool DirectoriesPrefs::Commit()
return true; return true;
} }
PrefsPanel *DirectoriesPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
{ DirectoriesPrefsFactory() {
wxASSERT(parent); // to justify safenew return [](wxWindow *parent, wxWindowID winid)
return safenew DirectoriesPrefs(parent, winid); {
wxASSERT(parent); // to justify safenew
return safenew DirectoriesPrefs(parent, winid);
};
} }

View File

@ -44,10 +44,7 @@ class DirectoriesPrefs final : public PrefsPanel
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
/// A PrefsPanelFactory that creates one DirectoriesPrefs panel. /// A PrefsPanel::Factory that creates one DirectoriesPrefs panel.
class DirectoriesPrefsFactory final : public PrefsPanelFactory /// This one is used not only in the Preferences command.
{ extern PrefsPanel::Factory DirectoriesPrefsFactory();
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -200,8 +200,9 @@ bool EffectsPrefs::Commit()
return true; return true;
} }
PrefsPanel *EffectsPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
EffectsPrefsFactory = [](wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew EffectsPrefs(parent, winid); return safenew EffectsPrefs(parent, winid);
} };

View File

@ -37,10 +37,6 @@ class EffectsPrefs final : public PrefsPanel
void Populate(); void Populate();
}; };
/// A PrefsPanelFactory that creates one EffectsPrefs panel. /// A PrefsPanel::Factory that creates one EffectsPrefs panel.
class EffectsPrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory EffectsPrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -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 wxASSERT(parent); // to justify safenew
return safenew ExtImportPrefs(parent, winid); return safenew ExtImportPrefs(parent, winid);
} };

View File

@ -114,10 +114,6 @@ class ExtImportPrefs final : public PrefsPanel
}; };
/// A PrefsPanelFactory that creates one ExtImportPrefs panel. /// A PrefsPanel::Factory that creates one ExtImportPrefs panel.
class ExtImportPrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory ExtImportPrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -268,8 +268,9 @@ bool GUIPrefs::Commit()
return true; return true;
} }
PrefsPanel *GUIPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
GUIPrefsFactory = [](wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew GUIPrefs(parent, winid); return safenew GUIPrefs(parent, winid);
} };

View File

@ -53,10 +53,6 @@ class GUIPrefs final : public PrefsPanel
wxArrayStringEx mRangeChoices; wxArrayStringEx mRangeChoices;
}; };
/// A PrefsPanelFactory that creates one GUIPrefs panel. /// A PrefsPanel::Factory that creates one GUIPrefs panel.
class GUIPrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory GUIPrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -128,8 +128,9 @@ bool ImportExportPrefs::Commit()
return true; return true;
} }
PrefsPanel *ImportExportPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
ImportExportPrefsFactory = [](wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew ImportExportPrefs(parent, winid); return safenew ImportExportPrefs(parent, winid);
} };

View File

@ -37,10 +37,6 @@ class ImportExportPrefs final : public PrefsPanel
void Populate(); void Populate();
}; };
/// A PrefsPanelFactory that creates one ImportExportPrefs panel. /// A PrefsPanel::Factory that creates one ImportExportPrefs panel.
class ImportExportPrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory ImportExportPrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

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

View File

@ -93,15 +93,9 @@ private:
}; };
/// A PrefsPanelFactory that creates one KeyConfigPrefs panel. /// A PrefsPanel::Factory that creates one KeyConfigPrefs panel.
class KeyConfigPrefsFactory final : public PrefsPanelFactory /// This factory can be parametrized by name, which specifies a command to be
{ /// focused initially
public: extern PrefsPanel::Factory KeyConfigPrefsFactory(
KeyConfigPrefsFactory(const CommandID &name = {}) const CommandID &name = {} );
: mName{ name } {}
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
private:
CommandID mName;
};
#endif #endif

View File

@ -267,8 +267,9 @@ bool LibraryPrefs::Commit()
return true; return true;
} }
PrefsPanel *LibraryPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
LibraryPrefsFactory = [](wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew LibraryPrefs(parent, winid); return safenew LibraryPrefs(parent, winid);
} };

View File

@ -50,10 +50,6 @@ class LibraryPrefs final : public PrefsPanel
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
/// A PrefsPanelFactory that creates one LibraryPrefs panel. /// A PrefsPanel::Factory that creates one LibraryPrefs panel.
class LibraryPrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory LibraryPrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -299,10 +299,11 @@ bool MidiIOPrefs::Validate()
return true; return true;
} }
PrefsPanel *MidiIOPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
MidiIOPrefsFactory = [](wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew MidiIOPrefs(parent, winid); return safenew MidiIOPrefs(parent, winid);
} };
#endif #endif

View File

@ -68,12 +68,8 @@ class MidiIOPrefs final : public PrefsPanel
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
/// A PrefsPanelFactory that creates one MidiIOPrefs panel. /// A PrefsPanel::Factory that creates one MidiIOPrefs panel.
class MidiIOPrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory MidiIOPrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif
#endif #endif

View File

@ -180,8 +180,9 @@ void ModulePrefs::SetModuleStatus(const FilePath &fname, int iStatus){
gPrefs->Flush(); gPrefs->Flush();
} }
PrefsPanel *ModulePrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
ModulePrefsFactory = [](wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew ModulePrefs(parent, winid); return safenew ModulePrefs(parent, winid);
} };

View File

@ -55,10 +55,6 @@ class ModulePrefs final : public PrefsPanel
FilePaths mPaths; FilePaths mPaths;
}; };
/// A PrefsPanelFactory that creates one ModulePrefs panel. /// A PrefsPanel::Factory that creates one ModulePrefs panel.
class ModulePrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory ModulePrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -218,8 +218,9 @@ bool MousePrefs::Commit()
return true; return true;
} }
PrefsPanel *MousePrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
MousePrefsFactory = [](wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew MousePrefs(parent, winid); return safenew MousePrefs(parent, winid);
} };

View File

@ -41,10 +41,6 @@ class MousePrefs final : public PrefsPanel
wxListCtrl * mList; wxListCtrl * mList;
}; };
/// A PrefsPanelFactory that creates one MousePrefs panel. /// A PrefsPanel::Factory that creates one MousePrefs panel.
class MousePrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory MousePrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

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

View File

@ -39,11 +39,7 @@ class PlaybackPrefs final : public PrefsPanel
}; };
/// A PrefsPanelFactory that creates one PlaybackPrefs panel. /// A PrefsPanel::Factory that creates one PlaybackPrefs panel.
class PlaybackPrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory PlaybackPrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -487,72 +487,42 @@ PrefsDialog::Factories
{ {
// To do, perhaps: create this table by registration, without including each PrefsPanel // To do, perhaps: create this table by registration, without including each PrefsPanel
// class... and thus allowing a plug-in protocol // 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[] = { static PrefsNode nodes[] = {
&devicePrefsFactory, DevicePrefsFactory,
&playbackPrefsFactory, PlaybackPrefsFactory,
&recordingPrefsFactory, RecordingPrefsFactory,
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
&midiIOPrefsFactory, MidiIOPrefsFactory,
#endif #endif
&qualityPrefsFactory, QualityPrefsFactory,
&guiPrefsFactory, GUIPrefsFactory,
// Group other page(s) // Group other page(s)
PrefsNode(&tracksPrefsFactory, 2), PrefsNode(TracksPrefsFactory, 2),
// &waveformPrefsFactory, // WaveformPrefsFactory(),
&tracksBehaviorsPrefsFactory, TracksBehaviorsPrefsFactory,
&spectrumPrefsFactory, SpectrumPrefsFactory(),
// Group one other page // Group one other page
PrefsNode(&importExportPrefsFactory, 1), PrefsNode(ImportExportPrefsFactory, 1),
&extImportPrefsFactory, ExtImportPrefsFactory,
&projectsPrefsFactory, ProjectsPrefsFactory,
#if !defined(DISABLE_DYNAMIC_LOADING_FFMPEG) || !defined(DISABLE_DYNAMIC_LOADING_LAME) #if !defined(DISABLE_DYNAMIC_LOADING_FFMPEG) || !defined(DISABLE_DYNAMIC_LOADING_LAME)
&libraryPrefsFactory, LibraryPrefsFactory,
#endif #endif
&directoriesPrefsFactory, DirectoriesPrefsFactory(),
&warningsPrefsFactory, WarningsPrefsFactory,
&effectsPrefsFactory, EffectsPrefsFactory,
#ifdef EXPERIMENTAL_THEME_PREFS #ifdef EXPERIMENTAL_THEME_PREFS
&themePrefsFactory, ThemePrefsFactory,
#endif #endif
// &batchPrefsFactory, // &batchPrefsFactory,
&keyConfigPrefsFactory, KeyConfigPrefsFactory(),
&mousePrefsFactory, MousePrefsFactory,
#ifdef EXPERIMENTAL_MODULE_PREFS #ifdef EXPERIMENTAL_MODULE_PREFS
&modulePrefsFactory, ModulePrefsFactory,
#endif #endif
}; };
@ -601,7 +571,7 @@ PrefsDialog::PrefsDialog
it != end; ++it, ++iPage) it != end; ++it, ++iPage)
{ {
const PrefsNode &node = *it; const PrefsNode &node = *it;
PrefsPanelFactory &factory = *node.pFactory; const PrefsPanel::Factory &factory = node.factory;
wxWindow *const w = factory(mCategories, wxID_ANY); wxWindow *const w = factory(mCategories, wxID_ANY);
if (stack.empty()) if (stack.empty())
// Parameters are: AddPage(page, name, IsSelected, imageId). // Parameters are: AddPage(page, name, IsSelected, imageId).
@ -629,7 +599,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];
PrefsPanelFactory &factory = *node.pFactory; const PrefsPanel::Factory &factory = node.factory;
mUniquePage = factory(this, wxID_ANY); mUniquePage = factory(this, wxID_ANY);
wxWindow * uniquePageWindow = S.Prop(1).AddWindow(mUniquePage, wxEXPAND); wxWindow * uniquePageWindow = S.Prop(1).AddWindow(mUniquePage, wxEXPAND);
// We're not in the wxTreebook, so add the accelerator here // We're not in the wxTreebook, so add the accelerator here

View File

@ -12,6 +12,7 @@
#ifndef __AUDACITY_PREFS_DIALOG__ #ifndef __AUDACITY_PREFS_DIALOG__
#define __AUDACITY_PREFS_DIALOG__ #define __AUDACITY_PREFS_DIALOG__
#include <functional>
#include <vector> #include <vector>
#include "../widgets/wxPanelWrapper.h" // to inherit #include "../widgets/wxPanelWrapper.h" // to inherit
#include "../Internat.h" #include "../Internat.h"
@ -19,7 +20,6 @@
class wxTreebook; class wxTreebook;
class wxTreeEvent; class wxTreeEvent;
class PrefsPanel; class PrefsPanel;
class PrefsPanelFactory;
class ShuttleGui; class ShuttleGui;
#ifdef __GNUC__ #ifdef __GNUC__
@ -33,14 +33,16 @@ 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 {
PrefsPanelFactory * CONST pFactory; using Factory =
std::function< PrefsPanel * (wxWindow *parent, wxWindowID winid) >;
Factory factory;
CONST int nChildren; CONST int nChildren;
bool expanded; bool expanded;
PrefsNode(PrefsPanelFactory *pFactory_, PrefsNode(const Factory &factory_,
int nChildren_ = 0, int nChildren_ = 0,
bool expanded_ = true) bool expanded_ = true)
: pFactory(pFactory_), nChildren(nChildren_), expanded(expanded_) : factory(factory_), nChildren(nChildren_), expanded(expanded_)
{} {}
}; };
typedef std::vector<PrefsNode> Factories; typedef std::vector<PrefsNode> Factories;

View File

@ -22,17 +22,12 @@ MousePrefs, QualityPrefs, SpectrumPrefs and ThemePrefs.
To actually add the new panel, edit the PrefsDialog constructor To actually add the new panel, edit the PrefsDialog constructor
to append the panel to its list of panels. 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__ #ifndef __AUDACITY_PREFS_PANEL__
#define __AUDACITY_PREFS_PANEL__ #define __AUDACITY_PREFS_PANEL__
#include <functional>
#include "../widgets/wxPanelWrapper.h" // to inherit #include "../widgets/wxPanelWrapper.h" // to inherit
#include "../include/audacity/ComponentInterface.h" #include "../include/audacity/ComponentInterface.h"
@ -52,6 +47,11 @@ class ShuttleGui;
class PrefsPanel /* not final */ : public wxPanelWrapper, ComponentInterface class PrefsPanel /* not final */ : public wxPanelWrapper, ComponentInterface
{ {
public: 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) PrefsPanel(wxWindow * parent, wxWindowID winid, const wxString &title)
: wxPanelWrapper(parent, winid) : wxPanelWrapper(parent, winid)
{ {
@ -86,11 +86,4 @@ class PrefsPanel /* not final */ : public wxPanelWrapper, ComponentInterface
virtual void Cancel(); virtual void Cancel();
}; };
class PrefsPanelFactory /* not final */
{
public:
// Precondition: parent != NULL
virtual PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) = 0;
};
#endif #endif

View File

@ -99,8 +99,9 @@ bool ProjectsPrefs::Commit()
return true; return true;
} }
PrefsPanel *ProjectsPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
ProjectsPrefsFactory = [](wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew ProjectsPrefs(parent, winid); return safenew ProjectsPrefs(parent, winid);
} };

View File

@ -37,10 +37,6 @@ class ProjectsPrefs final : public PrefsPanel
void Populate(); void Populate();
}; };
/// A PrefsPanelFactory that creates one ProjectPrefs panel. /// A PrefsPanel::Factory that creates one ProjectPrefs panel.
class ProjectsPrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory ProjectsPrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -277,11 +277,12 @@ bool QualityPrefs::Commit()
return true; return true;
} }
PrefsPanel *QualityPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
QualityPrefsFactory = [](wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew QualityPrefs(parent, winid); return safenew QualityPrefs(parent, winid);
} };
sampleFormat QualityPrefs::SampleFormatChoice() sampleFormat QualityPrefs::SampleFormatChoice()
{ {

View File

@ -59,10 +59,6 @@ class QualityPrefs final : public PrefsPanel
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
/// A PrefsPanelFactory that creates one QualityPrefs panel. /// A PrefsPanel::Factory that creates one QualityPrefs panel.
class QualityPrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory QualityPrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -305,8 +305,9 @@ void RecordingPrefs::OnToggleCustomName(wxCommandEvent & /* Evt */)
mToggleCustomName->Enable(mUseCustomTrackName); mToggleCustomName->Enable(mUseCustomTrackName);
} }
PrefsPanel *RecordingPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
RecordingPrefsFactory = [](wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew RecordingPrefs(parent, winid); return safenew RecordingPrefs(parent, winid);
} };

View File

@ -44,10 +44,6 @@ class RecordingPrefs final : public PrefsPanel
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
/// A PrefsPanelFactory that creates one RecordingPrefs panel. /// A PrefsPanel::Factory that creates one RecordingPrefs panel.
class RecordingPrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory RecordingPrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -575,13 +575,12 @@ BEGIN_EVENT_TABLE(SpectrumPrefs, PrefsPanel)
END_EVENT_TABLE() END_EVENT_TABLE()
SpectrumPrefsFactory::SpectrumPrefsFactory(WaveTrack *wt) PrefsPanel::Factory
: mWt(wt) SpectrumPrefsFactory( WaveTrack *wt )
{ {
} return [=](wxWindow *parent, wxWindowID winid)
{
PrefsPanel *SpectrumPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) wxASSERT(parent); // to justify safenew
{ return safenew SpectrumPrefs(parent, winid, wt);
wxASSERT(parent); // to justify safenew };
return safenew SpectrumPrefs(parent, winid, mWt);
} }

View File

@ -105,14 +105,8 @@ class SpectrumPrefs final : public PrefsPanel
bool mCommitted{}; bool mCommitted{};
}; };
/// A PrefsPanelFactory that creates one SpectrumPrefs panel. /// A PrefsPanel::Factory that creates one SpectrumPrefs panel.
class SpectrumPrefsFactory final : public PrefsPanelFactory /// This factory can be parametrized by a single track, to change settings
{ /// non-globally
public: extern PrefsPanel::Factory SpectrumPrefsFactory( WaveTrack *wt = 0 );
explicit SpectrumPrefsFactory(WaveTrack *wt = 0);
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
private:
WaveTrack *const mWt;
};
#endif #endif

View File

@ -216,8 +216,9 @@ bool ThemePrefs::Commit()
return true; return true;
} }
PrefsPanel *ThemePrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
ThemePrefsFactory = [](wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew ThemePrefs(parent, winid); return safenew ThemePrefs(parent, winid);
} };

View File

@ -46,10 +46,6 @@ class ThemePrefs final : public PrefsPanel
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
/// A PrefsPanelFactory that creates one ThemePrefs panel. /// A PrefsPanel::Factory that creates one ThemePrefs panel.
class ThemePrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory ThemePrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -134,12 +134,9 @@ bool TracksBehaviorsPrefs::Commit()
return true; return true;
} }
TracksBehaviorsPrefsFactory::TracksBehaviorsPrefsFactory() PrefsPanel::Factory
{ TracksBehaviorsPrefsFactory = [](wxWindow *parent, wxWindowID winid)
}
PrefsPanel *TracksBehaviorsPrefsFactory::operator () (wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew TracksBehaviorsPrefs(parent, winid); return safenew TracksBehaviorsPrefs(parent, winid);
} };

View File

@ -43,12 +43,6 @@ class TracksBehaviorsPrefs final : public PrefsPanel
wxArrayStringEx mSoloChoices; wxArrayStringEx mSoloChoices;
}; };
/// A PrefsPanelFactory that creates one TracksBehaviorsPrefs panel. /// A PrefsPanel::Factory that creates one TracksBehaviorsPrefs panel.
class TracksBehaviorsPrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory TracksBehaviorsPrefsFactory;
{
public:
explicit TracksBehaviorsPrefsFactory();
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -406,8 +406,9 @@ bool TracksPrefs::Commit()
return true; return true;
} }
PrefsPanel *TracksPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
TracksPrefsFactory = [](wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew TracksPrefs(parent, winid); return safenew TracksPrefs(parent, winid);
} };

View File

@ -54,10 +54,6 @@ class TracksPrefs final : public PrefsPanel
static int iPreferencePinned; static int iPreferencePinned;
}; };
/// A PrefsPanelFactory that creates one TracksPrefs panel. /// A PrefsPanel::Factory that creates one TracksPrefs panel.
class TracksPrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory TracksPrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -106,8 +106,9 @@ bool WarningsPrefs::Commit()
return true; return true;
} }
PrefsPanel *WarningsPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) PrefsPanel::Factory
WarningsPrefsFactory = [](wxWindow *parent, wxWindowID winid)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew
return safenew WarningsPrefs(parent, winid); return safenew WarningsPrefs(parent, winid);
} };

View File

@ -37,10 +37,6 @@ class WarningsPrefs final : public PrefsPanel
void PopulateOrExchange(ShuttleGui & S) override; void PopulateOrExchange(ShuttleGui & S) override;
}; };
/// A PrefsPanelFactory that creates one WarningPrefs panel. /// A PrefsPanel::Factory that creates one WarningPrefs panel.
class WarningsPrefsFactory final : public PrefsPanelFactory extern PrefsPanel::Factory WarningsPrefsFactory;
{
public:
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
};
#endif #endif

View File

@ -247,13 +247,12 @@ EVT_CHOICE(ID_RANGE, WaveformPrefs::OnControl)
EVT_CHECKBOX(ID_DEFAULTS, WaveformPrefs::OnDefaults) EVT_CHECKBOX(ID_DEFAULTS, WaveformPrefs::OnDefaults)
END_EVENT_TABLE() END_EVENT_TABLE()
WaveformPrefsFactory::WaveformPrefsFactory(WaveTrack *wt) PrefsPanel::Factory
: mWt(wt) WaveformPrefsFactory(WaveTrack *wt)
{ {
} return [=](wxWindow *parent, wxWindowID winid)
{
PrefsPanel *WaveformPrefsFactory::operator () (wxWindow *parent, wxWindowID winid) wxASSERT(parent); // to justify safenew
{ return safenew WaveformPrefs(parent, winid, wt);
wxASSERT(parent); // to justify safenew };
return safenew WaveformPrefs(parent, winid, mWt);
} }

View File

@ -63,14 +63,8 @@ private:
bool mPopulating; bool mPopulating;
}; };
/// A PrefsPanelFactory that creates one WaveformPrefs panel. /// A PrefsPanel::Factory that creates one WaveformPrefs panel.
class WaveformPrefsFactory final : public PrefsPanelFactory /// This factory can be parametrized by a single track, to change settings
{ /// non-globally
public: extern PrefsPanel::Factory WaveformPrefsFactory(WaveTrack *wt);
explicit WaveformPrefsFactory(WaveTrack *wt = 0);
PrefsPanel *operator () (wxWindow *parent, wxWindowID winid) override;
private:
WaveTrack *const mWt;
};
#endif #endif

View File

@ -781,13 +781,10 @@ void WaveTrackMenuTable::OnSpectrogramSettings(wxCommandEvent &)
} }
WaveTrack *const pTrack = static_cast<WaveTrack*>(mpData->pTrack); WaveTrack *const pTrack = static_cast<WaveTrack*>(mpData->pTrack);
// WaveformPrefsFactory waveformFactory(pTrack);
// TracksBehaviorsPrefsFactory tracksBehaviorsFactory();
SpectrumPrefsFactory spectrumFactory(pTrack);
PrefsDialog::Factories factories; PrefsDialog::Factories factories;
// factories.push_back(&waveformFactory); // factories.push_back(WaveformPrefsFactory( pTrack ));
factories.push_back(&spectrumFactory); factories.push_back(SpectrumPrefsFactory( pTrack ));
const int page = const int page =
// (pTrack->GetDisplay() == WaveTrack::Spectrum) ? 1 : // (pTrack->GetDisplay() == WaveTrack::Spectrum) ? 1 :
0; 0;