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
170 // If this default finder function is reached, then FinderScope should
171 // have been used somewhere but was not, or an explicit
172 // CommandHandlerFinder was not passed to menu item constructors
173 wxASSERT( false );
174 return project;
175 };
176
177}
178
179namespace {
180
181using namespace Registry;
182
183const auto MenuPathStart = wxT("MenuBar");
184
185}
186
188{
189 static GroupItem<Traits> registry{ MenuPathStart };
190 return registry;
191}
192
194{
195 // Once only, cause initial population of preferences for the ordering
196 // of some menu items that used to be given in tables but are now separately
197 // registered in several .cpp files; the sequence of registration depends
198 // on unspecified accidents of static initialization order across
199 // compilation units, so we need something specific here to preserve old
200 // default appearance of menus.
201 // But this needs only to mention some strings -- there is no compilation or
202 // link dependency of this source file on those other implementation files.
203
206 {
207 {wxT(""), wxT(
208"File,Edit,Select,View,Transport,Tracks,Generate,Effect,Analyze,Tools,Window,Optional,Help"
209 )},
210 {wxT("/Optional/Extra/Part1"), wxT(
211"Transport,Tools,Mixer,Edit,PlayAtSpeed,Seek,Device,Select"
212 )},
213 {wxT("/Optional/Extra/Part2"), wxT(
214"Navigation,Focus,Cursor,Track,Scriptables1,Scriptables2"
215 )},
216 {wxT("/View/Windows"), wxT("UndoHistory,MixerBoard")},
217 {wxT("/Analyze/Analyzers/Windows"), wxT("ContrastAnalyser,PlotSpectrum")},
218 {wxT("/Transport/Basic"), wxT("Play,Record,Scrubbing,Cursor")},
219 {wxT("/View/Other/Toolbars/Toolbars/Other"), wxT(
220"ShowTransportTB,ShowToolsTB,ShowRecordMeterTB,ShowPlayMeterTB,"
221//"ShowMeterTB,"
222"ShowMixerTB,"
223"ShowEditTB,ShowTranscriptionTB,ShowScrubbingTB,ShowDeviceTB,ShowSelectionTB,"
224"ShowSpectralSelectionTB") },
225 {wxT("/Tracks/Add/Add"), wxT(
226"NewMonoTrack,NewStereoTrack,NewLabelTrack,NewTimeTrack")},
227 {wxT("/Optional/Extra/Part2/Scriptables1"), wxT(
228"SelectTime,SelectFrequencies,SelectTracks,SetTrackStatus,SetTrackAudio,"
229"SetTrackVisuals,GetPreference,SetPreference,SetClip,SetEnvelope,SetLabel"
230"SetProject") },
231 {wxT("/Optional/Extra/Part2/Scriptables2"), wxT(
232"Select,SetTrack,GetInfo,Message,Help,Import2,Export2,OpenProject2,"
233"SaveProject2,Drag,CompareAudio") },
234 }
235 };
236
237 static const auto menuTree = MenuRegistry::Items( MenuPathStart );
238
239 wxLogNull nolog;
240 Registry::VisitWithFunctions(visitor, menuTree.get(),
242}
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
static const AudacityProject::AttachedObjects::RegisteredFactory key
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
wxString name
Definition: TagsEditor.cpp:166
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
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