1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-30 15:39:27 +02:00

define PrefsPanel::Registration

This commit is contained in:
Paul Licameli 2020-01-19 20:14:36 -05:00
parent 1367220650
commit 1555fd84a4
3 changed files with 44 additions and 5 deletions

View File

@ -477,7 +477,36 @@ 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 >;
Entries &Registry()
{
static Entries result;
return result;
}
}
PrefsPanel::Registration::Registration( unsigned sequenceNumber,
const Factory &factory,
unsigned nChildren,
bool expanded )
{
auto &registry = 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 );
}
PrefsDialog::Factories
&PrefsDialog::DefaultFactories()

View File

@ -39,11 +39,11 @@ class PrefsDialog /* not final */ : public wxDialogWrapper
std::function< PrefsPanel * (
wxWindow *parent, wxWindowID winid, AudacityProject *) >;
Factory factory;
CONST int nChildren;
unsigned nChildren;
bool expanded;
PrefsNode(const Factory &factory_,
int nChildren_ = 0,
unsigned nChildren_ = 0,
bool expanded_ = true)
: factory(factory_), nChildren(nChildren_), expanded(expanded_)
{}

View File

@ -49,7 +49,7 @@ class PrefsPanel /* not final */ : public wxPanelWrapper, ComponentInterface
{
public:
// \brief Type alias for factories such as GUIPrefsFactory that produce a
// PrefsPanel.
// PrefsPanel, used by the Preferences dialog in a treebook.
// 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.
@ -57,8 +57,18 @@ class PrefsPanel /* not final */ : public wxPanelWrapper, ComponentInterface
std::function< PrefsPanel * (
wxWindow *parent, wxWindowID winid, AudacityProject *) >;
PrefsPanel(
wxWindow * parent, wxWindowID winid, const TranslatableString &title)
// Typically you make a static object of this type in the .cpp file that
// also implements the PrefsPanel subclass.
struct Registration final
{
Registration( unsigned sequenceNumber,
const Factory &factory,
unsigned nChildren = 0,
bool expanded = true );
};
PrefsPanel(wxWindow * parent,
wxWindowID winid, const TranslatableString &title)
: wxPanelWrapper(parent, winid)
{
SetLabel(title); // Provide visual label