Audacity 3.2.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
CommandManager Class Reference

CommandManager implements a system for organizing all user-callable commands. More...

#include <CommandManager.h>

Inheritance diagram for CommandManager:
[legend]
Collaboration diagram for CommandManager:
[legend]

Classes

struct  CommandListEntry
 
struct  Factory
 
struct  GlobalMenuHook
 
struct  Populator
 

Public Types

enum  { repeattypenone = 0 , repeattypeplugin = 1 , repeattypeunique = 2 , repeattypeapplymacro = 3 }
 
enum  TextualCommandResult { CommandFailure , CommandSuccess , CommandNotFound }
 
- Public Types inherited from Observer::Publisher< MenuUpdateMessage >
using message_type = MenuUpdateMessage
 
using CallbackReturn = std::conditional_t< true, void, bool >
 
using Callback = std::function< CallbackReturn(const MenuUpdateMessage &) >
 Type of functions that can be connected to the Publisher. More...
 

Public Member Functions

 CommandManager (AudacityProject &project)
 
 CommandManager (const CommandManager &)=delete
 
CommandManageroperator= (const CommandManager &)=delete
 
 ~CommandManager () override
 
CommandFlag GetUpdateFlags (bool quick=false) const
 
void UpdatePrefs () override
 
bool ReportIfActionNotAllowed (const TranslatableString &Name, CommandFlag &flags, CommandFlag flagsRqd)
 
bool TryToMakeActionAllowed (CommandFlag &flags, CommandFlag flagsRqd)
 
AudacityProjectGetProject ()
 
size_t NCommands () const
 
void PurgeData ()
 
void SetCommandFlags (const CommandID &name, CommandFlag flags)
 
void EnableUsingFlags (CommandFlag flags, CommandFlag strictFlags)
 
void Enable (const wxString &name, bool enabled)
 
void Check (const CommandID &name, bool checked)
 
void Modify (const wxString &name, const TranslatableString &newLabel)
 Changes the label text of a menu item. More...
 
void SetKeyFromName (const CommandID &name, const NormalizedKeyString &key)
 
void SetKeyFromIndex (int i, const NormalizedKeyString &key)
 
bool HandleMenuID (int id, CommandFlag flags, bool alwaysEnabled)
 
void RegisterLastAnalyzer (const CommandContext &context)
 
void RegisterLastTool (const CommandContext &context)
 
void DoRepeatProcess (const CommandContext &context, int)
 
TextualCommandResult HandleTextualCommand (const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)
 
TranslatableStrings GetCategories ()
 
void GetAllCommandNames (CommandIDs &names, bool includeMultis) const
 
void GetAllCommandLabels (TranslatableStrings &labels, std::vector< bool > &vExcludeFromMacros, bool includeMultis) const
 
void GetAllCommandData (CommandIDs &names, std::vector< NormalizedKeyString > &keys, std::vector< NormalizedKeyString > &default_keys, TranslatableStrings &labels, TranslatableStrings &categories, bool includeMultis)
 
CommandID GetNameFromNumericID (int id) const
 
TranslatableString GetLabelFromName (const CommandID &name) const
 
TranslatableString GetPrefixedLabelFromName (const CommandID &name) const
 
TranslatableString GetCategoryFromName (const CommandID &name) const
 
NormalizedKeyString GetKeyFromName (const CommandID &name) const
 
NormalizedKeyString GetDefaultKeyFromName (const CommandID &name) const
 
bool GetEnabled (const CommandID &name) const
 
int GetNumberOfKeysRead () const
 
TranslatableString ReportDuplicateShortcuts ()
 
void WriteXML (XMLWriter &xmlFile) const
 
TranslatableString DescribeCommandsAndShortcuts (const ComponentInterfaceSymbol commands[], size_t nCommands) const
 
void UpdateCheckmarks ()
 
wxString FormatLabelForMenu (const CommandID &id, const TranslatableString *pLabel) const
 Format a string appropriate for insertion in a menu. More...
 
void ModifyUndoMenuItems ()
 
void UpdateMenus (bool checkActive=true)
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs)=0
 
virtual void HandleXMLEndTag (const std::string_view &WXUNUSED(tag))
 
virtual void HandleXMLContent (const std::string_view &WXUNUSED(content))
 
virtual XMLTagHandlerHandleXMLChild (const std::string_view &tag)=0
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 
- Public Member Functions inherited from ClientData::Base
virtual ~Base ()
 
- Public Member Functions inherited from Observer::Publisher< MenuUpdateMessage >
 Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={})
 Constructor supporting type-erased custom allocation/deletion. More...
 
 Publisher (Publisher &&)=default
 
Publisheroperator= (Publisher &&)=default
 
Subscription Subscribe (Callback callback)
 Connect a callback to the Publisher; later-connected are called earlier. More...
 
Subscription Subscribe (Object &obj, Return(Object::*callback)(Args...))
 Overload of Subscribe takes an object and pointer-to-member-function. More...
 

Static Public Member Functions

static CommandManagerGet (AudacityProject &project)
 
static const CommandManagerGet (const AudacityProject &project)
 
static const std::vector< NormalizedKeyString > & ExcludedList ()
 

Public Attributes

CommandFlag mLastFlags = AlwaysEnabledFlag
 
PluginID mLastGenerator {}
 
PluginID mLastEffect {}
 
PluginID mLastAnalyzer {}
 
int mLastAnalyzerRegistration = repeattypenone
 
int mLastAnalyzerRegisteredId = -1
 
PluginID mLastTool {}
 
int mLastToolRegistration = repeattypenone
 
int mLastToolRegisteredId = -1
 
unsigned mRepeatGeneratorFlags = 0
 
unsigned mRepeatEffectFlags = 0
 
unsigned mRepeatAnalyzerFlags = 0
 
unsigned mRepeatToolFlags = 0
 
int mWhatIfNoSelection
 
bool mStopIfWasPaused { true }
 

Protected Types

using CommandKeyHash = std::unordered_map< NormalizedKeyString, CommandListEntry * >
 

Protected Member Functions

bool HandleCommandEntry (const CommandListEntry *entry, CommandFlag flags, bool alwaysEnabled, const wxEvent *evt=nullptr, const CommandContext *pGivenContext=nullptr)
 
virtual void ExecuteCommand (const CommandContext &context, const wxEvent *evt, const CommandListEntry &entry)
 
virtual bool ReallyDoQuickCheck ()
 Default implementation returns true. More...
 
- Protected Member Functions inherited from Observer::Publisher< MenuUpdateMessage >
CallbackReturn Publish (const MenuUpdateMessage &message)
 Send a message to connected callbacks. More...
 

Protected Attributes

AudacityProjectmProject
 
CommandKeyHash mCommandKeyHash
 

Static Protected Attributes

static const TranslatableString COMMAND = XO("Command")
 

Private Types

using CommandList = std::vector< std::unique_ptr< CommandListEntry > >
 
using CommandNameHash = std::unordered_map< CommandID, CommandListEntry * >
 
using CommandNumericIDHash = std::unordered_map< int, CommandListEntry * >
 

Private Member Functions

void Enable (CommandListEntry &entry, bool enabled)
 
bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs) override
 
void HandleXMLEndTag (const std::string_view &tag) override
 
XMLTagHandlerHandleXMLChild (const std::string_view &tag) override
 
void TellUserWhyDisallowed (const TranslatableString &Name, CommandFlag flagsGot, CommandFlag flagsRequired)
 
void OnUndoRedo (struct UndoRedoMessage)
 
- Private Member Functions inherited from PrefsListener
 PrefsListener ()
 
virtual ~PrefsListener ()
 
virtual void UpdatePrefs ()=0
 
virtual void UpdateSelectedPrefs (int id)
 

Static Private Member Functions

static int NextIdentifier (int ID)
 
- Static Private Member Functions inherited from PrefsListener
static void Broadcast (int id=0)
 Call this static function to notify all PrefsListener objects. More...
 

Private Attributes

CommandList mCommandList
 
CommandNameHash mCommandNameHash
 
CommandNumericIDHash mCommandNumericIDHash
 
int mXMLKeysRead
 
TranslatableString mNiceName
 
int mLastProcessId
 
const Observer::Subscription mUndoSubscription
 

Additional Inherited Members

- Static Public Attributes inherited from Observer::Publisher< MenuUpdateMessage >
static constexpr bool notifies_all
 

Detailed Description

