1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-18 17:10:55 +02:00

Redefine PrefsPanel::Registration with new Registry system...

... preserving the existing ordering of pages with a combination of
preferences and ordering hints
This commit is contained in:
Paul Licameli 2019-01-16 12:18:40 -05:00
parent 2ee8a6440a
commit a333b7d35a
24 changed files with 94 additions and 77 deletions

View File

@ -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

View File

@ -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

View File

@ -300,7 +300,7 @@ DirectoriesPrefsFactory() {
}
namespace{
PrefsPanel::Registration sAttachment{ 150,
PrefsPanel::Registration sAttachment{ "Directories",
DirectoriesPrefsFactory() };
};

View File

@ -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

View File

@ -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" }
};
}

View File

@ -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

View File

@ -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
}
};
}

View File

@ -890,7 +890,7 @@ KeyConfigPrefsFactory( const CommandID &name )
};
}
namespace{
PrefsPanel::Registration sAttachment{ 200,
PrefsPanel::Registration sAttachment{ "KeyConfig",
KeyConfigPrefsFactory()
};
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 &registry = 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<false> {
@ -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;
}

View File

@ -30,6 +30,7 @@ MousePrefs, QualityPrefs, SpectrumPrefs and ThemePrefs.
#include <functional>
#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,

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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" }
};
}

View File

@ -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

View File

@ -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" }
};
}

View File

@ -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
}
};
}

View File

@ -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

View File

@ -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