12#ifndef __AUDACITY_COMMAND_MANAGER__
13#define __AUDACITY_COMMAND_MANAGER__
31#include <unordered_map>
49using CommandList = std::vector<std::unique_ptr<CommandListEntry>>;
51using CommandKeyHash = std::unordered_map<NormalizedKeyString, CommandListEntry*>;
69 bool(const CommandID&)
89 std::unique_ptr<wxMenuBar> AddMenuBar(
const wxString & sMenu);
103 Options(
const wxChar *accel_ ) : accel{ accel_ } {}
106 const wxChar *accel_,
108 : accel{ accel_ }, longName{ longName_ } {}
111 { accel = value;
return std::move(*
this); }
113 { bIsEffect = value;
return std::move(*
this); }
115 { parameter = value;
return std::move(*
this); }
117 { longName = value;
return std::move(*
this); }
119 { global =
true;
return std::move(*
this); }
121 { useStrictFlags =
true;
return std::move(*
this); }
123 { wantKeyUp =
true;
return std::move(*
this); }
125 { skipKeyDown =
true;
return std::move(*
this); }
129 { allowDup =
true;
return std::move(*
this); }
132 { allowInMacros = value;
return std::move(*
this); }
137 { checker =
fn;
return std::move(*
this); }
140 checker = MakeCheckFn(
key, defaultValue );
141 return std::move(*
this);
145 checker = MakeCheckFn( setting );
146 return std::move(*
this);
149 const wxChar *accel{ wxT(
"") };
151 bool bIsEffect{
false };
154 bool global{
false };
155 bool useStrictFlags{
false };
156 bool wantKeyUp{
false };
157 bool skipKeyDown{
false };
158 bool allowDup{
false };
159 int allowInMacros{ -1 };
163 MakeCheckFn(
const wxString
key,
bool defaultValue );
174 bool bIsEffect =
false);
187 void BeginOccultCommands();
188 void EndOccultCommands();
197 void EnableUsingFlags(
199 void Enable(
const wxString &
name,
bool enabled);
216 bool FilterKeyEvent(
AudacityProject *project,
const wxKeyEvent & evt,
bool permit =
false);
238 void GetAllCommandLabels(
240 bool includeMultis)
const;
241 void GetAllCommandData(
243 std::vector<NormalizedKeyString> &keys,
244 std::vector<NormalizedKeyString> &default_keys,
246#
if defined(EXPERIMENTAL_KEY_VIEW)
253 CommandID GetNameFromNumericID(
int id );
262 int GetNumberOfKeysRead()
const;
267 void RemoveDuplicateShortcuts();
273 void WriteXML(
XMLWriter &xmlFile)
const ;
285 static const std::vector<NormalizedKeyString> &ExcludedList();
293 int NextIdentifier(
int ID);
316 bool alwaysEnabled,
const wxEvent * evt =
nullptr,
333 wxMenuBar * CurrentMenuBar()
const;
334 wxMenuBar * GetMenuBar(
const wxString & sMenu)
const;
335 wxMenu * CurrentSubMenu()
const;
337 wxMenu * CurrentMenu()
const;
346 wxString FormatLabelForMenu(
351 wxString FormatLabelForMenu(
384 wxMenu *mCurrentMenu {};
401 virtual void DoSeparator();
404 void MaybeDoSeparator();
425 WholeMenu(
bool extend =
false ) : extension{ extend } {}
439 template<
typename... Args >
443 internalName, std::forward<Args>(args)... }
446 ~MenuItem()
override;
462 template<
typename... Args >
466 internalName, std::forward<Args>(args)... }
509 template<
typename Handler >
518 flags_, options_, finder)
535 std::vector< ComponentInterfaceSymbol > items_,
543 template<
typename Handler >
545 std::vector< ComponentInterfaceSymbol > items_,
552 flags_, isEffect_, finder)
557 const std::vector<ComponentInterfaceSymbol>
items;
581 template<
typename... Args >
585 internalName, std::forward< Args >( args )... }
600 template<
typename... Args >
601 inline std::unique_ptr< MenuItems >
Items(
602 const Identifier &internalName, Args&&... args )
603 {
return std::make_unique< MenuItems >(
604 internalName, std::forward<Args>(args)... ); }
611 template<
typename... Args >
613 const Identifier &internalName, Args&&... args )
614 {
return std::make_unique< MenuPart >(
615 internalName, std::forward<Args>(args)... ); }
623 template<
typename... Args >
624 inline std::unique_ptr<MenuItem>
Menu(
626 {
return std::make_unique<MenuItem>(
627 internalName,
title, std::forward<Args>(args)... ); }
628 inline std::unique_ptr<MenuItem>
Menu(
630 {
return std::make_unique<MenuItem>(
631 internalName,
title, std::move( items ) ); }
639 template<
typename... Args >
643 {
return std::make_unique<ConditionalGroupItem>(
644 internalName, condition, std::forward<Args>(args)... ); }
648 {
return std::make_unique<ConditionalGroupItem>(
649 internalName, condition, std::move( items ) ); }
658 template<
typename... Args >
661 {
if (
title.empty() )
662 return Items( internalName, std::forward<Args>(args)... );
664 return std::make_unique<MenuItem>(
665 internalName,
title, std::forward<Args>(args)... ); }
669 {
if (
title.empty() )
670 return Items( internalName, std::move( items ) );
672 return std::make_unique<MenuItem>(
673 internalName,
title, std::move( items ) ); }
675 template<
typename Handler >
683 return std::make_unique<CommandItem>(
684 name, label_in, pmf, flags, options, finder
688 template<
typename Handler >
691 std::vector< ComponentInterfaceSymbol > items,
696 return std::make_unique<CommandGroupItem>(
697 name, std::move(items), pmf, flags, isEffect, finder
703 {
return std::make_unique<SpecialItem>(
name,
fn ); }
Utility ClientData::Site to register hooks into a host class that attach client data.
bool HandleTextualCommand(CommandManager &commandManager, const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)
std::bitset< NCommandFlags > CommandFlag
void(CommandHandlerObject::*)(const CommandContext &context) CommandFunctorPointer
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
std::vector< CommandID > CommandIDs
TaggedIdentifier< CommandIdTag, false > CommandID
Identifies a menu command or macro. Case-insensitive comparison.
auto Visit(Visitor &&vis, Variant &&var)
Mimic some of std::visit, for the case of one visitor only.
static ProjectFileIORegistry::AttributeWriterEntry entry
std::vector< TranslatableString > TranslatableStrings
std::vector< Attribute > AttributesList
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
This specialization of Setting for bool adds a Toggle method to negate the saved value.
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.
CommandNameHash mCommandNameHash
std::unique_ptr< wxMenuBar > mTempMenuBar
TranslatableString mCurrentMenuName
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.
std::vector< Identifier > Path
Holds a msgid for the translation catalog; may also bind format arguments.
Set a variable temporarily in a scope.
This class is an interface which should be implemented by classes which wish to be able to load and s...
virtual XMLTagHandler * HandleXMLChild(const std::string_view &tag)=0
virtual void HandleXMLEndTag(const std::string_view &WXUNUSED(tag))
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...
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
std::unique_ptr< BaseItem > BaseItemPtr
std::vector< BaseItemPtr > BaseItemPtrs
A convenient default parameter for class template Site.
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(const wxChar *accel_, const TranslatableString &longName_)
Options && WantKeyUp() &&
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) &&
const std::vector< ComponentInterfaceSymbol > items
CommandHandlerFinder finder
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