CommandManager implements a system for organizing all user-callable commands.

It creates and manages a menu bar with a command associated with each item, and managing other commands callable by keyboard shortcuts.

Commands are implemented by overriding an abstract functor class. See Menus.cpp for an example use.

Menus or submenus containing lists of items can be added at once, with a single function (functor) to be called when any of the items is selected, with the index number of the selection as the parameter. This is useful for dynamic menus (effects) and submenus containing a list of choices (selection formats).

Menu items can be enabled or disabled individually, groups of "multi-items" can be enabled or disabled all at once, or entire sets of commands can be enabled or disabled all at once using flags. The flags should be a bitfield stored in a 32-bit integer but can be whatever you want. You specify both the desired values of the flags, and the set of flags relevant to a particular command, by using a combination of a flags parameter and a mask parameter. Any flag set to 0 in the mask parameter is the same as "don't care". Any command whose mask is set to zero will not be affected by enabling/disabling by flags.

Definition at line 49 of file CommandManager.h.

Member Typedef Documentation

◆ CommandKeyHash

using CommandManager::CommandKeyHash = std::unordered_map<NormalizedKeyString, CommandListEntry*>
protected

Definition at line 433 of file CommandManager.h.

◆ CommandList

using CommandManager::CommandList = std::vector<std::unique_ptr<CommandListEntry> >
private

Definition at line 443 of file CommandManager.h.

◆ CommandNameHash

using CommandManager::CommandNameHash = std::unordered_map<CommandID, CommandListEntry*>
private

Definition at line 447 of file CommandManager.h.

◆ CommandNumericIDHash

using CommandManager::CommandNumericIDHash = std::unordered_map<int, CommandListEntry*>
private

Definition at line 452 of file CommandManager.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
repeattypenone 
repeattypeplugin 
repeattypeunique 
repeattypeapplymacro 

Definition at line 100 of file CommandManager.h.

◆ TextualCommandResult

Enumerator
CommandFailure 
CommandSuccess 
CommandNotFound 

Definition at line 244 of file CommandManager.h.

Constructor & Destructor Documentation

◆ CommandManager() [1/2]

CommandManager::CommandManager ( AudacityProject project)
explicit

Standard Constructor

Definition at line 123 of file CommandManager.cpp.

124 : mProject{ project }
127{
128 mLastProcessId = 0;
129
130 UpdatePrefs();
131}
const auto project
AudacityProject & mProject
void OnUndoRedo(struct UndoRedoMessage)
void UpdatePrefs() override
const Observer::Subscription mUndoSubscription
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
static UndoManager & Get(AudacityProject &project)
Definition: UndoManager.cpp:71

References mLastProcessId, and UpdatePrefs().

Here is the call graph for this function:

◆ CommandManager() [2/2]

CommandManager::CommandManager ( const CommandManager )
delete

◆ ~CommandManager()

CommandManager::~CommandManager ( )
override

Class Destructor. Includes PurgeData, which removes menubars

Definition at line 145 of file CommandManager.cpp.

146{
147 PurgeData();
148}

References PurgeData().

Here is the call graph for this function:

Member Function Documentation

◆ Check()

void CommandManager::Check ( const CommandID name,
bool  checked 
)

Definition at line 720 of file CommandManager.cpp.

721{
722 if (auto iter = mCommandNameHash.find(name);
723 iter != mCommandNameHash.end())
724 iter->second->Check(checked);
725}
const TranslatableString name
Definition: Distortion.cpp:76
CommandNameHash mCommandNameHash

References mCommandNameHash, and name.

◆ DescribeCommandsAndShortcuts()

TranslatableString CommandManager::DescribeCommandsAndShortcuts ( const ComponentInterfaceSymbol  commands[],
size_t  nCommands 
) const

Formatting summaries that include shortcut keys

Definition at line 763 of file CommandManager.cpp.

765{
766 wxString mark;
767 // This depends on the language setting and may change in-session after
768 // change of preferences:
770 mark = wxT("\u200f");
771
772 static const wxString &separatorFormat = wxT("%s / %s");
773 TranslatableString result;
774 for (size_t ii = 0; ii < nCommands; ++ii) {
775 const auto &pair = commands[ii];
776 // If RTL, then the control character forces right-to-left sequencing of
777 // "/" -separated command names, and puts any "(...)" shortcuts to the
778 // left, consistently with accelerators in menus (assuming matching
779 // operating system preferences for language), even if the command name
780 // was missing from the translation file and defaulted to the English.
781
782 // Note: not putting this and other short format strings in the
783 // translation catalogs
784 auto piece = Verbatim( wxT("%s%s") )
785 .Format( mark, pair.Msgid().Stripped() );
786
787 auto name = pair.Internal();
788 if (!name.empty()) {
789 auto keyStr = GetKeyFromName(name);
790 if (!keyStr.empty()){
791 auto keyString = keyStr.Display(true);
792 auto format = wxT("%s %s(%s)");
793#ifdef __WXMAC__
794 // The unicode controls push and pop left-to-right embedding.
795 // This keeps the directionally weak characters, such as uparrow
796 // for Shift, left of the key name,
797 // consistently with how menu accelerators appear, even when the
798 // system language is RTL.
799 format = wxT("%s %s(\u202a%s\u202c)");
800#endif
801 // The mark makes correctly placed parentheses for RTL, even
802 // in the case that the piece is untranslated.
803 piece = Verbatim( format ).Format( piece, mark, keyString );
804 }
805 }
806
807 if (result.empty())
808 result = piece;
809 else
810 result = Verbatim( separatorFormat ).Format( result, piece );
811 }
812 return result;
813}
wxT("CloseDown"))
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
NormalizedKeyString GetKeyFromName(const CommandID &name) const
Holds a msgid for the translation catalog; may also bind format arguments.
TranslatableString & Format(Args &&...args) &
Capture variadic format arguments (by copy) when there is no plural.
bool IsUsingRtlLayout()
Whether using a right-to-left language layout.
Definition: BasicUI.h:389

References TranslatableString::empty(), TranslatableString::Format(), anonymous_namespace{ExportPCM.cpp}::format, GetKeyFromName(), BasicUI::IsUsingRtlLayout(), name, Verbatim(), and wxT().

Here is the call graph for this function:

◆ DoRepeatProcess()

void CommandManager::DoRepeatProcess ( const CommandContext context,
int  id 
)

Definition at line 891 of file CommandManager.cpp.

892{
893 mLastProcessId = 0; //Don't Process this as repeat
894 if (auto iter = mCommandNumericIDHash.find(id);
895 iter != mCommandNumericIDHash.end()
896 ) {
897 const auto entry = iter->second;
898 // Discriminate the union entry->callback by entry->finder
899 if (auto &finder = entry->finder) {
900 auto &handler = finder(context.project);
901 (handler.*(entry->callback.memberFn))(context);
902 }
903 else
904 (entry->callback.nonMemberFn)(context);
905 }
906}
static ProjectFileIORegistry::AttributeWriterEntry entry
AudacityProject & project
CommandNumericIDHash mCommandNumericIDHash
auto finder(TrackId id, int &distance)

References entry, anonymous_namespace{PendingTracks.cpp}::finder(), cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, mCommandNumericIDHash, mLastProcessId, and CommandContext::project.

Referenced by anonymous_namespace{PluginMenus.cpp}::OnRepeatLastAnalyzer(), and anonymous_namespace{BatchProcessDialog.cpp}::OnRepeatLastTool().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Enable() [1/2]

void CommandManager::Enable ( CommandListEntry entry,
bool  enabled 
)
private

