forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrefsPanel.cpp
More file actions
133 lines (111 loc) · 3.65 KB
/
Copy pathPrefsPanel.cpp
File metadata and controls
133 lines (111 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**********************************************************************
Audacity: A Digital Audio Editor
PrefsPanel.cpp
Paul Licameli split from PrefsDialog.cpp
**********************************************************************/
#include "PrefsPanel.h"
#include <mutex>
namespace {
const auto PathStart = wxT("Preferences");
static Registry::GroupItem &sRegistry()
{
static Registry::TransparentGroupItem<> registry{ PathStart };
return registry;
}
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( PrefsPanel::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();
}
PrefsPanel::Factories &factories;
std::vector<size_t> childCounts;
std::vector<size_t> indices;
};
}
PluginPath PrefsPanel::GetPath()
{ return BUILTIN_PREFS_PANEL_PREFIX + GetSymbol().Internal(); }
VendorSymbol PrefsPanel::GetVendor()
{ return XO("Audacity");}
wxString PrefsPanel::GetVersion()
{ return AUDACITY_VERSION_STRING;}
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 ) );
}
PrefsPanel::~PrefsPanel()
{
}
void PrefsPanel::Cancel()
{
}
bool PrefsPanel::ShowsPreviewButton()
{
return false;
}
wxString PrefsPanel::HelpPageName()
{
return wxEmptyString;
}
PrefsPanel::Factories
&PrefsPanel::DefaultFactories()
{
// Once only, cause initial population of preferences for the ordering
// of some preference pages that used to be given in a table but are now
// separately registered in several .cpp files; the sequence of registration
// depends on unspecified accidents of static initialization order across
// compilation units, so we need something specific here to preserve old
// default appearance of the preference dialog.
// But this needs only to mention some strings -- there is no compilation or
// link dependency of this source file on those other implementation files.
static Registry::OrderingPreferenceInitializer init{
PathStart,
{
{wxT(""),
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, []{
PrefsItemVisitor visitor{ factories };
Registry::TransparentGroupItem<> top{ PathStart };
Registry::Visit( visitor, &top, &sRegistry() );
} );
return factories;
}