Audacity 3.2.0
CommandManager.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 CommandManager.h
6
7 Brian Gunlogson
8 Dominic Mazzoni
9
10**********************************************************************/
11
12#ifndef __AUDACITY_COMMAND_MANAGER__
13#define __AUDACITY_COMMAND_MANAGER__
14
15#include "Identifier.h"
16
17#include "ClientData.h"
18#include "CommandFunctors.h"
19#include "CommandFlag.h"
20#include "GlobalVariable.h"
21
22#include "Keyboard.h"
23
24#include "Prefs.h"
25#include "Project.h"
26#include "Registry.h"
27
28#include <vector>
29
30#include "XMLTagHandler.h"
31
32#include <unordered_map>
33
34class wxEvent;
35class wxMenu;
36class wxMenuBar;
38
39class BoolSetting;
40
41struct MenuBarListEntry;
42struct SubMenuListEntry;
43struct CommandListEntry;
44
45using MenuBarList = std::vector < MenuBarListEntry >;
46using SubMenuList = std::vector < SubMenuListEntry >;
47
48// This is an array of pointers, not structures, because the hash maps also point to them,
49// so we don't want the structures to relocate with vector operations.
50using CommandList = std::vector<std::unique_ptr<CommandListEntry>>;
51
52using CommandKeyHash = std::unordered_map<NormalizedKeyString, CommandListEntry*>;
53using CommandNameHash = std::unordered_map<CommandID, CommandListEntry*>;
54using CommandNumericIDHash = std::unordered_map<int, CommandListEntry*>;
55
56class AudacityProject;
57class CommandContext;
58
59class AUDACITY_DLL_API CommandManager final
60 : public XMLTagHandler
61 , public ClientData::Base
62{
63 public:
64 static CommandManager &Get( AudacityProject &project );
65 static const CommandManager &Get( const AudacityProject &project );
66
67 // Interception of menu item handling.
68 // If it returns true, bypass the usual dispatch of commands.
69 struct AUDACITY_DLL_API GlobalMenuHook : GlobalHook<GlobalMenuHook,
70 bool(const CommandID&)
71 >{};
72
73 //
74 // Constructor / Destructor
75 //
76
78 virtual ~CommandManager();
79
80 CommandManager(const CommandManager&) PROHIBITED;
81 CommandManager &operator= (const CommandManager&) PROHIBITED;
82
83 void SetMaxList();
84 void PurgeData();
85
86 //
87 // Creating menus and adding commands
88 //
89
90 std::unique_ptr<wxMenuBar> AddMenuBar(const wxString & sMenu);
91
92 wxMenu *BeginMenu(const TranslatableString & tName);
93 void EndMenu();
94
95 // type of a function that determines checkmark state
96 using CheckFn = std::function< bool(AudacityProject&) >;
97
98 // For specifying unusual arguments in AddItem
99 struct AUDACITY_DLL_API Options
100 {
102 // Allow implicit construction from an accelerator string, which is
103 // a very common case
104 Options( const wxChar *accel_ ) : accel{ accel_ } {}
105 // A two-argument constructor for another common case
107 const wxChar *accel_,
108 const TranslatableString &longName_ )
109 : accel{ accel_ }, longName{ longName_ } {}
110
111 Options &&Accel (const wxChar *value) &&
112 { accel = value; return std::move(*this); }
113 Options &&IsEffect (bool value = true) &&
114 { bIsEffect = value; return std::move(*this); }
116 { parameter = value; return std::move(*this); }
118 { longName = value; return std::move(*this); }
120 { global = true; return std::move(*this); }
122 { useStrictFlags = true; return std::move(*this); }
124 { wantKeyUp = true; return std::move(*this); }
126 { skipKeyDown = true; return std::move(*this); }
127
128 // This option affects debugging only:
130 { allowDup = true; return std::move(*this); }
131
132 Options &&AllowInMacros ( int value = 1 ) &&
133 { allowInMacros = value; return std::move(*this); }
134
135 // CheckTest is overloaded
136 // Take arbitrary predicate
138 { checker = fn; return std::move(*this); }
139 // Take a preference path
140 Options &&CheckTest (const wxChar *key, bool defaultValue) && {
141 checker = MakeCheckFn( key, defaultValue );
142 return std::move(*this);
143 }
144 // Take a BoolSetting
145 Options &&CheckTest ( const BoolSetting &setting ) && {
146 checker = MakeCheckFn( setting );
147 return std::move(*this);
148 }
149
150 const wxChar *accel{ wxT("") };
151 CheckFn checker; // default value means it's not a check item
152 bool bIsEffect{ false };
153 CommandParameter parameter{};
155 bool global{ false };
156 bool useStrictFlags{ false };
157 bool wantKeyUp{ false };
158 bool skipKeyDown{ false };
159 bool allowDup{ false };
160 int allowInMacros{ -1 }; // 0 = never, 1 = always, -1 = deduce from label
161
162 private:
163 static CheckFn
164 MakeCheckFn( const wxString key, bool defaultValue );
165 static CheckFn
166 MakeCheckFn( const BoolSetting &setting );
167 };
168
169 void AddItemList(const CommandID & name,
170 const ComponentInterfaceSymbol items[],
171 size_t nItems,
173 CommandFunctorPointer callback,
174 CommandFlag flags,
175 bool bIsEffect = false);
176
177 void AddItem(AudacityProject &project,
178 const CommandID & name,
179 const TranslatableString &label_in,
181 CommandFunctorPointer callback,
182 CommandFlag flags,
183 const Options &options = {});
184
185 void AddSeparator();
186
187 void PopMenuBar();
188 void BeginOccultCommands();
189 void EndOccultCommands();
190
191
192 void SetCommandFlags(const CommandID &name, CommandFlag flags);
193
194 //
195 // Modifying menus
196 //
197
198 void EnableUsingFlags(
199 CommandFlag flags, CommandFlag strictFlags);
200 void Enable(const wxString &name, bool enabled);
201 void Check(const CommandID &name, bool checked);
202 void Modify(const wxString &name, const TranslatableString &newLabel);
203
204 //
205 // Modifying accelerators
206 //
207
208 void SetKeyFromName(const CommandID &name, const NormalizedKeyString &key);
209 void SetKeyFromIndex(int i, const NormalizedKeyString &key);
210
211 //
212 // Executing commands
213 //
214
215 // "permit" allows filtering even if the active window isn't a child of the project.
216 // Lyrics and MixerTrackCluster classes use it.
217 bool FilterKeyEvent(AudacityProject *project, const wxKeyEvent & evt, bool permit = false);
218 bool HandleMenuID(AudacityProject &project, int id, CommandFlag flags, bool alwaysEnabled);
219 void RegisterLastAnalyzer(const CommandContext& context);
220 void RegisterLastTool(const CommandContext& context);
221 void DoRepeatProcess(const CommandContext& context, int);
222
226 CommandNotFound
227 };
228
229 TextualCommandResult
231 const CommandContext & context, CommandFlag flags, bool alwaysEnabled);
232
233 //
234 // Accessing
235 //
236
237 TranslatableStrings GetCategories( AudacityProject& );
238 void GetAllCommandNames(CommandIDs &names, bool includeMultis) const;
239 void GetAllCommandLabels(
240 TranslatableStrings &labels, std::vector<bool> &vExcludeFromMacros,
241 bool includeMultis) const;
242 void GetAllCommandData(
244 std::vector<NormalizedKeyString> &keys,
245 std::vector<NormalizedKeyString> &default_keys,
246 TranslatableStrings &labels, TranslatableStrings &categories,
247#if defined(EXPERIMENTAL_KEY_VIEW)
248 TranslatableStrings &prefixes,
249#endif
250 bool includeMultis);
251
252 // Each command is assigned a numerical ID for use in wxMenu and wxEvent,
253 // which need not be the same across platforms or sessions
254 CommandID GetNameFromNumericID( int id );
255
256 TranslatableString GetLabelFromName(const CommandID &name);
257 TranslatableString GetPrefixedLabelFromName(const CommandID &name);
258 TranslatableString GetCategoryFromName(const CommandID &name);
259 NormalizedKeyString GetKeyFromName(const CommandID &name) const;
260 NormalizedKeyString GetDefaultKeyFromName(const CommandID &name);
261
262 bool GetEnabled(const CommandID &name);
263 int GetNumberOfKeysRead() const;
264
265#if defined(_DEBUG)
266 void CheckDups();
267#endif
268 void RemoveDuplicateShortcuts();
269
270 //
271 // Loading/Saving
272 //
273
274 void WriteXML(XMLWriter &xmlFile) const /* not override */;
275
279 TranslatableString DescribeCommandsAndShortcuts
280 (
281 // If a shortcut key is defined for the command, then it is appended,
282 // parenthesized, after the translated name.
283 const ComponentInterfaceSymbol commands[], size_t nCommands) const;
284
285 // Sorted list of the shortcut keys to be excluded from the standard defaults
286 static const std::vector<NormalizedKeyString> &ExcludedList();
287
288private:
289
290 //
291 // Creating menus and adding commands
292 //
293
294 int NextIdentifier(int ID);
295 CommandListEntry *NewIdentifier(const CommandID & name,
297 wxMenu *menu,
299 CommandFunctorPointer callback,
300 const CommandID &nameSuffix,
301 int index,
302 int count,
303 const Options &options);
304
305 void AddGlobalCommand(const CommandID &name,
308 CommandFunctorPointer callback,
309 const Options &options = {});
310
311 //
312 // Executing commands
313 //
314
315 bool HandleCommandEntry(AudacityProject &project,
316 const CommandListEntry * entry, CommandFlag flags,
317 bool alwaysEnabled, const wxEvent * evt = nullptr,
318 const CommandContext *pGivenContext = nullptr );
319
320 //
321 // Modifying
322 //
323
324 void Enable(CommandListEntry *entry, bool enabled);
325 wxMenu *BeginMainMenu(const TranslatableString & tName);
326 void EndMainMenu();
327 wxMenu* BeginSubMenu(const TranslatableString & tName);
328 void EndSubMenu();
329
330 //
331 // Accessing
332 //
333
334 wxMenuBar * CurrentMenuBar() const;
335 wxMenuBar * GetMenuBar(const wxString & sMenu) const;
336 wxMenu * CurrentSubMenu() const;
337public:
338 wxMenu * CurrentMenu() const;
339
340 void UpdateCheckmarks( AudacityProject &project );
341
343
347 wxString FormatLabelForMenu(
348 const CommandID &id, const TranslatableString *pLabel) const;
349
350private:
351 wxString FormatLabelForMenu(const CommandListEntry *entry) const;
352 wxString FormatLabelForMenu(
353 const TranslatableString &translatableLabel,
354 const NormalizedKeyString &keyStr) const;
355 wxString FormatLabelWithDisabledAccel(const CommandListEntry *entry) const;
356
357 //
358 // Loading/Saving
359 //
360
361 bool HandleXMLTag(const std::string_view& tag, const AttributesList &attrs) override;
362 void HandleXMLEndTag(const std::string_view& tag) override;
363 XMLTagHandler *HandleXMLChild(const std::string_view& tag) override;
364
365private:
366 // mMaxList only holds shortcuts that should not be added (by default)
367 // and is sorted.
368 std::vector<NormalizedKeyString> mMaxListOnly;
369
378
379 bool mbSeparatorAllowed; // false at the start of a menu and immediately after a separator.
380
384 std::unique_ptr<wxMenu> uCurrentMenu;
385 wxMenu *mCurrentMenu {};
386
388 std::unique_ptr< wxMenuBar > mTempMenuBar;
389};
390
391struct AUDACITY_DLL_API MenuVisitor : Registry::Visitor
392{
393 // final overrides
394 void BeginGroup( Registry::GroupItem &item, const Path &path ) final;
395 void EndGroup( Registry::GroupItem &item, const Path& ) final;
396 void Visit( Registry::SingleItem &item, const Path &path ) final;
397
398 // added virtuals
399 virtual void DoBeginGroup( Registry::GroupItem &item, const Path &path );
400 virtual void DoEndGroup( Registry::GroupItem &item, const Path &path );
401 virtual void DoVisit( Registry::SingleItem &item, const Path &path );
402 virtual void DoSeparator();
403
404private:
405 void MaybeDoSeparator();
406 std::vector<bool> firstItem;
407 std::vector<bool> needSeparator;
408};
409
411{
413 operator AudacityProject & () const { return project; }
415};
416
417// Define items that populate tables that specifically describe menu trees
418namespace MenuTable {
419 using namespace Registry;
420
421 // These are found by dynamic_cast
422 struct AUDACITY_DLL_API MenuSection {
423 virtual ~MenuSection();
424 };
425 struct AUDACITY_DLL_API WholeMenu {
426 WholeMenu( bool extend = false ) : extension{ extend } {}
427 virtual ~WholeMenu();
429 };
430
431 // Describes a main menu in the toolbar, or a sub-menu
432 struct AUDACITY_DLL_API MenuItem final
433 : ConcreteGroupItem< false, ToolbarMenuVisitor >
434 , WholeMenu {
435 // Construction from an internal name and a previously built-up
436 // vector of pointers
437 MenuItem( const Identifier &internalName,
438 const TranslatableString &title_, BaseItemPtrs &&items_ );
439 // In-line, variadic constructor that doesn't require building a vector
440 template< typename... Args >
441 MenuItem( const Identifier &internalName,
442 const TranslatableString &title_, Args&&... args )
444 internalName, std::forward<Args>(args)... }
445 , title{ title_ }
446 {}
447 ~MenuItem() override;
448
450 };
451
452 // Collects other items that are conditionally shown or hidden, but are
453 // always available to macro programming
455 : ConcreteGroupItem< false, ToolbarMenuVisitor > {
456 using Condition = std::function< bool() >;
457
458 // Construction from an internal name and a previously built-up
459 // vector of pointers
460 ConditionalGroupItem( const Identifier &internalName,
461 Condition condition_, BaseItemPtrs &&items_ );
462 // In-line, variadic constructor that doesn't require building a vector
463 template< typename... Args >
464 ConditionalGroupItem( const Identifier &internalName,
465 Condition condition_, Args&&... args )
467 internalName, std::forward<Args>(args)... }
468 , condition{ condition_ }
469 {}
470 ~ConditionalGroupItem() override;
471
473 };
474
475 // usage:
476 // auto scope = FinderScope( findCommandHandler );
477 // return Items( ... );
478 //
479 // or:
480 // return ( FinderScope( findCommandHandler ), Items( ... ) );
481 //
482 // where findCommandHandler names a function.
483 // This is used before a sequence of many calls to Command() and
484 // CommandGroup(), so that the finder argument need not be specified
485 // in each call.
486 class AUDACITY_DLL_API FinderScope : ValueRestorer< CommandHandlerFinder >
487 {
489
490 public:
492 static CommandHandlerFinder DefaultFinder() { return sFinder; }
493
495 explicit
497 : ValueRestorer( sFinder, finder )
498 { assert(finder); }
499 };
500
501 // Describes one command in a menu
502 struct AUDACITY_DLL_API CommandItem final : SingleItem {
503 CommandItem(const CommandID &name_,
504 const TranslatableString &label_in_,
505 CommandFunctorPointer callback_,
506 CommandFlag flags_,
507 const CommandManager::Options &options_,
508 CommandHandlerFinder finder_);
509
510 // Takes a pointer to member function directly, and delegates to the
511 // previous constructor; useful within the lifetime of a FinderScope
515 template< typename Handler >
516 CommandItem(const CommandID &name_,
517 const TranslatableString &label_in_,
518 void (Handler::*pmf)(const CommandContext&),
519 CommandFlag flags_,
520 const CommandManager::Options &options_,
522 : CommandItem(name_, label_in_,
524 static_cast<CommandFunctorPointer::MemberFn>(pmf) },
525 flags_, options_, finder)
526 { assert(finder); }
527
528 // Takes a pointer to nonmember function and delegates to the first
529 // constructor
530 CommandItem(const CommandID &name_,
531 const TranslatableString &label_in_,
533 CommandFlag flags_,
534 const CommandManager::Options &options_)
535 : CommandItem(name_, label_in_,
536 CommandFunctorPointer{ callback_ },
537 flags_, options_, nullptr)
538 {}
539
540 ~CommandItem() override;
541
547 };
548
549 // Describes several successive commands in a menu that are closely related
550 // and dispatch to one common callback, which will be passed a number
551 // in the CommandContext identifying the command
552 struct AUDACITY_DLL_API CommandGroupItem final : SingleItem {
553 CommandGroupItem(const Identifier &name_,
554 std::vector< ComponentInterfaceSymbol > items_,
555 CommandFunctorPointer callback_,
556 CommandFlag flags_,
557 bool isEffect_,
558 CommandHandlerFinder finder_);
559
560 // Takes a pointer to member function directly, and delegates to the
561 // previous constructor; useful within the lifetime of a FinderScope
565 template< typename Handler >
567 std::vector< ComponentInterfaceSymbol > items_,
568 void (Handler::*pmf)(const CommandContext&),
569 CommandFlag flags_,
570 bool isEffect_,
572 : CommandGroupItem(name_, move(items_),
574 static_cast<CommandFunctorPointer::MemberFn>(pmf) },
575 flags_, isEffect_, finder)
576 { assert(finder); }
577
578 // Takes a pointer to nonmember function and delegates to the first
579 // constructor
581 std::vector< ComponentInterfaceSymbol > items_,
583 CommandFlag flags_,
584 bool isEffect_)
585 : CommandGroupItem(name_, move(items_),
587 flags_, isEffect_, nullptr)
588 {}
589
590 ~CommandGroupItem() override;
591
592 const std::vector<ComponentInterfaceSymbol> items;
597 };
598
599 // For manipulating the enclosing menu or sub-menu directly,
600 // adding any number of items, not using the CommandManager
601 struct SpecialItem final : SingleItem
602 {
603 using Appender = std::function< void( AudacityProject&, wxMenu& ) >;
604
605 explicit SpecialItem( const Identifier &internalName, const Appender &fn_ )
606 : SingleItem{ internalName }
607 , fn{ fn_ }
608 {}
609 ~SpecialItem() override;
610
612 };
613
614 struct MenuPart : ConcreteGroupItem< false, ToolbarMenuVisitor >, MenuSection
615 {
616 template< typename... Args >
617 explicit
618 MenuPart( const Identifier &internalName, Args&&... args )
620 internalName, std::forward< Args >( args )... }
621 {}
622 };
624
625 // The following, and Shared(), are the functions to use directly
626 // in writing table definitions.
627
628 // Group items can be constructed two ways.
629 // Pointers to subordinate items are moved into the result.
630 // Null pointers are permitted, and ignored when building the menu.
631 // Items are spliced into the enclosing menu.
632 // The name is untranslated and may be empty, to make the group transparent
633 // in identification of items by path. Otherwise try to keep the name
634 // stable across Audacity versions.
635 template< typename... Args >
636 inline std::unique_ptr< MenuItems > Items(
637 const Identifier &internalName, Args&&... args )
638 { return std::make_unique< MenuItems >(
639 internalName, std::forward<Args>(args)... ); }
640
641 // Like Items, but insert a menu separator between the menu section and
642 // any other items or sections before or after it in the same (innermost,
643 // enclosing) menu.
644 // It's not necessary that the sisters of sections be other sections, but it
645 // might clarify the logical groupings.
646 template< typename... Args >
647 inline std::unique_ptr< MenuPart > Section(
648 const Identifier &internalName, Args&&... args )
649 { return std::make_unique< MenuPart >(
650 internalName, std::forward<Args>(args)... ); }
651
652 // Menu items can be constructed two ways, as for group items
653 // Items will appear in a main toolbar menu or in a sub-menu.
654 // The name is untranslated. Try to keep the name stable across Audacity
655 // versions.
656 // If the name of a menu is empty, then subordinate items cannot be located
657 // by path.
658 template< typename... Args >
659 inline std::unique_ptr<MenuItem> Menu(
660 const Identifier &internalName, const TranslatableString &title, Args&&... args )
661 { return std::make_unique<MenuItem>(
662 internalName, title, std::forward<Args>(args)... ); }
663 inline std::unique_ptr<MenuItem> Menu(
664 const Identifier &internalName, const TranslatableString &title, BaseItemPtrs &&items )
665 { return std::make_unique<MenuItem>(
666 internalName, title, std::move( items ) ); }
667
668 // Conditional group items can be constructed two ways, as for group items
669 // These items register in the CommandManager but are not shown in menus
670 // if the condition evaluates false.
671 // The name is untranslated. Try to keep the name stable across Audacity
672 // versions.
673 // Name for conditional group must be non-empty.
674 template< typename... Args >
675 inline std::unique_ptr<ConditionalGroupItem> ConditionalItems(
676 const Identifier &internalName,
677 ConditionalGroupItem::Condition condition, Args&&... args )
678 { return std::make_unique<ConditionalGroupItem>(
679 internalName, condition, std::forward<Args>(args)... ); }
680 inline std::unique_ptr<ConditionalGroupItem> ConditionalItems(
681 const Identifier &internalName, ConditionalGroupItem::Condition condition,
682 BaseItemPtrs &&items )
683 { return std::make_unique<ConditionalGroupItem>(
684 internalName, condition, std::move( items ) ); }
685
686 // Make either a menu item or just a group, depending on the nonemptiness
687 // of the title.
688 // The name is untranslated and may be empty, to make the group transparent
689 // in identification of items by path. Otherwise try to keep the name
690 // stable across Audacity versions.
691 // If the name of a menu is empty, then subordinate items cannot be located
692 // by path.
693 template< typename... Args >
695 const Identifier &internalName, const TranslatableString &title, Args&&... args )
696 { if ( title.empty() )
697 return Items( internalName, std::forward<Args>(args)... );
698 else
699 return std::make_unique<MenuItem>(
700 internalName, title, std::forward<Args>(args)... ); }
702 const Identifier &internalName,
703 const TranslatableString &title, BaseItemPtrs &&items )
704 { if ( title.empty() )
705 return Items( internalName, std::move( items ) );
706 else
707 return std::make_unique<MenuItem>(
708 internalName, title, std::move( items ) ); }
709
713 template< typename Handler >
714 inline std::unique_ptr<CommandItem> Command(
715 const CommandID &name,
716 const TranslatableString &label_in,
717 void (Handler::*pmf)(const CommandContext&),
718 CommandFlag flags, const CommandManager::Options &options = {},
720 {
721 assert(finder);
722 return std::make_unique<CommandItem>(
723 name, label_in, pmf, flags, options, finder
724 );
725 }
726
727 inline std::unique_ptr<CommandItem> Command(
728 const CommandID &name,
729 const TranslatableString &label_in,
730 void (*fn)(const CommandContext&),
731 CommandFlag flags, const CommandManager::Options &options = {})
732 {
733 return std::make_unique<CommandItem>(
734 name, label_in, fn, flags, options
735 );
736 }
737
741 template< typename Handler >
742 inline std::unique_ptr<CommandGroupItem> CommandGroup(
743 const Identifier &name,
744 std::vector< ComponentInterfaceSymbol > items,
745 void (Handler::*pmf)(const CommandContext&),
746 CommandFlag flags, bool isEffect = false,
748 {
749 assert(finder);
750 return std::make_unique<CommandGroupItem>(
751 name, move(items), pmf, flags, isEffect, finder
752 );
753 }
754
755 inline std::unique_ptr<CommandGroupItem> CommandGroup(
756 const Identifier &name,
757 std::vector< ComponentInterfaceSymbol > items,
758 void (*fn)(const CommandContext&),
759 CommandFlag flags, bool isEffect = false)
760 {
761 return std::make_unique<CommandGroupItem>(
762 name, move(items), fn, flags, isEffect
763 );
764 }
765
766 inline std::unique_ptr<SpecialItem> Special(
767 const Identifier &name, const SpecialItem::Appender &fn )
768 { return std::make_unique<SpecialItem>( name, fn ); }
769
771 static GroupItem &Registry();
772 };
773
774 // Typically you make a static object of this type in the .cpp file that
775 // also defines the added menu actions.
776 // pItem can be specified by an expression using the inline functions above.
777 struct AUDACITY_DLL_API AttachedItem final
778 : public RegisteredItem<BaseItem, ItemRegistry>
779 {
780 AttachedItem( const Placement &placement, BaseItemPtr pItem );
781
782 AttachedItem( const wxString &path, BaseItemPtr pItem )
783 // Delegating constructor
784 : AttachedItem( Placement{ path }, std::move( pItem ) )
785 {}
786 };
787
788 void DestroyRegistry();
789
790}
791
792#endif
wxT("CloseDown"))
Utility ClientData::Site to register hooks into a host class that attach client data.
std::bitset< NCommandFlags > CommandFlag
Definition: CommandFlag.h:30
std::function< CommandHandlerObject &(AudacityProject &) > CommandHandlerFinder
static const AudacityProject::AttachedObjects::RegisteredFactory key
std::unordered_map< CommandID, CommandListEntry * > CommandNameHash
std::unordered_map< int, CommandListEntry * > CommandNumericIDHash
std::unordered_map< NormalizedKeyString, CommandListEntry * > CommandKeyHash
const TranslatableString name
Definition: Distortion.cpp:76
std::vector< CommandID > CommandIDs
Definition: Identifier.h:233
TaggedIdentifier< CommandIdTag, false > CommandID
Identifies a menu command or macro. Case-insensitive comparison.
Definition: Identifier.h:232
auto Visit(Visitor &&vis, Variant &&var)
Mimic some of std::visit, for the case of one visitor only.
Definition: MemoryX.h:628
static const auto title
static ProjectFileIORegistry::AttributeWriterEntry entry
TranslatableString label
Definition: TagsEditor.cpp:164
static TranslatableStrings names
Definition: TagsEditor.cpp:152
std::vector< TranslatableString > TranslatableStrings
static const auto fn
std::vector< Attribute > AttributesList
Definition: XMLTagHandler.h:40
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:339
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
List of CommandListEntry.
CommandManager implements a system for organizing all user-callable commands.
CommandList mCommandList
CommandNameHash mCommandNameHash
std::unique_ptr< wxMenuBar > mTempMenuBar
TranslatableString mCurrentMenuName
MenuBarList mMenuBarList
SubMenuList mSubMenuList
std::vector< NormalizedKeyString > mMaxListOnly
std::unique_ptr< wxMenu > uCurrentMenu
bool bMakingOccultCommands
CommandKeyHash mCommandKeyHash
std::function< bool(AudacityProject &) > CheckFn
CommandManager(const CommandManager &) PROHIBITED
TranslatableString mNiceName
CommandNumericIDHash mCommandNumericIDHash
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Global function-valued variable, adding a convenient Call()
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
List of MenuBarListEntry.
static CommandHandlerFinder DefaultFinder()
FinderScope(CommandHandlerFinder finder)
static CommandHandlerFinder sFinder
Generates classes whose instances register items at construction.
Definition: Registry.h:245
std::vector< Identifier > Path
Definition: Registry.h:262
List of SubMenuListEntry.
Holds a msgid for the translation catalog; may also bind format arguments.
Set a variable temporarily in a scope.
Definition: MemoryX.h:212
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:42
virtual XMLTagHandler * HandleXMLChild(const std::string_view &tag)=0
virtual void HandleXMLEndTag(const std::string_view &WXUNUSED(tag))
Definition: XMLTagHandler.h:59
virtual bool HandleXMLTag(const std::string_view &tag, const AttributesList &attrs)=0
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:25
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196
AUDACITY_DLL_API bool HandleTextualCommand(CommandManager &commandManager, const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)
std::unique_ptr< MenuItem > Menu(const Identifier &internalName, const TranslatableString &title, Args &&... args)
std::unique_ptr< MenuPart > Section(const Identifier &internalName, Args &&... args)
void DestroyRegistry()
Definition: Menus.cpp:266
std::unique_ptr< CommandGroupItem > CommandGroup(const Identifier &name, std::vector< ComponentInterfaceSymbol > items, void(Handler::*pmf)(const CommandContext &), CommandFlag flags, bool isEffect=false, CommandHandlerFinder finder=FinderScope::DefaultFinder())
std::unique_ptr< ConditionalGroupItem > ConditionalItems(const Identifier &internalName, ConditionalGroupItem::Condition condition, Args &&... args)
std::unique_ptr< MenuItems > Items(const Identifier &internalName, Args &&... args)
std::unique_ptr< CommandItem > Command(const CommandID &name, const TranslatableString &label_in, void(Handler::*pmf)(const CommandContext &), CommandFlag flags, const CommandManager::Options &options={}, CommandHandlerFinder finder=FinderScope::DefaultFinder())
std::unique_ptr< SpecialItem > Special(const Identifier &name, const SpecialItem::Appender &fn)
BaseItemPtr MenuOrItems(const Identifier &internalName, const TranslatableString &title, Args &&... args)
Definition: Menus.h:35
std::unique_ptr< BaseItem > BaseItemPtr
Definition: Registry.h:71
std::vector< BaseItemPtr > BaseItemPtrs
Definition: Registry.h:73
STL namespace.
A convenient default parameter for class template Site.
Definition: ClientData.h:28
CommandListEntry is a structure used by CommandManager.
Options && CheckTest(const BoolSetting &setting) &&
Options && CheckTest(const wxChar *key, bool defaultValue) &&
Options && UseStrictFlags() &&
Options && CheckTest(const CheckFn &fn) &&
Options(const wxChar *accel_)
Options && AllowDup() &&
Options(const wxChar *accel_, const TranslatableString &longName_)
Options && WantKeyUp() &&
Options && IsGlobal() &&
Options && Accel(const wxChar *value) &&
Options && IsEffect(bool value=true) &&
Options && SkipKeyDown() &&
Options && Parameter(const CommandParameter &value) &&
Options && LongName(const TranslatableString &value) &&
Options && AllowInMacros(int value=1) &&
MenuBarListEntry is a structure used by CommandManager.
AttachedItem(const wxString &path, BaseItemPtr pItem)
const std::vector< ComponentInterfaceSymbol > items
CommandHandlerFinder finder
CommandGroupItem(const CommandID &name_, std::vector< ComponentInterfaceSymbol > items_, CommandFunctorPointer::NonMemberFn fn_, CommandFlag flags_, bool isEffect_)
CommandFunctorPointer callback
CommandGroupItem(const Identifier &name_, std::vector< ComponentInterfaceSymbol > items_, void(Handler::*pmf)(const CommandContext &), CommandFlag flags_, bool isEffect_, CommandHandlerFinder finder=FinderScope::DefaultFinder())
const TranslatableString label_in
CommandHandlerFinder finder
CommandFunctorPointer callback
CommandItem(const CommandID &name_, const TranslatableString &label_in_, void(Handler::*pmf)(const CommandContext &), CommandFlag flags_, const CommandManager::Options &options_, CommandHandlerFinder finder=FinderScope::DefaultFinder())
CommandManager::Options options
CommandItem(const CommandID &name_, const TranslatableString &label_in_, CommandFunctorPointer::NonMemberFn callback_, CommandFlag flags_, const CommandManager::Options &options_)
std::function< bool() > Condition
ConditionalGroupItem(const Identifier &internalName, Condition condition_, BaseItemPtrs &&items_)
Definition: Menus.cpp:194
ConditionalGroupItem(const Identifier &internalName, Condition condition_, Args &&... args)
static GroupItem & Registry()
Definition: Menus.cpp:254
MenuItem(const Identifier &internalName, const TranslatableString &title_, Args &&... args)
TranslatableString title
MenuPart(const Identifier &internalName, Args &&... args)
~SpecialItem() override
Definition: Menus.cpp:226
SpecialItem(const Identifier &internalName, const Appender &fn_)
std::function< void(AudacityProject &, wxMenu &) > Appender
WholeMenu(bool extend=false)
std::vector< bool > firstItem
std::vector< bool > needSeparator
SubMenuListEntry is a structure used by CommandManager.
AudacityProject & project
ToolbarMenuVisitor(AudacityProject &p)
void(*)(const CommandContext &context) NonMemberFn