Enables or disables a menu item based on its name (not the label in the menu bar, but the name of the command.) If you give it the name of a multi-item (one that was added using AddItemList(), it will enable or disable all of them at once

Definition at line 634 of file CommandManager.cpp.

635{
636 entry.Enable(enabled);
637 if (entry.multi) {
638 for (int i = 1, ID = entry.id;
639 i < entry.count;
640 ++i, ID = NextIdentifier(ID)
641 ) {
642 // This menu item is not necessarily in the same menu, because
643 // multi-items can be spread across multiple sub menus
644 if (auto iter = mCommandNumericIDHash.find(ID);
645 iter != mCommandNumericIDHash.end())
646 iter->second->EnableMultiItem(enabled);
647 else
648 wxLogDebug(wxT("Warning: Menu entry with id %i not in hash"), ID);
649 }
650 }
651}
static int NextIdentifier(int ID)

References entry, mCommandNumericIDHash, NextIdentifier(), and wxT().

Here is the call graph for this function:

◆ Enable() [2/2]

void CommandManager::Enable ( const wxString &  name,
bool  enabled 
)

Definition at line 663 of file CommandManager.cpp.

664{
665 if (auto iter = mCommandNameHash.find(name);
666 iter != mCommandNameHash.end())
667 Enable(*iter->second, enabled);
668 else
669 wxLogDebug(wxT("Warning: Unknown command enabled: '%s'"),
670 (const wxChar*)name);
671}
void Enable(const wxString &name, bool enabled)

References Enable(), mCommandNameHash, name, and wxT().

Referenced by Enable(), EnableUsingFlags(), and ModifyUndoMenuItems().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnableUsingFlags()

void CommandManager::EnableUsingFlags ( CommandFlag  flags,
CommandFlag  strictFlags 
)

Definition at line 673 of file CommandManager.cpp.

675{
676 // strictFlags are a subset of flags. strictFlags represent the real
677 // conditions now, but flags are the conditions that could be made true.
678 // Some commands use strict flags only, refusing the chance to fix
679 // conditions
680 wxASSERT( (strictFlags & ~flags).none() );
681
682 for(const auto &entry : mCommandList) {
683 if (entry->multi && entry->index != 0)
684 continue;
685 if( entry->isOccult )
686 continue;
687
688 auto useFlags = entry->useStrictFlags ? strictFlags : flags;
689
690 if (entry->flags.any()) {
691 bool enable = ((useFlags & entry->flags) == entry->flags);
692 Enable(*entry, enable);
693 }
694 }
695}
@ none
Definition: Dither.h:20
CommandList mCommandList

References Enable(), entry, mCommandList, and none.

Referenced by UpdateMenus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExcludedList()

const std::vector< NormalizedKeyString > & CommandManager::ExcludedList ( )
static

Definition at line 150 of file CommandManager.cpp.

151{
152 static const auto list = [] {
153 // These short cuts are for the max list only....
154 const char *const strings[] = {
155 // "Ctrl+I",
156 "Ctrl+Alt+I",
157 //"Ctrl+J",
158 "Ctrl+Alt+J",
159 "Ctrl+Alt+V",
160 "Alt+X",
161 "Alt+K",
162 "Shift+Alt+X",
163 "Shift+Alt+K",
164 "Alt+L",
165 "Shift+Alt+C",
166 "Alt+I",
167 "Alt+J",
168 "Shift+Alt+J",
169 "Ctrl+Shift+A",
170 //"Q",
171 //"Shift+J",
172 //"Shift+K",
173 //"Shift+Home",
174 //"Shift+End",
175 "Ctrl+[",
176 "Ctrl+]",
177 "1",
178 "Shift+F5",
179 "Shift+F6",
180 "Shift+F7",
181 "Shift+F8",
182 "Ctrl+Shift+F5",
183 "Ctrl+Shift+F7",
184 "Ctrl+Shift+N",
185 "Ctrl+Shift+M",
186 "Ctrl+Home",
187 "Ctrl+End",
188 "Shift+C",
189 "Alt+Shift+Up",
190 "Alt+Shift+Down",
191 "Shift+P",
192 "Alt+Shift+Left",
193 "Alt+Shift+Right",
194 "Ctrl+Shift+T",
195 //"Command+M",
196 //"Option+Command+M",
197 "Shift+H",
198 "Shift+O",
199 "Shift+I",
200 "Shift+N",
201 "D",
202 "A",
203 "Alt+Shift+F6",
204 "Alt+F6",
205 };
206
207 std::vector<NormalizedKeyString> result(
208 std::begin(strings), std::end(strings)
209 );
210 std::sort( result.begin(), result.end() );
211 return result;
212 }();
213 return list;
214}
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150

References PackedArray::begin(), and PackedArray::end().

Referenced by KeyConfigPrefs::FilterKeys(), and CommandManager::Populator::SetMaxList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExecuteCommand()

void CommandManager::ExecuteCommand ( const CommandContext context,
const wxEvent *  evt,
const CommandListEntry entry 
)
protectedvirtual

Reimplemented in MenuCreator.

Definition at line 853 of file CommandManager.cpp.

855{
856 // Discriminate the union entry->callback by entry->finder
857 if (auto &finder = entry.finder) {
858 auto &handler = finder(mProject);
859 (handler.*(entry.callback.memberFn))(context);
860 }
861 else
862 (entry.callback.nonMemberFn)(context);
863 mLastProcessId = 0;
864}

References entry, anonymous_namespace{PendingTracks.cpp}::finder(), cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, mLastProcessId, and mProject.

Referenced by MenuCreator::ExecuteCommand(), and HandleCommandEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FormatLabelForMenu()

wxString CommandManager::FormatLabelForMenu ( const CommandID id,
const TranslatableString pLabel 
) const

Format a string appropriate for insertion in a menu.

Parameters
pLabelif not null, use this instead of the manager's stored label

Definition at line 598 of file CommandManager.cpp.

600{
601 NormalizedKeyString keyStr;
602 if (auto iter = mCommandNameHash.find(id); iter != mCommandNameHash.end()) {
603 if (auto pEntry = iter->second) {
604 keyStr = pEntry->key;
605 if (!pLabel)
606 pLabel = &pEntry->label;
607 }
608 }
609 if (pLabel)
610 return CommandListEntry::FormatLabelForMenu(*pLabel, keyStr);
611 return {};
612}
wxString FormatLabelForMenu() const

References CommandManager::CommandListEntry::FormatLabelForMenu(), and mCommandNameHash.

Here is the call graph for this function:

◆ Get() [1/2]

CommandManager & CommandManager::Get ( AudacityProject project)
static

Definition at line 110 of file CommandManager.cpp.

111{
112 return project.AttachedObjects::Get<CommandManager>(key);
113}
static const AudacityProject::AttachedObjects::RegisteredFactory key
CommandManager implements a system for organizing all user-callable commands.

References key, and project.

Referenced by SelectUtilities::ActivatePlayRegion(), CommandManager::Populator::AddItem(), anonymous_namespace{PluginMenus.cpp}::AnalyzeMenu(), MacroCommands::ApplyCommandInBatchMode(), ToolManager::CreateWindows(), CommonTrackPanelCell::DoContextMenu(), EffectUI::DoEffect(), ProjectAudioManager::DoRecord(), anonymous_namespace{EditMenus.cpp}::EditMenu(), anonymous_namespace{PluginMenus.cpp}::EffectMenu(), GetInfoCommand::ExploreMenu(), ToolBarButtons::ForAllButtons(), anonymous_namespace{PluginMenus.cpp}::GenerateMenu(), MenuCreator::Get(), Get(), CommandDispatch::HandleTextualCommand(), anonymous_namespace{PluginMenus.cpp}::HasLastAnalyzerFlag(), anonymous_namespace{PluginMenus.cpp}::HasLastEffectFlag(), anonymous_namespace{PluginMenus.cpp}::HasLastGeneratorFlag(), anonymous_namespace{BatchProcessDialog.cpp}::HasLastToolFlag(), SelectUtilities::InactivatePlayRegion(), MacroCommandsCatalog::MacroCommandsCatalog(), ToolManager::ModifyToolbarMenus(), CommandManager::Populator::NewIdentifier(), EffectUIHost::OnApply(), anonymous_namespace{BatchProcessDialog.cpp}::OnApplyMacroDirectlyByName(), anonymous_namespace{BatchProcessDialog.cpp}::OnApplyMacrosPalette(), anonymous_namespace{PluginMenus.cpp}::OnBenchmark(), ToolBarButtons::OnButton(), anonymous_namespace{Contrast.cpp}::anonymous_namespace{Contrast.cpp}::OnContrast(), anonymous_namespace{PluginMenus.cpp}::OnDetectUpstreamDropouts(), anonymous_namespace{BatchProcessDialog.cpp}::OnManageMacros(), ProjectWindow::OnMenu(), anonymous_namespace{FreqWindow.cpp}::OnPlotSpectrum(), anonymous_namespace{PluginMenus.cpp}::OnRepeatLastAnalyzer(), anonymous_namespace{PluginMenus.cpp}::OnRepeatLastEffect(), anonymous_namespace{PluginMenus.cpp}::OnRepeatLastGenerator(), anonymous_namespace{BatchProcessDialog.cpp}::OnRepeatLastTool(), anonymous_namespace{PluginMenus.cpp}::OnResetConfig(), anonymous_namespace{ViewMenus.cpp}::OnShowClipping(), anonymous_namespace{ViewMenus.cpp}::OnShowExtraMenus(), anonymous_namespace{ViewMenus.cpp}::OnShowNameOverlay(), anonymous_namespace{PluginMenus.cpp}::OnSimulateRecordingErrors(), ProjectWindow::OnUpdateUI(), ProjectWindow::OnViewportMessage(), PluginMenuItems(), KeyConfigPrefs::Populate(), SelectHandle::Preview(), SelectUtilities::SelectAllIfNone(), SelectUtilities::SelectAllIfNoneAndAllowed(), ToolBar::SetButtonToolTip(), anonymous_namespace{TimelineMenus.cpp}::SetTimeDisplayMode(), MuteButtonHandle::Tip(), SoloButtonHandle::Tip(), MenuButtonHandle::Tip(), and CloseButtonHandle::Tip().

◆ Get() [2/2]

const CommandManager & CommandManager::Get ( const AudacityProject project)
static

Definition at line 115 of file CommandManager.cpp.

116{
117 return Get(const_cast<AudacityProject &>(project));
118}
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static CommandManager & Get(AudacityProject &project)

References Get(), and project.

Here is the call graph for this function:

◆ GetAllCommandData()

void CommandManager::GetAllCommandData ( CommandIDs names,
std::vector< NormalizedKeyString > &  keys,
std::vector< NormalizedKeyString > &  default_keys,
TranslatableStrings labels,
TranslatableStrings categories,
bool  includeMultis 
)

Definition at line 1037 of file CommandManager.cpp.

1047{
1048 for(const auto &entry : mCommandList) {
1049 // GetAllCommandData is used by KeyConfigPrefs.
1050 // It does need the effects.
1051 //if ( entry->isEffect )
1052 // continue;
1053 if ( !entry->multi || includeMultis )
1054 {
1055 names.push_back(entry->name);
1056 keys.push_back(entry->key);
1057 default_keys.push_back(entry->defaultKey);
1058 labels.push_back(entry->label);
1059 categories.push_back(entry->labelTop);
1060#if defined(EXPERIMENTAL_KEY_VIEW)
1061 prefixes.push_back(entry->labelPrefix);
1062#endif
1063 }
1064 }
1065}
static TranslatableStrings names
Definition: TagsEditor.cpp:153

References entry, mCommandList, and names.

Referenced by KeyConfigPrefs::RefreshBindings().

Here is the caller graph for this function:

◆ GetAllCommandLabels()

void CommandManager::GetAllCommandLabels ( TranslatableStrings labels,
std::vector< bool > &  vExcludeFromMacros,
bool  includeMultis 
) const

Definition at line 1018 of file CommandManager.cpp.

1021{
1022 vExcludeFromMacros.clear();
1023 for(const auto &entry : mCommandList) {
1024 // This is fetching commands from the menus, for use as batch commands.
1025 // Until we have properly merged EffectManager and CommandManager
1026 // we explicitly exclude effects, as they are already handled by the
1027 // effects Manager.
1028 if ( entry->isEffect )
1029 continue;
1030 if (!entry->multi)
1031 names.push_back(entry->longLabel), vExcludeFromMacros.push_back(entry->excludeFromMacros);
1032 else if( includeMultis )
1033 names.push_back(entry->longLabel), vExcludeFromMacros.push_back(entry->excludeFromMacros);
1034 }
1035}

References entry, mCommandList, and names.

◆ GetAllCommandNames()

void CommandManager::GetAllCommandNames ( CommandIDs names,
bool  includeMultis 
) const

Definition at line 1005 of file CommandManager.cpp.

1007{
1008 for(const auto &entry : mCommandList) {
1009 if ( entry->isEffect )
1010 continue;
1011 if (!entry->multi)
1012 names.push_back(entry->name);
1013 else if( includeMultis )
1014 names.push_back(entry->name );// + wxT(":")/*+ mCommandList[i]->label*/);
1015 }
1016}

References entry, mCommandList, and names.

◆ GetCategories()

TranslatableStrings CommandManager::GetCategories ( )

Definition at line 973 of file CommandManager.cpp.

974{
976
977 for (const auto &entry : mCommandList) {
978 auto &cat = entry->labelTop;
979 if ( ! make_iterator_range( cats ).contains(cat) ) {
980 cats.push_back(cat);
981 }
982 }
983#if 0
984 mCommandList.size(); i++) {
985 if (includeMultis || !mCommandList[i]->multi)
986 names.push_back(mCommandList[i]->name);
987 }
988
989 if (p == NULL) {
990 return;
991 }
992
993 wxMenuBar *bar = p->GetMenuBar();
994 size_t cnt = bar->GetMenuCount();
995 for (size_t i = 0; i < cnt; i++) {
996 cats.push_back(bar->GetMenuLabelText(i));
997 }
998
999 cats.push_back(COMMAND);
1000#endif
1001
1002 return cats;
1003}
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: IteratorX.h:210
std::vector< TranslatableString > TranslatableStrings
static const TranslatableString COMMAND

