diff --git a/src/prefs/BatchPrefs.cpp b/src/prefs/BatchPrefs.cpp index 535f5c6a9..6a03afcfd 100644 --- a/src/prefs/BatchPrefs.cpp +++ b/src/prefs/BatchPrefs.cpp @@ -97,12 +97,16 @@ BatchPrefs::~BatchPrefs() #if 0 namespace{ -PrefsPanel::Registration sAttachment{ 190, +PrefsPanel::Registration sAttachment{ "Batch", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew return safenew BatchPrefs(parent, winid); - } + }, + false, + // Register with an explicit ordering hint because this one is + // only conditionally compiled + { "", { Registry::OrderingHint::Before, "KeyConfig" } } }; } #endif diff --git a/src/prefs/DevicePrefs.cpp b/src/prefs/DevicePrefs.cpp index 8ecc90c42..5a850bd98 100644 --- a/src/prefs/DevicePrefs.cpp +++ b/src/prefs/DevicePrefs.cpp @@ -423,7 +423,7 @@ bool DevicePrefs::Commit() } namespace{ -PrefsPanel::Registration sAttachment{ 10, +PrefsPanel::Registration sAttachment{ "Device", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew diff --git a/src/prefs/DirectoriesPrefs.cpp b/src/prefs/DirectoriesPrefs.cpp index 909058b62..af0be75a3 100644 --- a/src/prefs/DirectoriesPrefs.cpp +++ b/src/prefs/DirectoriesPrefs.cpp @@ -300,7 +300,7 @@ DirectoriesPrefsFactory() { } namespace{ -PrefsPanel::Registration sAttachment{ 150, +PrefsPanel::Registration sAttachment{ "Directories", DirectoriesPrefsFactory() }; }; diff --git a/src/prefs/EffectsPrefs.cpp b/src/prefs/EffectsPrefs.cpp index f632e64b7..088b4062e 100644 --- a/src/prefs/EffectsPrefs.cpp +++ b/src/prefs/EffectsPrefs.cpp @@ -251,7 +251,7 @@ bool EffectsPrefs::Commit() } namespace{ -PrefsPanel::Registration sAttachment{ 170, +PrefsPanel::Registration sAttachment{ "Effects", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew diff --git a/src/prefs/ExtImportPrefs.cpp b/src/prefs/ExtImportPrefs.cpp index 964e468c1..28a92f484 100644 --- a/src/prefs/ExtImportPrefs.cpp +++ b/src/prefs/ExtImportPrefs.cpp @@ -827,11 +827,14 @@ void ExtImportPrefsDropTarget::OnLeave() } namespace{ -PrefsPanel::Registration sAttachment{ 120, +PrefsPanel::Registration sAttachment{ "ExtImport", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew return safenew ExtImportPrefs(parent, winid); - } + }, + false, + // Place as a lower level of the tree of pages: + { "ImportExport" } }; } diff --git a/src/prefs/GUIPrefs.cpp b/src/prefs/GUIPrefs.cpp index 0f0fc684a..b30818abc 100644 --- a/src/prefs/GUIPrefs.cpp +++ b/src/prefs/GUIPrefs.cpp @@ -382,7 +382,7 @@ int ShowClippingPrefsID() } namespace{ -PrefsPanel::Registration sAttachment{ 60, +PrefsPanel::Registration sAttachment{ "GUI", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew diff --git a/src/prefs/ImportExportPrefs.cpp b/src/prefs/ImportExportPrefs.cpp index 0f16a5109..33980f1e3 100644 --- a/src/prefs/ImportExportPrefs.cpp +++ b/src/prefs/ImportExportPrefs.cpp @@ -150,12 +150,11 @@ bool ImportExportPrefs::Commit() } namespace{ -PrefsPanel::Registration sAttachment{ 110, +PrefsPanel::Registration sAttachment{ "ImportExport", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew return safenew ImportExportPrefs(parent, winid); - }, - 1 + } }; } diff --git a/src/prefs/KeyConfigPrefs.cpp b/src/prefs/KeyConfigPrefs.cpp index c2be8db85..b2a08b95a 100644 --- a/src/prefs/KeyConfigPrefs.cpp +++ b/src/prefs/KeyConfigPrefs.cpp @@ -890,7 +890,7 @@ KeyConfigPrefsFactory( const CommandID &name ) }; } namespace{ -PrefsPanel::Registration sAttachment{ 200, +PrefsPanel::Registration sAttachment{ "KeyConfig", KeyConfigPrefsFactory() }; } diff --git a/src/prefs/LibraryPrefs.cpp b/src/prefs/LibraryPrefs.cpp index 83cc8c063..fdb104169 100644 --- a/src/prefs/LibraryPrefs.cpp +++ b/src/prefs/LibraryPrefs.cpp @@ -263,12 +263,16 @@ bool LibraryPrefs::Commit() #if !defined(DISABLE_DYNAMIC_LOADING_FFMPEG) || !defined(DISABLE_DYNAMIC_LOADING_LAME) namespace{ -PrefsPanel::Registration sAttachment{ 140, +PrefsPanel::Registration sAttachment{ "Library", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew return safenew LibraryPrefs(parent, winid); - } + }, + false, + // Register with an explicit ordering hint because this one is + // only conditionally compiled + { "", { Registry::OrderingHint::Before, "Directories" } } }; } #endif diff --git a/src/prefs/MidiIOPrefs.cpp b/src/prefs/MidiIOPrefs.cpp index ddd854bbf..1a8ec49d4 100644 --- a/src/prefs/MidiIOPrefs.cpp +++ b/src/prefs/MidiIOPrefs.cpp @@ -303,12 +303,16 @@ bool MidiIOPrefs::Validate() #ifdef EXPERIMENTAL_MIDI_OUT namespace{ -PrefsPanel::Registration sAttachment{ 40, +PrefsPanel::Registration sAttachment{ "MidiIO", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew return safenew MidiIOPrefs(parent, winid); - } + }, + false, + // Register with an explicit ordering hint because this one is + // only conditionally compiled + { "", { Registry::OrderingHint::After, "Recording" } } }; } #endif diff --git a/src/prefs/ModulePrefs.cpp b/src/prefs/ModulePrefs.cpp index 604159b40..8f5dae341 100644 --- a/src/prefs/ModulePrefs.cpp +++ b/src/prefs/ModulePrefs.cpp @@ -191,12 +191,16 @@ void ModulePrefs::SetModuleStatus(const FilePath &fname, int iStatus){ #ifdef EXPERIMENTAL_MODULE_PREFS namespace{ -PrefsPanel::Registration sAttachment{ 220, +PrefsPanel::Registration sAttachment{ "Module", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew return safenew ModulePrefs(parent, winid); - } + }, + false, + // Register with an explicit ordering hint because this one is + // only conditionally compiled + { "", { Registry::OrderingHint::After, "Mouse" } } }; } #endif diff --git a/src/prefs/MousePrefs.cpp b/src/prefs/MousePrefs.cpp index 705c379c2..cd72eb7c0 100644 --- a/src/prefs/MousePrefs.cpp +++ b/src/prefs/MousePrefs.cpp @@ -223,7 +223,7 @@ bool MousePrefs::Commit() } namespace{ -PrefsPanel::Registration sAttachment{ 210, +PrefsPanel::Registration sAttachment{ "Mouse", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew diff --git a/src/prefs/PlaybackPrefs.cpp b/src/prefs/PlaybackPrefs.cpp index 1b4f57fb5..a27a6d69f 100644 --- a/src/prefs/PlaybackPrefs.cpp +++ b/src/prefs/PlaybackPrefs.cpp @@ -183,7 +183,7 @@ bool PlaybackPrefs::Commit() } namespace{ -PrefsPanel::Registration sAttachment{ 20, +PrefsPanel::Registration sAttachment{ "Playback", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew diff --git a/src/prefs/PrefsDialog.cpp b/src/prefs/PrefsDialog.cpp index 828d85fbc..d489242a2 100644 --- a/src/prefs/PrefsDialog.cpp +++ b/src/prefs/PrefsDialog.cpp @@ -452,39 +452,6 @@ int wxTreebookExt::SetSelection(size_t n) return i; } -namespace { - struct Entry{ - unsigned sequenceNumber; - PrefsDialog::PrefsNode node; - - bool operator < ( const Entry &other ) const - { return sequenceNumber < other.sequenceNumber; } - }; - using Entries = std::vector< Entry >; - namespace Prefs { - Entries &Registry() - { - static Entries result; - return result; - } - } -} - -PrefsPanel::Registration::Registration( unsigned sequenceNumber, - const Factory &factory, - unsigned nChildren, - bool expanded ) -{ - auto ®istry = Prefs::Registry(); - Entry entry{ sequenceNumber, { factory, nChildren, expanded } }; - const auto end = registry.end(); - // Find insertion point: - auto iter = std::lower_bound( registry.begin(), end, entry ); - // There should not be duplicate sequence numbers: - wxASSERT( iter == end || entry < *iter ); - registry.insert( iter, entry ); -} - namespace { struct PrefsItem final : Registry::ConcreteGroupItem { @@ -537,6 +504,22 @@ const auto PathStart = wxT("Preferences"); } +namespace { +static Registry::GroupItem &sRegistry() +{ + static Registry::TransparentGroupItem<> registry{ PathStart }; + return registry; +} +} + +PrefsPanel::Registration::Registration( const wxString &name, + const Factory &factory, bool expanded, + const Registry::Placement &placement ) +{ + Registry::RegisterItem( sRegistry(), placement, + std::make_unique< PrefsItem >( name, factory, expanded ) ); +} + PrefsDialog::Factories &PrefsDialog::DefaultFactories() { @@ -552,18 +535,19 @@ PrefsDialog::Factories PathStart, { {wxT(""), - wxT("Device,Playback,Recording,Quality,GUI,Tracks,ImportExport,Projects,Directories,Warnings,Effects,KeyConfig,Mouse") + wxT("Device,Playback,Recording,Quality,GUI,Tracks,ImportExport,Directories,Warnings,Effects,KeyConfig,Mouse") }, {wxT("/Tracks"), wxT("TracksBehaviors,Spectrum")}, } }; + static Factories factories; static std::once_flag flag; std::call_once( flag, []{ - for ( const auto &entry : Prefs::Registry() ) { - factories.push_back( entry.node ); - } + PrefsItemVisitor visitor{ factories }; + Registry::TransparentGroupItem<> top{ PathStart }; + Registry::Visit( visitor, &top, &sRegistry() ); } ); return factories; } diff --git a/src/prefs/PrefsPanel.h b/src/prefs/PrefsPanel.h index c8508ac8f..bcd8063b5 100644 --- a/src/prefs/PrefsPanel.h +++ b/src/prefs/PrefsPanel.h @@ -30,6 +30,7 @@ MousePrefs, QualityPrefs, SpectrumPrefs and ThemePrefs. #include #include "../widgets/wxPanelWrapper.h" // to inherit #include "../include/audacity/ComponentInterface.h" +#include "../commands/CommandManager.h" /* A few constants for an attempt at semi-uniformity */ #define PREFS_FONT_SIZE 8 @@ -61,10 +62,9 @@ class PrefsPanel /* not final */ : public wxPanelWrapper, ComponentInterface // also implements the PrefsPanel subclass. struct Registration final { - Registration( unsigned sequenceNumber, - const Factory &factory, - unsigned nChildren = 0, - bool expanded = true ); + Registration( const wxString &name, const Factory &factory, + bool expanded = true, + const Registry::Placement &placement = { wxEmptyString, {} }); }; PrefsPanel(wxWindow * parent, diff --git a/src/prefs/ProjectsPrefs.cpp b/src/prefs/ProjectsPrefs.cpp index 092ab3e03..3c4e0effe 100644 --- a/src/prefs/ProjectsPrefs.cpp +++ b/src/prefs/ProjectsPrefs.cpp @@ -99,12 +99,16 @@ bool ProjectsPrefs::Commit() #ifdef EXPERIMENTAL_OD_DATA namespace{ -PrefsPanel::Registration sAttachment{ 130, +PrefsPanel::Registration sAttachment{ "Projects", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew return safenew ProjectsPrefs(parent, winid); - } + }, + false, + // Register with an explicit ordering hint because this one is + // only conditionally compiled + { "", { Registry::OrderingHint::After, "ImportExport" } } }; } #endif diff --git a/src/prefs/QualityPrefs.cpp b/src/prefs/QualityPrefs.cpp index 88a424bc0..ef4504a8e 100644 --- a/src/prefs/QualityPrefs.cpp +++ b/src/prefs/QualityPrefs.cpp @@ -234,7 +234,7 @@ bool QualityPrefs::Commit() } namespace{ -PrefsPanel::Registration sAttachment{ 50, +PrefsPanel::Registration sAttachment{ "Quality", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew diff --git a/src/prefs/RecordingPrefs.cpp b/src/prefs/RecordingPrefs.cpp index bf04ed74e..92ab9c56e 100644 --- a/src/prefs/RecordingPrefs.cpp +++ b/src/prefs/RecordingPrefs.cpp @@ -305,7 +305,7 @@ void RecordingPrefs::OnToggleCustomName(wxCommandEvent & /* Evt */) } namespace{ -PrefsPanel::Registration sAttachment{ 30, +PrefsPanel::Registration sAttachment{ "Recording", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew diff --git a/src/prefs/SpectrumPrefs.cpp b/src/prefs/SpectrumPrefs.cpp index 09dcb0ec7..156b56604 100644 --- a/src/prefs/SpectrumPrefs.cpp +++ b/src/prefs/SpectrumPrefs.cpp @@ -602,8 +602,10 @@ SpectrumPrefsFactory( WaveTrack *wt ) } namespace{ -PrefsPanel::Registration sAttachment{ 100, +PrefsPanel::Registration sAttachment{ "Spectrum", SpectrumPrefsFactory( nullptr ), - false + false, + // Place it at a lower tree level + { "Tracks" } }; } diff --git a/src/prefs/ThemePrefs.cpp b/src/prefs/ThemePrefs.cpp index 2d1d0ddfd..3c6de95e9 100644 --- a/src/prefs/ThemePrefs.cpp +++ b/src/prefs/ThemePrefs.cpp @@ -233,12 +233,16 @@ bool ThemePrefs::Commit() #ifdef EXPERIMENTAL_THEME_PREFS namespace{ -PrefsPanel::Registration sAttachment{ 180, +PrefsPanel::Registration sAttachment{ "Theme", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew return safenew ThemePrefs(parent, winid); - } + }, + false, + // Register with an explicit ordering hint because this one is + // only conditionally compiled + { "", { Registry::OrderingHint::After, "Effects" } } }; } #endif diff --git a/src/prefs/TracksBehaviorsPrefs.cpp b/src/prefs/TracksBehaviorsPrefs.cpp index 2cd89ff79..5da8861b4 100644 --- a/src/prefs/TracksBehaviorsPrefs.cpp +++ b/src/prefs/TracksBehaviorsPrefs.cpp @@ -132,11 +132,14 @@ bool TracksBehaviorsPrefs::Commit() } namespace{ -PrefsPanel::Registration sAttachment{ 90, +PrefsPanel::Registration sAttachment{ "TracksBehaviors", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew return safenew TracksBehaviorsPrefs(parent, winid); - } + }, + false, + // Place it at a lower tree level + { "Tracks" } }; } diff --git a/src/prefs/TracksPrefs.cpp b/src/prefs/TracksPrefs.cpp index 2916cc2ab..a8cfde7e1 100644 --- a/src/prefs/TracksPrefs.cpp +++ b/src/prefs/TracksPrefs.cpp @@ -448,12 +448,11 @@ bool TracksPrefs::Commit() } namespace{ -PrefsPanel::Registration sAttachment{ 70, +PrefsPanel::Registration sAttachment{ "Tracks", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew return safenew TracksPrefs(parent, winid); - }, - 2 + } }; } diff --git a/src/prefs/WarningsPrefs.cpp b/src/prefs/WarningsPrefs.cpp index 2ad2a306f..2a09b9bd7 100644 --- a/src/prefs/WarningsPrefs.cpp +++ b/src/prefs/WarningsPrefs.cpp @@ -107,7 +107,7 @@ bool WarningsPrefs::Commit() } namespace{ -PrefsPanel::Registration sAttachment{ 160, +PrefsPanel::Registration sAttachment{ "Warnings", [](wxWindow *parent, wxWindowID winid, AudacityProject *) { wxASSERT(parent); // to justify safenew diff --git a/src/prefs/WaveformPrefs.cpp b/src/prefs/WaveformPrefs.cpp index c9159f6a1..6ff108b7c 100644 --- a/src/prefs/WaveformPrefs.cpp +++ b/src/prefs/WaveformPrefs.cpp @@ -265,9 +265,12 @@ WaveformPrefsFactory(WaveTrack *wt) } #if 0 namespace{ -PrefsPanel::Registration sAttachment{ 80, +PrefsPanel::Registration sAttachment{ "Waveform", WaveformPrefsFactory( nullptr ), - false + false, + // Register with an explicit ordering hint because this one is + // only conditionally compiled; and place it at a lower tree level + { "Tracks", { Registry::OrderingHint::Before, "Spectrum" } } }; } #endif