12#ifndef __AUDACITY_COMMAND_MANAGER__
13#define __AUDACITY_COMMAND_MANAGER__
32#include <unordered_map>
50using CommandList = std::vector<std::unique_ptr<CommandListEntry>>;
52using CommandKeyHash = std::unordered_map<NormalizedKeyString, CommandListEntry*>;
70 bool(const CommandID&)
90 std::unique_ptr<wxMenuBar> AddMenuBar(
const wxString & sMenu);
104 Options(
const wxChar *accel_ ) : accel{ accel_ } {}
107 const wxChar *accel_,
109 : accel{ accel_ }, longName{ longName_ } {}
112 { accel = value;
return std::move(*
this); }
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); }
130 { allowDup =
true;
return std::move(*
this); }
133 { allowInMacros = value;
return std::move(*
this); }
138 { checker =
fn;
return std::move(*
this); }
141 checker = MakeCheckFn(
key, defaultValue );
142 return std::move(*
this);
146 checker = MakeCheckFn( setting );
147 return std::move(*
this);
150 const wxChar *accel{
wxT(
"") };
152 bool bIsEffect{
false };
155 bool global{
false };
156 bool useStrictFlags{
false };
157 bool wantKeyUp{
false };
158 bool skipKeyDown{
false };
159 bool allowDup{
false };
160 int allowInMacros{ -1 };
164 MakeCheckFn(
const wxString
key,
bool defaultValue );
175 bool bIsEffect =
false);
188 void BeginOccultCommands();
189 void EndOccultCommands();
198 void EnableUsingFlags(
200 void Enable(
const wxString &
name,
bool enabled);
217 bool FilterKeyEvent(
AudacityProject *project,
const wxKeyEvent & evt,
bool permit =
false);
239 void GetAllCommandLabels(
241 bool includeMultis)
const;
242 void GetAllCommandData(
244 std::vector<NormalizedKeyString> &keys,
245 std::vector<NormalizedKeyString> &default_keys,
247#
if defined(EXPERIMENTAL_KEY_VIEW)
254 CommandID GetNameFromNumericID(
int id );
263 int GetNumberOfKeysRead()
const;
268 void RemoveDuplicateShortcuts();
274 void WriteXML(
XMLWriter &xmlFile)
const ;
286 static const std::vector<NormalizedKeyString> &ExcludedList();
294 int NextIdentifier(
int ID);
317 bool alwaysEnabled,
const wxEvent * evt =
nullptr,
334 wxMenuBar * CurrentMenuBar()
const;
335 wxMenuBar * GetMenuBar(
const wxString & sMenu)
const;
336 wxMenu * CurrentSubMenu()
const;
338 wxMenu * CurrentMenu()
const;
347 wxString FormatLabelForMenu(
352 wxString FormatLabelForMenu(
385 wxMenu *mCurrentMenu {};
402 virtual void DoSeparator();
405 void MaybeDoSeparator();
426 WholeMenu(
bool extend =
false ) : extension{ extend } {}
440 template<
typename... Args >
444 internalName, std::forward<Args>(args)... }
447 ~MenuItem()
override;
463 template<
typename... Args >
467 internalName, std::forward<Args>(args)... }
515 template<
typename Handler >
525 flags_, options_, finder)
537 flags_, options_, nullptr)
554 std::vector< ComponentInterfaceSymbol > items_,
565 template<
typename Handler >
567 std::vector< ComponentInterfaceSymbol > items_,
575 flags_, isEffect_, finder)
581 std::vector< ComponentInterfaceSymbol > items_,
587 flags_, isEffect_, nullptr)
592 const std::vector<ComponentInterfaceSymbol>
items;
616 template<
typename... Args >
620 internalName, std::forward< Args >( args )... }
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)... ); }
646 template<
typename... Args >
648 const Identifier &internalName, Args&&... args )
649 {
return std::make_unique< MenuPart >(
650 internalName, std::forward<Args>(args)... ); }
658 template<
typename... Args >
659 inline std::unique_ptr<MenuItem>
Menu(
661 {
return std::make_unique<MenuItem>(
662 internalName,
title, std::forward<Args>(args)... ); }
663 inline std::unique_ptr<MenuItem>
Menu(
665 {
return std::make_unique<MenuItem>(
666 internalName,
title, std::move( items ) ); }
674 template<
typename... Args >
678 {
return std::make_unique<ConditionalGroupItem>(
679 internalName, condition, std::forward<Args>(args)... ); }
683 {
return std::make_unique<ConditionalGroupItem>(
684 internalName, condition, std::move( items ) ); }
693 template<
typename... Args >
696 {
if (
title.empty() )
697 return Items( internalName, std::forward<Args>(args)... );
699 return std::make_unique<MenuItem>(
700 internalName,
title, std::forward<Args>(args)... ); }
704 {
if (
title.empty() )
705 return Items( internalName, std::move( items ) );
707 return std::make_unique<MenuItem>(
708 internalName,
title, std::move( items ) ); }
713 template<
typename Handler >
722 return std::make_unique<CommandItem>(
723 name, label_in, pmf, flags, options, finder
733 return std::make_unique<CommandItem>(
734 name, label_in,
fn, flags, options
741 template<
typename Handler >
744 std::vector< ComponentInterfaceSymbol > items,
750 return std::make_unique<CommandGroupItem>(
751 name, move(items), pmf, flags, isEffect, finder
757 std::vector< ComponentInterfaceSymbol > items,
761 return std::make_unique<CommandGroupItem>(
762 name, move(items),
fn, flags, isEffect
768 {
return std::make_unique<SpecialItem>(
name,
fn ); }
Utility ClientData::Site to register hooks into a host class that attach client data.
std::bitset< NCommandFlags > CommandFlag
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.
Generates classes whose instances register items at construction.
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.
AUDACITY_DLL_API bool HandleTextualCommand(CommandManager &commandManager, const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)
std::unique_ptr< BaseItem > BaseItemPtr
std::vector< BaseItemPtr > BaseItemPtrs
CommandManager::Options Options
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
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_)
void(*)(const CommandContext &context) NonMemberFn