References COMMAND, entry, make_iterator_range(), mCommandList, name, and names.

Here is the call graph for this function:

◆ GetCategoryFromName()

TranslatableString CommandManager::GetCategoryFromName ( const CommandID name) const

Definition at line 1101 of file CommandManager.cpp.

1102{
1103 if (auto iter = mCommandNameHash.find(name);
1104 iter != mCommandNameHash.end())
1105 return iter->second->labelTop;
1106 return {};
1107}

References mCommandNameHash, and name.

Referenced by KeyConfigPrefs::OnSet().

Here is the caller graph for this function:

◆ GetDefaultKeyFromName()

NormalizedKeyString CommandManager::GetDefaultKeyFromName ( const CommandID name) const

Definition at line 1117 of file CommandManager.cpp.

1119{
1120 if (auto iter = mCommandNameHash.find(name);
1121 iter != mCommandNameHash.end())
1122 return iter->second->defaultKey;
1123 return {};
1124}

References mCommandNameHash, and name.

Referenced by KeyConfigPrefs::OnSet().

Here is the caller graph for this function:

◆ GetEnabled()

bool CommandManager::GetEnabled ( const CommandID name) const

Definition at line 697 of file CommandManager.cpp.

698{
699 if (auto iter = mCommandNameHash.find(name);
700 iter != mCommandNameHash.end())
701 return iter->second->GetEnabled();
702 else {
703 // using GET in a log message for devs' eyes only
704 wxLogDebug(wxT("Warning: command doesn't exist: '%s'"),
705 name.GET());
706 return false;
707 }
708}

References mCommandNameHash, name, and wxT().

Referenced by ToolBarButtons::ForAllButtons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetKeyFromName()

NormalizedKeyString CommandManager::GetKeyFromName ( const CommandID name) const

Definition at line 1109 of file CommandManager.cpp.

1110{
1111 if (auto iter = mCommandNameHash.find(name);
1112 iter != mCommandNameHash.end())
1113 return iter->second->key;
1114 return {};
1115}

References mCommandNameHash, and name.

Referenced by DescribeCommandsAndShortcuts(), KeyConfigPrefs::MergeWithExistingKeys(), SelectHandle::Preview(), and KeyConfigPrefs::RefreshKeyInfo().

Here is the caller graph for this function:

◆ GetLabelFromName()

TranslatableString CommandManager::GetLabelFromName ( const CommandID name) const

Definition at line 1075 of file CommandManager.cpp.

1076{
1077 if (auto iter = mCommandNameHash.find(name);
1078 iter != mCommandNameHash.end())
1079 return iter->second->longLabel;
1080 return {};
1081}

References mCommandNameHash, and name.

◆ GetNameFromNumericID()

CommandID CommandManager::GetNameFromNumericID ( int  id) const

Definition at line 1067 of file CommandManager.cpp.

1068{
1069 if (auto iter = mCommandNumericIDHash.find(id);
1070 iter != mCommandNumericIDHash.end())
1071 return iter->second->name;
1072 return {};
1073}

References mCommandNumericIDHash.

◆ GetNumberOfKeysRead()

int CommandManager::GetNumberOfKeysRead ( ) const

Definition at line 715 of file CommandManager.cpp.

716{
717 return mXMLKeysRead;
718}

