Audacity  3.0.3
PrefsPanel.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 PrefsPanel.cpp
6 
7 Paul Licameli split from PrefsDialog.cpp
8 
9 **********************************************************************/
10 
11 #include "PrefsPanel.h"
12 #include <mutex>
13 
14 namespace {
15 const auto PathStart = wxT("Preferences");
16 
18 {
20  return registry;
21 }
22 
23 struct PrefsItem final : Registry::ConcreteGroupItem<false> {
25  bool expanded{ false };
26 
27  PrefsItem( const wxString &name,
28  const PrefsPanel::Factory &factory_, bool expanded_ )
29  : ConcreteGroupItem<false>{ name }
30  , factory{ factory_ }, expanded{ expanded_ }
31  {}
32 };
33 
34 // Collects registry tree nodes into a vector, in preorder.
37  : factories{ factories_ }
38  {
39  childCounts.push_back( 0 );
40  }
41  void BeginGroup( Registry::GroupItem &item, const Path & ) override
42  {
43  auto pItem = dynamic_cast<PrefsItem*>( &item );
44  if (!pItem)
45  return;
46  indices.push_back( factories.size() );
47  factories.emplace_back( pItem->factory, 0, pItem->expanded );
48  ++childCounts.back();
49  childCounts.push_back( 0 );
50  }
51  void EndGroup( Registry::GroupItem &item, const Path & ) override
52  {
53  auto pItem = dynamic_cast<PrefsItem*>( &item );
54  if (!pItem)
55  return;
56  auto &factory = factories[ indices.back() ];
57  factory.nChildren = childCounts.back();
58  childCounts.pop_back();
59  indices.pop_back();
60  }
61 
63  std::vector<size_t> childCounts;
64  std::vector<size_t> indices;
65 };
66 }
67 
70 
72 { return XO("Audacity");}
73 
75 { return AUDACITY_VERSION_STRING;}
76 
78  const Factory &factory, bool expanded,
79  const Registry::Placement &placement )
80 {
81  Registry::RegisterItem( sRegistry(), placement,
82  std::make_unique< PrefsItem >( name, factory, expanded ) );
83 }
84 
86 {
87 }
88 
90 {
91 }
92 
94 {
95  return false;
96 }
97 
99 {
100  return {};
101 }
102 
105 {
106  // Once only, cause initial population of preferences for the ordering
107  // of some preference pages that used to be given in a table but are now
108  // separately registered in several .cpp files; the sequence of registration
109  // depends on unspecified accidents of static initialization order across
110  // compilation units, so we need something specific here to preserve old
111  // default appearance of the preference dialog.
112  // But this needs only to mention some strings -- there is no compilation or
113  // link dependency of this source file on those other implementation files.
115  PathStart,
116  {
117  {wxT(""),
118  wxT("Device,Playback,Recording,Quality,GUI,Tracks,ImportExport,Directories,Warnings,Effects,KeyConfig,Mouse")
119  },
120  {wxT("/Tracks"), wxT("TracksBehaviors,Spectrum")},
121  }
122  };
123 
124  static Factories factories;
125  static std::once_flag flag;
126 
127  std::call_once( flag, []{
128  PrefsItemVisitor visitor{ factories };
130  Registry::Visit( visitor, &top, &sRegistry() );
131  } );
132  return factories;
133 }
Registry::TransparentGroupItem
Definition: Registry.h:210
Registry::RegisterItem
void RegisterItem(GroupItem &registry, const Placement &placement, BaseItemPtr pItem)
Definition: Registry.cpp:750
PrefsPanel::GetVersion
virtual wxString GetVersion()
Definition: PrefsPanel.cpp:74
ComponentInterface::GetSymbol
virtual ComponentInterfaceSymbol GetSymbol()=0
flag
static std::once_flag flag
Definition: WaveformView.cpp:1124
PrefsPanel.h
PrefsPanel::HelpPageName
virtual ManualPageID HelpPageName()
If not empty string, the Help button is added below the panel.
Definition: PrefsPanel.cpp:98
PluginPath
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
XO
#define XO(s)
Definition: Internat.h:31
PrefsPanel::Factory
std::function< PrefsPanel *(wxWindow *parent, wxWindowID winid, AudacityProject *) > Factory
Definition: PrefsPanel.h:79
Registry::Placement
Definition: Registry.h:219
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
PrefsPanel::GetPath
virtual PluginPath GetPath()
Definition: PrefsPanel.cpp:68
PrefsPanel::ShowsPreviewButton
virtual bool ShowsPreviewButton()
Definition: PrefsPanel.cpp:93
Registry::Visitor
Definition: Registry.h:242
anonymous_namespace{PrefsPanel.cpp}::PrefsItemVisitor::indices
std::vector< size_t > indices
Definition: PrefsPanel.cpp:64
PrefsPanel::DefaultFactories
static Factories & DefaultFactories()
Definition: PrefsPanel.cpp:104
factory
static RegisteredToolbarFactory factory
Definition: ControlToolBar.cpp:806
BUILTIN_PREFS_PANEL_PREFIX
#define BUILTIN_PREFS_PANEL_PREFIX
Definition: PrefsPanel.h:38
anonymous_namespace{PrefsPanel.cpp}::PrefsItemVisitor::factories
PrefsPanel::Factories & factories
Definition: PrefsPanel.cpp:62
Registry::Visitor::Path
std::vector< Identifier > Path
Definition: Registry.h:245
name
const TranslatableString name
Definition: Distortion.cpp:98
anonymous_namespace{PrefsPanel.cpp}::PrefsItemVisitor
Definition: PrefsPanel.cpp:35
anonymous_namespace{PrefsPanel.cpp}::PrefsItemVisitor::BeginGroup
void BeginGroup(Registry::GroupItem &item, const Path &) override
Definition: PrefsPanel.cpp:41
PrefsPanel::GetVendor
virtual VendorSymbol GetVendor()
Definition: PrefsPanel.cpp:71
anonymous_namespace{PrefsPanel.cpp}::PrefsItemVisitor::childCounts
std::vector< size_t > childCounts
Definition: PrefsPanel.cpp:63
anonymous_namespace{PrefsPanel.cpp}::PrefsItem::factory
PrefsPanel::Factory factory
Definition: PrefsPanel.cpp:24
Registry::Visit
void Visit(Visitor &visitor, BaseItem *pTopItem, const GroupItem *pRegistry)
Definition: Registry.cpp:713
TaggedIdentifier< ManualPageIDTag >
anonymous_namespace{PrefsPanel.cpp}::PathStart
const auto PathStart
Definition: PrefsPanel.cpp:15
PrefsPanel::Cancel
virtual void Cancel()
Definition: PrefsPanel.cpp:89
PrefsPanel::~PrefsPanel
virtual ~PrefsPanel()
Definition: PrefsPanel.cpp:85
Registry::ConcreteGroupItem
Definition: Registry.h:198
ComponentInterfaceSymbol::Internal
const wxString & Internal() const
Definition: ComponentInterfaceSymbol.h:55
anonymous_namespace{PrefsPanel.cpp}::PrefsItem
Definition: PrefsPanel.cpp:23
Registry::GroupItem
Definition: Registry.h:126
anonymous_namespace{PrefsPanel.cpp}::PrefsItemVisitor::PrefsItemVisitor
PrefsItemVisitor(PrefsPanel::Factories &factories_)
Definition: PrefsPanel.cpp:36
anonymous_namespace{PrefsPanel.cpp}::PrefsItem::PrefsItem
PrefsItem(const wxString &name, const PrefsPanel::Factory &factory_, bool expanded_)
Definition: PrefsPanel.cpp:27
PrefsPanel::Registration::Registration
Registration(const wxString &name, const Factory &factory, bool expanded=true, const Registry::Placement &placement={ wxEmptyString, {} })
Definition: PrefsPanel.cpp:77
PrefsPanel::Factories
std::vector< PrefsPanel::PrefsNode > Factories
Definition: PrefsPanel.h:69
anonymous_namespace{PrefsPanel.cpp}::sRegistry
static Registry::GroupItem & sRegistry()
Definition: PrefsPanel.cpp:17
anonymous_namespace{PrefsPanel.cpp}::PrefsItemVisitor::EndGroup
void EndGroup(Registry::GroupItem &item, const Path &) override
Definition: PrefsPanel.cpp:51
Registry::OrderingPreferenceInitializer
Definition: Registry.h:273