mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-21 16:37:12 +01:00
Define registry item class and visitor for Preference pages
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
#include "../AudioIOBase.h"
|
#include "../AudioIOBase.h"
|
||||||
#include "../Prefs.h"
|
#include "../Prefs.h"
|
||||||
#include "../ShuttleGui.h"
|
#include "../ShuttleGui.h"
|
||||||
|
#include "../commands/CommandManager.h"
|
||||||
|
|
||||||
#include "PrefsPanel.h"
|
#include "PrefsPanel.h"
|
||||||
|
|
||||||
@@ -460,19 +461,21 @@ namespace {
|
|||||||
{ return sequenceNumber < other.sequenceNumber; }
|
{ return sequenceNumber < other.sequenceNumber; }
|
||||||
};
|
};
|
||||||
using Entries = std::vector< Entry >;
|
using Entries = std::vector< Entry >;
|
||||||
|
namespace Prefs {
|
||||||
Entries &Registry()
|
Entries &Registry()
|
||||||
{
|
{
|
||||||
static Entries result;
|
static Entries result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PrefsPanel::Registration::Registration( unsigned sequenceNumber,
|
PrefsPanel::Registration::Registration( unsigned sequenceNumber,
|
||||||
const Factory &factory,
|
const Factory &factory,
|
||||||
unsigned nChildren,
|
unsigned nChildren,
|
||||||
bool expanded )
|
bool expanded )
|
||||||
{
|
{
|
||||||
auto ®istry = Registry();
|
auto ®istry = Prefs::Registry();
|
||||||
Entry entry{ sequenceNumber, { factory, nChildren, expanded } };
|
Entry entry{ sequenceNumber, { factory, nChildren, expanded } };
|
||||||
const auto end = registry.end();
|
const auto end = registry.end();
|
||||||
// Find insertion point:
|
// Find insertion point:
|
||||||
@@ -482,6 +485,53 @@ PrefsPanel::Registration::Registration( unsigned sequenceNumber,
|
|||||||
registry.insert( iter, entry );
|
registry.insert( iter, entry );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct PrefsItem final : Registry::ConcreteGroupItem<false> {
|
||||||
|
PrefsPanel::Factory factory;
|
||||||
|
bool expanded{ false };
|
||||||
|
|
||||||
|
PrefsItem( const wxString &name,
|
||||||
|
const PrefsPanel::Factory &factory_, bool expanded_ )
|
||||||
|
: ConcreteGroupItem<false>{ name }
|
||||||
|
, factory{ factory_ }, expanded{ expanded_ }
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Collects registry tree nodes into a vector, in preorder.
|
||||||
|
struct PrefsItemVisitor final : Registry::Visitor {
|
||||||
|
PrefsItemVisitor( PrefsDialog::Factories &factories_ )
|
||||||
|
: factories{ factories_ }
|
||||||
|
{
|
||||||
|
childCounts.push_back( 0 );
|
||||||
|
}
|
||||||
|
void BeginGroup( Registry::GroupItem &item, const Path & ) override
|
||||||
|
{
|
||||||
|
auto pItem = dynamic_cast<PrefsItem*>( &item );
|
||||||
|
if (!pItem)
|
||||||
|
return;
|
||||||
|
indices.push_back( factories.size() );
|
||||||
|
factories.emplace_back( pItem->factory, 0, pItem->expanded );
|
||||||
|
++childCounts.back();
|
||||||
|
childCounts.push_back( 0 );
|
||||||
|
}
|
||||||
|
void EndGroup( Registry::GroupItem &item, const Path & ) override
|
||||||
|
{
|
||||||
|
auto pItem = dynamic_cast<PrefsItem*>( &item );
|
||||||
|
if (!pItem)
|
||||||
|
return;
|
||||||
|
auto &factory = factories[ indices.back() ];
|
||||||
|
factory.nChildren = childCounts.back();
|
||||||
|
childCounts.pop_back();
|
||||||
|
indices.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
PrefsDialog::Factories &factories;
|
||||||
|
std::vector<size_t> childCounts;
|
||||||
|
std::vector<size_t> indices;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
PrefsDialog::Factories
|
PrefsDialog::Factories
|
||||||
&PrefsDialog::DefaultFactories()
|
&PrefsDialog::DefaultFactories()
|
||||||
{
|
{
|
||||||
@@ -489,7 +539,7 @@ PrefsDialog::Factories
|
|||||||
static std::once_flag flag;
|
static std::once_flag flag;
|
||||||
|
|
||||||
std::call_once( flag, []{
|
std::call_once( flag, []{
|
||||||
for ( const auto &entry : Registry() ) {
|
for ( const auto &entry : Prefs::Registry() ) {
|
||||||
factories.push_back( entry.node );
|
factories.push_back( entry.node );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ class PrefsDialog /* not final */ : public wxDialogWrapper
|
|||||||
std::function< PrefsPanel * (
|
std::function< PrefsPanel * (
|
||||||
wxWindow *parent, wxWindowID winid, AudacityProject *) >;
|
wxWindow *parent, wxWindowID winid, AudacityProject *) >;
|
||||||
Factory factory;
|
Factory factory;
|
||||||
unsigned nChildren;
|
size_t nChildren{ 0 };
|
||||||
bool expanded;
|
bool expanded{ false };
|
||||||
|
|
||||||
PrefsNode(const Factory &factory_,
|
PrefsNode(const Factory &factory_,
|
||||||
unsigned nChildren_ = 0,
|
unsigned nChildren_ = 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user