References mXMLKeysRead.

Referenced by KeyConfigPrefs::OnImport().

Here is the caller graph for this function:

◆ GetPrefixedLabelFromName()

TranslatableString CommandManager::GetPrefixedLabelFromName ( const CommandID name) const

Definition at line 1084 of file CommandManager.cpp.

1085{
1086 if (auto iter = mCommandNameHash.find(name);
1087 iter != mCommandNameHash.end()
1088 ) {
1089 const auto entry = iter->second;
1090 if (!entry->labelPrefix.empty())
1091 return Verbatim( wxT("%s - %s") )
1092 .Format(entry->labelPrefix, entry->label)
1093 .Stripped();
1094 else
1095 return entry->label.Stripped();
1096 }
1097 return {};
1098}
TranslatableString Stripped(unsigned options=MenuCodes) const
non-mutating, constructs another TranslatableString object

References entry, TranslatableString::Format(), mCommandNameHash, name, TranslatableString::Stripped(), Verbatim(), and wxT().

Referenced by KeyConfigPrefs::ContainsIllegalDups(), KeyConfigPrefs::MergeWithExistingKeys(), and KeyConfigPrefs::OnSet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetProject()

AudacityProject & CommandManager::GetProject ( )
inline

Definition at line 117 of file CommandManager.h.

117{ return mProject; }

Referenced by HandleTextualCommand().

Here is the caller graph for this function:

◆ GetUpdateFlags()

CommandFlag CommandManager::GetUpdateFlags ( bool  quick = false) const

Definition at line 1285 of file CommandManager.cpp.

1286{
1287 // This method determines all of the flags that determine whether
1288 // certain menu items and commands should be enabled or disabled,
1289 // and returns them in a bitfield. Note that if none of the flags
1290 // have changed, it's not necessary to even check for updates.
1291
1292 // static variable, used to remember flags for next time.
1293 static CommandFlag lastFlags;
1294
1295 CommandFlag flags, quickFlags;
1296
1297 const auto &options = ReservedCommandFlag::Options();
1298 size_t ii = 0;
1299 for ( const auto &predicate : ReservedCommandFlag::RegisteredPredicates() ) {
1300 if ( options[ii].quickTest ) {
1301 quickFlags[ii] = true;
1302 if( predicate( mProject ) )
1303 flags[ii] = true;
1304 }
1305 ++ii;
1306 }
1307
1308 if (quick)
1309 // quick 'short-circuit' return.
1310 flags = (lastFlags & ~quickFlags) | flags;
1311 else {
1312 ii = 0;
1313 for ( const auto &predicate
1315 if ( !options[ii].quickTest && predicate( mProject ) )
1316 flags[ii] = true;
1317 ++ii;
1318 }
1319 }
1320
1321 lastFlags = flags;
1322 return flags;
1323}
std::bitset< NCommandFlags > CommandFlag
Definition: CommandFlag.h:30
static const Predicates & RegisteredPredicates()
Definition: CommandFlag.cpp:27
static const std::vector< CommandFlagOptions > & Options()
Definition: CommandFlag.cpp:32

References mProject, ReservedCommandFlag::Options(), and ReservedCommandFlag::RegisteredPredicates().

Referenced by ToolBarButtons::OnButton(), ProjectWindow::OnMenu(), SelectUtilities::SelectAllIfNone(), SelectUtilities::SelectAllIfNoneAndAllowed(), TryToMakeActionAllowed(), and UpdateMenus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleCommandEntry()

bool CommandManager::HandleCommandEntry ( const CommandListEntry entry,
CommandFlag  flags,
bool  alwaysEnabled,
const wxEvent *  evt = nullptr,
const CommandContext pGivenContext = nullptr 
)
protected

HandleCommandEntry() takes a CommandListEntry and executes it returning true iff successful. If you pass any flags, the command won't be executed unless the flags are compatible with the command's flags.

Definition at line 819 of file CommandManager.cpp.

