Audacity 3.2.0
MenuRegistry.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 MenuRegistry.cpp
6
7 (formerly Menus.cpp)
8
9 Dominic Mazzoni
10 Brian Gunlogson
11 et al.
12
13*//*******************************************************************/
14#include "MenuRegistry.h"
15#include "Project.h"
16#include "BasicUI.h"
17#include <wx/log.h>
18
19namespace MenuRegistry {
20auto Options::MakeCheckFn(const wxString key, bool defaultValue ) -> CheckFn
21{
22 return [=](AudacityProject&){ return gPrefs->ReadBool( key, defaultValue ); };
23}
24
26{
27 return MakeCheckFn( setting.GetPath(), setting.GetDefault() );
28}
29
31 const ItemProperties *pProperties)
32{
33 const auto properties =
34 pProperties ? pProperties->GetProperties() : ItemProperties::None;
35
36 bool inlined = false;
37 bool shouldDoSeparator = false;
38
39 switch (properties) {
41 inlined = true;
42 break;
43 }
45 if (!needSeparator.empty())
46 needSeparator.back() = true;
47 break;
48 }
51 shouldDoSeparator = ShouldDoSeparator();
52 break;
53 }
54 default:
55 break;
56 }
57
58 return { !inlined, shouldDoSeparator };
59}
60
62 const ItemProperties *pProperties)
63{
64 const auto properties =
65 pProperties ? pProperties->GetProperties() : ItemProperties::None;
66
67 bool isMenu = false;
68 bool isExtension = false;
69
70 switch (properties) {
73 isMenu = true;
74 isExtension = (properties == ItemProperties::Extension);
75 break;
76 }
77 default:
78 break;
79 }
80
81 if (isMenu) {
82 needSeparator.push_back(false);
83 firstItem.push_back(!isExtension);
84 }
85}
86
88 const ItemProperties *pProperties)
89{
90 const auto properties =
91 pProperties ? pProperties->GetProperties() : ItemProperties::None;
92
93 bool inlined = false;
94
95 switch (properties) {
97 inlined = true;
98 break;
99 }
101 if ( !needSeparator.empty() )
102 needSeparator.back() = true;
103 break;
104 }
107 firstItem.pop_back();
108 needSeparator.pop_back();
109 break;
110 }
111 default:
112 break;
113 }
114
115 return !inlined;
116}
117
119{
120 bool separate = false;
121 if (!needSeparator.empty()) {
122 separate = needSeparator.back() && !firstItem.back();
123 needSeparator.back() = false;
124 firstItem.back() = false;
125 }
126 return separate;
127}
128
130auto MenuItem::GetProperties() const -> Properties { return Whole; }
131
133
135 const TranslatableString &label_in_,
136 CommandFunctorPointer callback_,
137 CommandFlag flags_,
138 const Options &options_,
139 CommandHandlerFinder finder_)
140: SingleItem{ name_ }, label_in{ label_in_ }
141, finder{ finder_ }, callback{ callback_ }
142, flags{ flags_ }, options{ options_ }
143{}
145
147 std::vector< ComponentInterfaceSymbol > items_,
148 CommandFunctorPointer callback_,
149 CommandFlag flags_,
150 bool isEffect_,
151 CommandHandlerFinder finder_)
152: SingleItem{ name_ }, items{ std::move(items_) }
153, finder{ finder_ }, callback{ callback_ }
154, flags{ flags_ }, isEffect{ isEffect_ }
155{}
157
160auto MenuPart::GetProperties() const -> Properties { return Section; }
161
163auto MenuItems::GetOrdering() const -> Ordering {
164 return name.empty() ? Anonymous : Weak;
165}
166auto MenuItems::GetProperties() const -> Properties { return Inline; }
167
169
172 // If this default finder function is reached, then FinderScope should
173 // have been used somewhere but was not, or an explicit
174 // CommandHandlerFinder was not passed to menu item constructors
175 wxASSERT( false );
176 return project;
177 };
178
179}
180
181namespace {
182
183using namespace Registry;
184
185const auto MenuPathStart = wxT("MenuBar");
186
187}
188
190{
191 static GroupItem<Traits> registry{ MenuPathStart };
192 return registry;
193}
194
196{
197 // Once only, cause initial population of preferences for the ordering
198 // of some menu items that used to be given in tables but are now separately
199 // registered in several .cpp files; the sequence of registration depends
200 // on unspecified accidents of static initialization order across
201 // compilation units, so we need something specific here to preserve old
202 // default appearance of menus.
203 // But this needs only to mention some strings -- there is no compilation or
204 // link dependency of this source file on those other implementation files.
205
208 {
209 {wxT(""), wxT(
210"File,Edit,Select,View,Transport,Tracks,Generate,Effect,Analyze,Tools,Window,Optional,Help"
211 )},
212 {wxT("/Optional/Extra/Part1"), wxT(
213"Transport,Tools,Mixer,Edit,PlayAtSpeed,Seek,Device,Select"
214 )},
215 {wxT("/Optional/Extra/Part2"), wxT(
216"Navigation,Focus,Cursor,Track,Scriptables1,Scriptables2"
217 )},
218 {wxT("/View/Windows"), wxT("UndoHistory,MixerBoard")},
219 {wxT("/Analyze/Analyzers/Windows"), wxT("ContrastAnalyser,PlotSpectrum")},
220 {wxT("/Transport/Basic"), wxT("Play,Record,Scrubbing,Cursor")},
221 {wxT("/View/Other/Toolbars/Toolbars/Other"), wxT(
222"ShowTransportTB,ShowToolsTB,ShowRecordMeterTB,ShowPlayMeterTB,"
223//"ShowMeterTB,"
224"ShowMixerTB,"
225"ShowEditTB,ShowTranscriptionTB,ShowScrubbingTB,ShowDeviceTB,ShowSelectionTB,"
226"ShowSpectralSelectionTB") },
227 {wxT("/Tracks/Add/Add"), wxT(
228"NewMonoTrack,NewStereoTrack,NewLabelTrack,NewTimeTrack")},
229 {wxT("/Optional/Extra/Part2/Scriptables1"), wxT(
230"SelectTime,SelectFrequencies,SelectTracks,SetTrackStatus,SetTrackAudio,"
231"SetTrackVisuals,GetPreference,SetPreference,SetClip,SetEnvelope,SetLabel"
232"SetProject") },
233 {wxT("/Optional/Extra/Part2/Scriptables2"), wxT(
234"Select,SetTrack,GetInfo,Message,Help,Import2,Export2,OpenProject2,"
235"SaveProject2,Drag,CompareAudio") },
236 }
237 };
238
239 static const auto menuTree = MenuRegistry::Items( MenuPathStart );
240
241 wxLogNull nolog;
242 Registry::VisitWithFunctions(visitor, menuTree.get(),
244}
wxT("CloseDown"))
Toolkit-neutral facade for basic user interface services.
std::bitset< NCommandFlags > CommandFlag
Definition: CommandFlag.h:30
std::function< CommandHandlerObject &(AudacityProject &) > CommandHandlerFinder
wxEvtHandler CommandHandlerObject
const TranslatableString name
Definition: Distortion.cpp:76
static const AudacityProject::AttachedObjects::RegisteredFactory key
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
const auto project
static const auto MenuPathStart
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
This specialization of Setting for bool adds a Toggle method to negate the saved value.
Definition: Prefs.h:346
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
static CommandHandlerFinder sFinder
Definition: MenuRegistry.h:267
Holds a msgid for the translation catalog; may also bind format arguments.
bool ReadBool(const wxString &key, bool defaultValue) const
constexpr auto Items
Definition: MenuRegistry.h:427
std::function< bool(AudacityProject &) > CheckFn
Definition: MenuRegistry.h:34
MENUS_API void Visit(Visitor< Traits > &visitor, AudacityProject &project)
void VisitWithFunctions(const VisitorFunctions< RegistryTraits > &visitors, const GroupItem< RegistryTraits > *pTopItem, const GroupItem< RegistryTraits > *pRegistry={}, typename RegistryTraits::ComputedItemContextType &computedItemContext=RegistryTraits::ComputedItemContextType::Instance)
Definition: Registry.h:623
auto finder(TrackId id, int &distance)
STL namespace.
CommandGroupItem(const Identifier &name_, std::vector< ComponentInterfaceSymbol > items_, CommandFunctorPointer callback_, CommandFlag flags_, bool isEffect_, CommandHandlerFinder finder_)
CommandItem(const CommandID &name_, const TranslatableString &label_in_, CommandFunctorPointer callback_, CommandFlag flags_, const Options &options_, CommandHandlerFinder finder_)
A mix-in discovered by dynamic_cast; independent of the Traits.
Definition: MenuRegistry.h:106
virtual Properties GetProperties() const =0
static GroupItem< Traits > & Registry()
Properties GetProperties() const override
Ordering GetOrdering() const override
Anonymous if its name is empty, else weakly ordered.
Properties GetProperties() const override
Properties GetProperties() const override
static CheckFn MakeCheckFn(const wxString key, bool defaultValue)
std::vector< bool > needSeparator
Definition: MenuRegistry.h:127
void AfterBeginGroup(const ItemProperties *pProperties)
bool ShouldEndGroup(const ItemProperties *pProperties)
std::pair< bool, bool > ShouldBeginGroup(const ItemProperties *pProperties)
Common abstract base class for items that are not groups.
Definition: Registry.h:224