822{
823 if (!entry )
824 return false;
825
826 if (flags != AlwaysEnabledFlag && !entry->enabled)
827 return false;
828
829 if (!alwaysEnabled && entry->flags.any()) {
830
831 const auto NiceName = entry->label.Stripped(
833 // NB: The call may have the side effect of changing flags.
834 bool allowed = ReportIfActionNotAllowed(NiceName, flags, entry->flags);
835 // If the function was disallowed, it STILL should count as having been
836 // handled (by doing nothing or by telling the user of the problem).
837 // Otherwise we may get other handlers having a go at obeying the command.
838 if (!allowed)
839 return true;
840 mNiceName = NiceName;
841 }
842 else {
843 mNiceName = {};
844 }
845
846 CommandContext context{ mProject, evt, entry->index, entry->parameter };
847 if (pGivenContext)
848 context.temporarySelection = pGivenContext->temporarySelection;
849 ExecuteCommand(context, evt, *entry);
850 return true;
851}
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:34
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
TemporarySelection temporarySelection
bool ReportIfActionNotAllowed(const TranslatableString &Name, CommandFlag &flags, CommandFlag flagsRqd)
virtual void ExecuteCommand(const CommandContext &context, const wxEvent *evt, const CommandListEntry &entry)
TranslatableString mNiceName

References AlwaysEnabledFlag, TranslatableString::Ellipses, entry, ExecuteCommand(), TranslatableString::MenuCodes, mNiceName, mProject, ReportIfActionNotAllowed(), and CommandContext::temporarySelection.

Referenced by HandleMenuID(), and HandleTextualCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleMenuID()

bool CommandManager::HandleMenuID ( int  id,
CommandFlag  flags,
bool  alwaysEnabled 
)

Call this when a menu event is received. If it matches a command, it will call the appropriate CommandManagerListener function. If you pass any flags, the command won't be executed unless the flags are compatible with the command's flags.

Definition at line 914 of file CommandManager.cpp.

916{
918 if (auto iter = mCommandNumericIDHash.find(id);
919 iter != mCommandNumericIDHash.end()
920 ) {
921 const auto entry = iter->second;
922 if (GlobalMenuHook::Call(entry->name))
923 return true;
924
925 return HandleCommandEntry(entry, flags, alwaysEnabled);
926 }
927 return false;
928}
int id
bool HandleCommandEntry(const CommandListEntry *entry, CommandFlag flags, bool alwaysEnabled, const wxEvent *evt=nullptr, const CommandContext *pGivenContext=nullptr)
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.

References GlobalHook< GlobalMenuHook, bool(const CommandID &) >::Call(), entry, HandleCommandEntry(), id, mCommandNumericIDHash, and mLastProcessId.

Here is the call graph for this function:

◆ HandleTextualCommand()

CommandManager::TextualCommandResult CommandManager::HandleTextualCommand ( const CommandID Str,
const CommandContext context,
CommandFlag  flags,
bool  alwaysEnabled 
)
Precondition
&context.project == &GetProject()

HandleTextualCommand() allows us a limited version of script/batch behavior, since we can get from a string command name to the actual code to run.

Definition at line 934 of file CommandManager.cpp.

936{
937 assert(&context.project == &GetProject());
938 if( Str.empty() )
939 return CommandFailure;
940 // Linear search for now...
941 for (const auto &entry : mCommandList)
942 {
943 if (!entry->multi)
944 {
945 // Testing against labelPrefix too allows us to call Nyquist functions by name.
946 if( Str == entry->name ||
947 // PRL: uh oh, mixing internal string (Str) with user-visible
948 // (labelPrefix, which was initialized from a user-visible
949 // sub-menu name)
950 Str == entry->labelPrefix.Translation() )
951 {
952 return HandleCommandEntry(
953 entry.get(), flags, alwaysEnabled,
954 nullptr, &context)
956 }
957 }
958 else
959 {
960 // Handle multis too...
961 if( Str == entry->name )
962 {
963 return HandleCommandEntry(
964 entry.get(), flags, alwaysEnabled,
965 nullptr, &context)
967 }
968 }
969 }
970 return CommandNotFound;
971}
AudacityProject & GetProject()
bool empty() const
Definition: Identifier.h:61

References CommandFailure, CommandNotFound, CommandSuccess, Identifier::empty(), entry, GetProject(), HandleCommandEntry(), mCommandList, and CommandContext::project.

Here is the call graph for this function:

◆ HandleXMLChild()

XMLTagHandler * CommandManager::HandleXMLChild ( const std::string_view &  tag)
overrideprivatevirtual

Implements XMLTagHandler.

Definition at line 1177 of file CommandManager.cpp.

1178{
1179 return this;
1180}

◆ HandleXMLEndTag()

void CommandManager::HandleXMLEndTag ( const std::string_view &  tag)
overrideprivate

Definition at line 1164 of file CommandManager.cpp.

1165{
1166 /*
1167 if (tag == "audacitykeyboard") {
1168 AudacityMessageBox(
1169 XO("Loaded %d keyboard shortcuts\n")
1170 .Format( mXMLKeysRead ),
1171 XO("Loading Keyboard Shortcuts"),
1172 wxOK | wxCENTRE);
1173 }
1174 */
1175}

◆ HandleXMLTag()

bool CommandManager::HandleXMLTag ( const std::string_view &  tag,
const AttributesList attrs 
)
overrideprivatevirtual

Implements XMLTagHandler.

Definition at line 1126 of file CommandManager.cpp.

1127{
1128 if (tag == "audacitykeyboard") {
1129 mXMLKeysRead = 0;
1130 }
1131
1132 if (tag == "command") {
1133 wxString name;
1135
1136 for (auto pair : attrs)
1137 {
1138 auto attr = pair.first;
1139 auto value = pair.second;
1140
1141 if (value.IsStringView())
1142 {
1143 const wxString strValue = value.ToWString();
1144
1145 if (attr == "name")
1146 name = strValue;
1147 else if (attr == "key")
1148 key = NormalizedKeyString{ strValue };
1149 }
1150 }
1151
1152 if (auto iter = mCommandNameHash.find(name);
1153 iter != mCommandNameHash.end()
1154 ) {
1155 iter->second->key = key;
1156 ++mXMLKeysRead;
1157 }
1158 }
1159
1160 return true;
1161}

References key, mCommandNameHash, mXMLKeysRead, and name.

◆ Modify()

void CommandManager::Modify ( const wxString &  name,
const TranslatableString newLabel 
)

Changes the label text of a menu item.

Definition at line 732 of file CommandManager.cpp.

733{
734 if (auto iter = mCommandNameHash.find(name);
735 iter != mCommandNameHash.end())
736 iter->second->Modify(newLabel);
737}

References mCommandNameHash, and name.

Referenced by ModifyUndoMenuItems(), RegisterLastAnalyzer(), and RegisterLastTool().

Here is the caller graph for this function:

◆ ModifyUndoMenuItems()

void CommandManager::ModifyUndoMenuItems ( )

Definition at line 1442 of file CommandManager.cpp.

1443{
1444 auto &project = mProject;
1446 auto &undoManager = UndoManager::Get( project );
1447 int cur = undoManager.GetCurrentState();
1448
1449 if (undoManager.UndoAvailable()) {
1450 undoManager.GetShortDescription(cur, &desc);
1451 Modify(wxT("Undo"), XXO("&Undo %s").Format(desc));
1452 Enable(wxT("Undo"), ProjectHistory::Get(project).UndoAvailable());
1453 }
1454 else {
1455 Modify(wxT("Undo"), XXO("&Undo"));
1456 }
1457
1458 if (undoManager.RedoAvailable()) {
1459 undoManager.GetShortDescription(cur+1, &desc);
1460 Modify(wxT("Redo"), XXO("&Redo %s").Format( desc ));
1461 Enable(wxT("Redo"), ProjectHistory::Get(project).RedoAvailable());
1462 }
1463 else {
1464 Modify(wxT("Redo"), XXO("&Redo"));
1465 Enable(wxT("Redo"), false);
1466 }
1467}
XXO("&Cut/Copy/Paste Toolbar")
void Modify(const wxString &name, const TranslatableString &newLabel)
Changes the label text of a menu item.
Abstract base class used in importing a file.
static ProjectHistory & Get(AudacityProject &project)
const TranslatableString desc
Definition: ExportPCM.cpp:51

References anonymous_namespace{ExportPCM.cpp}::desc, Enable(), ProjectHistory::Get(), UndoManager::Get(), Modify(), mProject, project, wxT(), and XXO().

Referenced by anonymous_namespace{EditMenus.cpp}::EditMenu(), anonymous_namespace{BatchProcessDialog.cpp}::OnApplyMacroDirectlyByName(), and OnUndoRedo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NCommands()

size_t CommandManager::NCommands ( ) const
inline

Definition at line 118 of file CommandManager.h.

118{ return mCommandList.size(); }

Referenced by SetKeyFromIndex().

Here is the caller graph for this function:

◆ NextIdentifier()

int CommandManager::NextIdentifier ( int  ID)
staticprivate

Definition at line 429 of file CommandManager.cpp.

430{
431 ID++;
432
433 //Skip the reserved identifiers used by wxWidgets
434 if((ID >= wxID_LOWEST) && (ID <= wxID_HIGHEST))
435 ID = wxID_HIGHEST+1;
436
437 return ID;
438}

Referenced by Enable(), and CommandManager::Populator::NewIdentifier().

Here is the caller graph for this function:

◆ OnUndoRedo()

void CommandManager::OnUndoRedo ( struct UndoRedoMessage  message)
private

Definition at line 1469 of file CommandManager.cpp.

1470{
1471 switch (message.type) {
1476 break;
1477 default:
1478 return;
1479 }
1481 UpdateMenus();
1482}
void UpdateMenus(bool checkActive=true)
enum UndoRedoMessage::Type type

References ModifyUndoMenuItems(), UndoRedoMessage::Pushed, UndoRedoMessage::Renamed, UndoRedoMessage::Reset, UndoRedoMessage::type, UndoRedoMessage::UndoOrRedo, and UpdateMenus().

Here is the call graph for this function:

◆ operator=()

CommandManager & CommandManager::operator= ( const CommandManager )
delete

◆ PurgeData()

void CommandManager::PurgeData ( )

Definition at line 238 of file CommandManager.cpp.

239{
240 // mCommandList contains unique pointers to CommandListEntrys
241 mCommandList.clear();
242
243 // Then clear the three hashes of dangling pointers
244 mCommandNameHash.clear();
245 mCommandKeyHash.clear();
246 mCommandNumericIDHash.clear();
247}
CommandKeyHash mCommandKeyHash

References mCommandKeyHash, mCommandList, mCommandNameHash, and mCommandNumericIDHash.

Referenced by MenuCreator::RebuildMenuBar(), and ~CommandManager().

Here is the caller graph for this function:

◆ ReallyDoQuickCheck()

bool CommandManager::ReallyDoQuickCheck ( )
protectedvirtual

Default implementation returns true.

Reimplemented in MenuCreator.

Definition at line 1525 of file CommandManager.cpp.

1526{
1527 return true;
1528}

Referenced by UpdateMenus().

Here is the caller graph for this function:

◆ RegisterLastAnalyzer()

void CommandManager::RegisterLastAnalyzer ( const CommandContext context)

Definition at line 868 of file CommandManager.cpp.

868 {
869 if (mLastProcessId != 0) {
872 auto lastEffectDesc = XO("Repeat %s").Format(mNiceName);
873 Modify(wxT("RepeatLastAnalyzer"), lastEffectDesc);
874 }
875 return;
876}
XO("Cut/Copy/Paste")
int mLastAnalyzerRegisteredId
int mLastAnalyzerRegistration

References mLastAnalyzerRegisteredId, mLastAnalyzerRegistration, mLastProcessId, mNiceName, Modify(), repeattypeunique, wxT(), and XO().

Referenced by anonymous_namespace{Contrast.cpp}::anonymous_namespace{Contrast.cpp}::OnContrast(), and anonymous_namespace{FreqWindow.cpp}::OnPlotSpectrum().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterLastTool()

void CommandManager::RegisterLastTool ( const CommandContext context)

Definition at line 880 of file CommandManager.cpp.

880 {
881 if (mLastProcessId != 0) {
884 auto lastEffectDesc = XO("Repeat %s").Format(mNiceName);
885 Modify(wxT("RepeatLastTool"), lastEffectDesc);
886 }
887 return;
888}

References mLastProcessId, mLastToolRegisteredId, mLastToolRegistration, mNiceName, Modify(), repeattypeunique, wxT(), and XO().

Referenced by anonymous_namespace{BatchProcessDialog.cpp}::OnApplyMacrosPalette(), anonymous_namespace{PluginMenus.cpp}::OnBenchmark(), and anonymous_namespace{BatchProcessDialog.cpp}::OnManageMacros().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReportDuplicateShortcuts()

TranslatableString CommandManager::ReportDuplicateShortcuts ( )

Definition at line 1261 of file CommandManager.cpp.

1262{
1263 TranslatableString disabledShortcuts;
1264
1265 for (auto& entry : mCommandList) {
1266 if (!entry->key.empty() && entry->key != entry->defaultKey) { // user assigned
1267 for (auto& entry2 : mCommandList) {
1268 if (!entry2->key.empty() && entry2->key == entry2->defaultKey) { // default
1269 if (entry2->key == entry->key) {
1270 auto name = wxT("/NewKeys/") + entry2->name.GET();
1272
1273 disabledShortcuts +=
1274 XO("\n* %s, because you have assigned the shortcut %s to %s")
1275 .Format(entry2->label.Strip(), entry->key.GET(), entry->label.Strip());
1276 }
1277 }
1278 }
1279 }
1280 }
1281
1282 return disabledShortcuts;
1283}
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
virtual bool Write(const wxString &key, bool value)=0

References entry, gPrefs, mCommandList, name, audacity::BasicSettings::Write(), wxT(), and XO().

Referenced by MenuCreator::RemoveDuplicateShortcuts().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReportIfActionNotAllowed()

bool CommandManager::ReportIfActionNotAllowed ( const TranslatableString Name,
CommandFlag flags,
CommandFlag  flagsRqd 
)

Definition at line 1325 of file CommandManager.cpp.

1327{
1328 auto &project = mProject;
1329 bool bAllowed = TryToMakeActionAllowed( flags, flagsRqd );
1330 if( bAllowed )
1331 return true;
1332 TellUserWhyDisallowed( Name, flags & flagsRqd, flagsRqd);
1333 return false;
1334}
void TellUserWhyDisallowed(const TranslatableString &Name, CommandFlag flagsGot, CommandFlag flagsRequired)
bool TryToMakeActionAllowed(CommandFlag &flags, CommandFlag flagsRqd)

References mProject, project, TellUserWhyDisallowed(), and TryToMakeActionAllowed().

Referenced by HandleCommandEntry(), and EffectUIHost::OnApply().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCommandFlags()

void CommandManager::SetCommandFlags ( const CommandID name,
CommandFlag  flags 
)

Definition at line 1207 of file CommandManager.cpp.

1209{
1210 if (auto iter = mCommandNameHash.find(name);
1211 iter != mCommandNameHash.end())
1212 iter->second->flags = flags;
1213}

References mCommandNameHash, and name.

Referenced by CommandManager::Populator::AddItem().

Here is the caller graph for this function:

◆ SetKeyFromIndex()

void CommandManager::SetKeyFromIndex ( int  i,
const NormalizedKeyString key 
)
Precondition
0 <= i && i < NCommands()

Definition at line 753 of file CommandManager.cpp.

754{
755 if (!(0 <= i && i < NCommands())) {
756 assert(false);
757 return;
758 }
759 const auto &entry = mCommandList[i];
760 entry->key = key;
761}
size_t NCommands() const

References entry, key, mCommandList, and NCommands().

Referenced by KeyConfigPrefs::Cancel(), KeyConfigPrefs::MergeWithExistingKeys(), and KeyConfigPrefs::OnImportDefaults().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetKeyFromName()

void CommandManager::SetKeyFromName ( const CommandID name,
const NormalizedKeyString key 
)

Definition at line 745 of file CommandManager.cpp.

747{
748 if (auto iter = mCommandNameHash.find(name);
749 iter != mCommandNameHash.end())
750 iter->second->key = key;
751}

References key, mCommandNameHash, and name.

Referenced by KeyConfigPrefs::ClearAllKeys(), KeyConfigPrefs::OnImport(), KeyConfigPrefs::OnSet(), and KeyConfigPrefs::SetKeyForSelected().

Here is the caller graph for this function:

◆ TellUserWhyDisallowed()

void CommandManager::TellUserWhyDisallowed ( const TranslatableString Name,
CommandFlag  flagsGot,
CommandFlag  flagsRequired 
)
private

Definition at line 1370 of file CommandManager.cpp.

1372{
1373 // The default string for 'reason' is a catch all. I hope it won't ever be seen
1374 // and that we will get something more specific.
1375 auto reason = XO("There was a problem with your last action. If you think\nthis is a bug, please tell us exactly where it occurred.");
1376 // The default title string is 'Disallowed'.
1377 auto untranslatedTitle = XO("Disallowed");
1378 wxString helpPage;
1379
1380 bool enableDefaultMessage = true;
1381 bool defaultMessage = true;
1382
1383 auto doOption = [&](const CommandFlagOptions &options) {
1384 if ( options.message ) {
1385 reason = options.message( Name );
1386 defaultMessage = false;
1387 if ( !options.title.empty() )
1388 untranslatedTitle = options.title;
1389 helpPage = options.helpPage;
1390 return true;
1391 }
1392 else {
1393 enableDefaultMessage =
1394 enableDefaultMessage && options.enableDefaultMessage;
1395 return false;
1396 }
1397 };
1398
1399 const auto &alloptions = ReservedCommandFlag::Options();
1400 auto missingFlags = flagsRequired & ~flagsGot;
1401
1402 // Find greatest priority
1403 unsigned priority = 0;
1404 for ( const auto &options : alloptions )
1405 priority = std::max( priority, options.priority );
1406
1407 // Visit all unsatisfied conditions' options, by descending priority,
1408 // stopping when we find a message
1409 ++priority;
1410 while( priority-- ) {
1411 size_t ii = 0;
1412 for ( const auto &options : alloptions ) {
1413 if (
1414 priority == options.priority
1415 &&
1416 missingFlags[ii]
1417 &&
1418 doOption( options ) )
1419 goto done;
1420
1421 ++ii;
1422 }
1423 }
1424 done:
1425
1426 if (
1427 // didn't find a message
1428 defaultMessage
1429 &&
1430 // did find a condition that suppresses the default message
1431 !enableDefaultMessage
1432 )
1433 return;
1434
1435 // Does not have the warning icon...
1437 untranslatedTitle,
1438 reason,
1439 helpPage);
1440}
void ShowErrorDialog(const WindowPlacement &placement, const TranslatableString &dlogTitle, const TranslatableString &message, const ManualPageID &helpPage, const ErrorDialogOptions &options={})
Show an error dialog with a link to the manual for further help.
Definition: BasicUI.h:262

References ReservedCommandFlag::Options(), BasicUI::ShowErrorDialog(), and XO().

Referenced by ReportIfActionNotAllowed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TryToMakeActionAllowed()

bool CommandManager::TryToMakeActionAllowed ( CommandFlag flags,
CommandFlag  flagsRqd 
)

Determines if flags for command are compatible with current state. If not, then try some recovery action to make it so.

Returns
whether compatible or not after any actions taken.

Definition at line 1339 of file CommandManager.cpp.

1341{
1342 auto &project = mProject;
1343
1344 if( flags.none() )
1345 flags = GetUpdateFlags();
1346
1347 // Visit the table of recovery actions
1348 auto &enablers = RegisteredMenuItemEnabler::Enablers();
1349 auto iter = enablers.begin(), end = enablers.end();
1350 while ((flags & flagsRqd) != flagsRqd && iter != end) {
1351 const auto &enabler = *iter;
1352 auto actual = enabler.actualFlags();
1353 auto MissingFlags = (~flags & flagsRqd);
1354 if (
1355 // Do we have the right precondition?
1356 (flags & actual) == actual
1357 &&
1358 // Can we get the condition we need?
1359 (MissingFlags & enabler.possibleFlags()).any()
1360 ) {
1361 // Then try the function
1362 enabler.tryEnable( project, flagsRqd );
1363 flags = GetUpdateFlags();
1364 }
1365 ++iter;
1366 }
1367 return (flags & flagsRqd) == flagsRqd;
1368}
CommandFlag GetUpdateFlags(bool quick=false) const
static const MenuItemEnablers & Enablers()
Definition: CommandFlag.cpp:56

References RegisteredMenuItemEnabler::Enablers(), PackedArray::end(), GetUpdateFlags(), mProject, and project.

Referenced by ProjectAudioManager::DoRecord(), and ReportIfActionNotAllowed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateCheckmarks()

void CommandManager::UpdateCheckmarks ( )

Definition at line 339 of file CommandManager.cpp.

340{
341 for (const auto &entry : mCommandList)
342 entry->UpdateCheckmark(mProject);
343}

References entry, mCommandList, and mProject.

Referenced by SelectUtilities::ActivatePlayRegion(), SelectUtilities::InactivatePlayRegion(), ToolManager::ModifyToolbarMenus(), and anonymous_namespace{TimelineMenus.cpp}::SetTimeDisplayMode().

Here is the caller graph for this function:

◆ UpdateMenus()

void CommandManager::UpdateMenus ( bool  checkActive = true)

Definition at line 1486 of file CommandManager.cpp.

1487{
1488 auto &project = mProject;
1489
1490 bool quick = checkActive && ReallyDoQuickCheck();
1491 auto flags = GetUpdateFlags(quick);
1492 // Return from this function if nothing's changed since
1493 // the last time we were here.
1494 if (flags == mLastFlags)
1495 return;
1496 mLastFlags = flags;
1497
1498 auto flags2 = flags;
1499
1500 // We can enable some extra items if we have select-all-on-none.
1501 //EXPLAIN-ME: Why is this here rather than in GetUpdateFlags()?
1502 //ANSWER: Because flags2 is used in the menu enable/disable.
1503 //The effect still needs flags to determine whether it will need
1504 //to actually do the 'select all' to make the command valid.
1505
1506 for ( const auto &enabler : RegisteredMenuItemEnabler::Enablers() ) {
1507 auto actual = enabler.actualFlags();
1508 if (
1509 enabler.applicable( project ) && (flags & actual) == actual
1510 )
1511 flags2 |= enabler.possibleFlags();
1512 }
1513
1514 // With select-all-on-none, some items that we don't want enabled may have
1515 // been enabled, since we changed the flags. Here we manually disable them.
1516 // 0 is grey out, 1 is Autoselect, 2 is Give warnings.
1518 flags2, // the "lax" flags
1519 (mWhatIfNoSelection == 0 ? flags2 : flags) // the "strict" flags
1520 );
1521
1522 Publish({});
1523}
CommandFlag mLastFlags
virtual bool ReallyDoQuickCheck()
Default implementation returns true.
void EnableUsingFlags(CommandFlag flags, CommandFlag strictFlags)
CallbackReturn Publish(const MenuUpdateMessage &message)
Send a message to connected callbacks.
Definition: Observer.h:207

References RegisteredMenuItemEnabler::Enablers(), EnableUsingFlags(), GetUpdateFlags(), mLastFlags, mProject, mWhatIfNoSelection, project, Observer::Publisher< MenuUpdateMessage >::Publish(), and ReallyDoQuickCheck().

Referenced by MacroCommands::ApplyCommandInBatchMode(), EffectUI::DoEffect(), OnUndoRedo(), ProjectWindow::OnUpdateUI(), and ProjectWindow::OnViewportMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdatePrefs()

void CommandManager::UpdatePrefs ( )
overridevirtual

Implements PrefsListener.

Definition at line 133 of file CommandManager.cpp.

134{
135 bool bSelectAllIfNone;
136 gPrefs->Read(wxT("/GUI/SelectAllOnNone"), &bSelectAllIfNone, false);
137 // 0 is grey out, 1 is Autoselect, 2 is Give warnings.
138 // Audacity autoselects or warns.
139 mWhatIfNoSelection = bSelectAllIfNone ? 1 : 2;
140}
virtual bool Read(const wxString &key, bool *value) const =0

References gPrefs, mWhatIfNoSelection, audacity::BasicSettings::Read(), and wxT().

Referenced by CommandManager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteXML()

void CommandManager::WriteXML ( XMLWriter xmlFile) const

Definition at line 1182 of file CommandManager.cpp.

1184{
1185 xmlFile.StartTag(wxT("audacitykeyboard"));
1186 xmlFile.WriteAttr(wxT("audacityversion"), AUDACITY_VERSION_STRING);
1187
1188 for(const auto &entry : mCommandList) {
1189
1190 xmlFile.StartTag(wxT("command"));
1191 xmlFile.WriteAttr(wxT("name"), entry->name);
1192 xmlFile.WriteAttr(wxT("key"), entry->key);
1193 xmlFile.EndTag(wxT("command"));
1194 }
1195
1196 xmlFile.EndTag(wxT("audacitykeyboard"));
1197}
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:79
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:36
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:102

References entry, mCommandList, and wxT().

Referenced by KeyConfigPrefs::OnExport().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ COMMAND

const TranslatableString CommandManager::COMMAND = XO("Command")
staticprotected

Definition at line 56 of file CommandManager.h.

Referenced by GetCategories().

◆ mCommandKeyHash

CommandKeyHash CommandManager::mCommandKeyHash
protected
Invariant
for each [key, value]: for some 0 <= i < NCommands(): value == mCommandList[i].get()

Definition at line 437 of file CommandManager.h.

Referenced by PurgeData().

◆ mCommandList

CommandList CommandManager::mCommandList
private

◆ mCommandNameHash

CommandNameHash CommandManager::mCommandNameHash
private

◆ mCommandNumericIDHash

CommandNumericIDHash CommandManager::mCommandNumericIDHash
private
Invariant
for each [key, value]: for some 0 <= i < NCommands(): value == mCommandList[i].get()

Definition at line 455 of file CommandManager.h.

Referenced by DoRepeatProcess(), Enable(), GetNameFromNumericID(), HandleMenuID(), and PurgeData().

◆ mLastAnalyzer

PluginID CommandManager::mLastAnalyzer {}

◆ mLastAnalyzerRegisteredId

int CommandManager::mLastAnalyzerRegisteredId = -1

Definition at line 96 of file CommandManager.h.

Referenced by RegisterLastAnalyzer().

◆ mLastAnalyzerRegistration

int CommandManager::mLastAnalyzerRegistration = repeattypenone

◆ mLastEffect

PluginID CommandManager::mLastEffect {}

◆ mLastFlags

CommandFlag CommandManager::mLastFlags = AlwaysEnabledFlag

Definition at line 89 of file CommandManager.h.

Referenced by MenuCreator::CreateMenusAndCommands(), and UpdateMenus().

◆ mLastGenerator

PluginID CommandManager::mLastGenerator {}

◆ mLastProcessId

int CommandManager::mLastProcessId
private

◆ mLastTool

PluginID CommandManager::mLastTool {}

Definition at line 97 of file CommandManager.h.

Referenced by PluginMenuItems().

◆ mLastToolRegisteredId

int CommandManager::mLastToolRegisteredId = -1

Definition at line 99 of file CommandManager.h.

Referenced by RegisterLastTool().

◆ mLastToolRegistration

int CommandManager::mLastToolRegistration = repeattypenone

Definition at line 98 of file CommandManager.h.

Referenced by RegisterLastTool().

◆ mNiceName

TranslatableString CommandManager::mNiceName
private

Definition at line 458 of file CommandManager.h.

Referenced by HandleCommandEntry(), RegisterLastAnalyzer(), and RegisterLastTool().

◆ mProject

AudacityProject& CommandManager::mProject
protected

◆ mRepeatAnalyzerFlags

unsigned CommandManager::mRepeatAnalyzerFlags = 0

Definition at line 108 of file CommandManager.h.

◆ mRepeatEffectFlags

unsigned CommandManager::mRepeatEffectFlags = 0

Definition at line 107 of file CommandManager.h.

◆ mRepeatGeneratorFlags

unsigned CommandManager::mRepeatGeneratorFlags = 0

Definition at line 106 of file CommandManager.h.

◆ mRepeatToolFlags

unsigned CommandManager::mRepeatToolFlags = 0

Definition at line 109 of file CommandManager.h.

◆ mStopIfWasPaused

bool CommandManager::mStopIfWasPaused { true }

Definition at line 115 of file CommandManager.h.

◆ mUndoSubscription

const Observer::Subscription CommandManager::mUndoSubscription
private

Definition at line 461 of file CommandManager.h.

◆ mWhatIfNoSelection

int CommandManager::mWhatIfNoSelection

Definition at line 112 of file CommandManager.h.

Referenced by UpdateMenus(), and UpdatePrefs().

◆ mXMLKeysRead

int CommandManager::mXMLKeysRead
private

Definition at line 456 of file CommandManager.h.

Referenced by GetNumberOfKeysRead(), and HandleXMLTag().


The documentation for this class was generated from the following files: