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, TranslatableStrings &prefixes, 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 431 of file CommandManager.h.

◆ CommandList

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

Definition at line 441 of file CommandManager.h.

◆ CommandNameHash

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

Definition at line 445 of file CommandManager.h.

◆ CommandNumericIDHash

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

Definition at line 450 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}
wxString name
Definition: TagsEditor.cpp:166
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:399

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

References entry, anonymous_namespace{Scrubbing.cpp}::finder, audacity::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 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}
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101

References details::begin(), and details::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{Scrubbing.cpp}::finder, audacity::cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, mLastProcessId, and mProject.

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

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(), Scrubber::CheckMenuItems(), ToolManager::CreateWindows(), CommonTrackPanelCell::DoContextMenu(), AudacityApplicationLogic::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{PluginMenus.cpp}::OnSimulateRecordingErrors(), ProjectWindow::OnUpdateUI(), ProjectWindow::OnViewportMessage(), PluginMenuItems(), KeyConfigPrefs::Populate(), Scrubber::PopulatePopupMenu(), 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,
TranslatableStrings prefixes,
bool  includeMultis 
)

Definition at line 1037 of file CommandManager.cpp.

1045{
1046 for(const auto &entry : mCommandList) {
1047 // GetAllCommandData is used by KeyConfigPrefs.
1048 // It does need the effects.
1049 //if ( entry->isEffect )
1050 // continue;
1051 if ( !entry->multi || includeMultis )
1052 {
1053 names.push_back(entry->name);
1054 keys.push_back(entry->key);
1055 default_keys.push_back(entry->defaultKey);
1056 labels.push_back(entry->label);
1057 categories.push_back(entry->labelTop);
1058 prefixes.push_back(entry->labelPrefix);
1059 }
1060 }
1061}
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 1097 of file CommandManager.cpp.

1098{
1099 if (auto iter = mCommandNameHash.find(name);
1100 iter != mCommandNameHash.end())
1101 return iter->second->labelTop;
1102 return {};
1103}

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 1113 of file CommandManager.cpp.

1115{
1116 if (auto iter = mCommandNameHash.find(name);
1117 iter != mCommandNameHash.end())
1118 return iter->second->defaultKey;
1119 return {};
1120}

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 1105 of file CommandManager.cpp.

1106{
1107 if (auto iter = mCommandNameHash.find(name);
1108 iter != mCommandNameHash.end())
1109 return iter->second->key;
1110 return {};
1111}

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 1071 of file CommandManager.cpp.

1072{
1073 if (auto iter = mCommandNameHash.find(name);
1074 iter != mCommandNameHash.end())
1075 return iter->second->longLabel;
1076 return {};
1077}

References mCommandNameHash, and name.

◆ GetNameFromNumericID()

CommandID CommandManager::GetNameFromNumericID ( int  id) const

Definition at line 1063 of file CommandManager.cpp.

1064{
1065 if (auto iter = mCommandNumericIDHash.find(id);
1066 iter != mCommandNumericIDHash.end())
1067 return iter->second->name;
1068 return {};
1069}

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 1080 of file CommandManager.cpp.

1081{
1082 if (auto iter = mCommandNameHash.find(name);
1083 iter != mCommandNameHash.end()
1084 ) {
1085 const auto entry = iter->second;
1086 if (!entry->labelPrefix.empty())
1087 return Verbatim( wxT("%s - %s") )
1088 .Format(entry->labelPrefix, entry->label)
1089 .Stripped();
1090 else
1091 return entry->label.Stripped();
1092 }
1093 return {};
1094}
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 1281 of file CommandManager.cpp.

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

1174{
1175 return this;
1176}

◆ HandleXMLEndTag()

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

Definition at line 1160 of file CommandManager.cpp.

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

◆ HandleXMLTag()

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

Implements XMLTagHandler.

Definition at line 1122 of file CommandManager.cpp.

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

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 1438 of file CommandManager.cpp.

1439{
1440 auto &project = mProject;
1442 auto &undoManager = UndoManager::Get( project );
1443 int cur = undoManager.GetCurrentState();
1444
1445 if (undoManager.UndoAvailable()) {
1446 undoManager.GetShortDescription(cur, &desc);
1447 Modify(wxT("Undo"), XXO("&Undo %s").Format(desc));
1448 Enable(wxT("Undo"), ProjectHistory::Get(project).UndoAvailable());
1449 }
1450 else {
1451 Modify(wxT("Undo"), XXO("&Undo"));
1452 }
1453
1454 if (undoManager.RedoAvailable()) {
1455 undoManager.GetShortDescription(cur+1, &desc);
1456 Modify(wxT("Redo"), XXO("&Redo %s").Format( desc ));
1457 Enable(wxT("Redo"), ProjectHistory::Get(project).RedoAvailable());
1458 }
1459 else {
1460 Modify(wxT("Redo"), XXO("&Redo"));
1461 Enable(wxT("Redo"), false);
1462 }
1463}
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 1465 of file CommandManager.cpp.

1466{
1467 switch (message.type) {
1472 break;
1473 default:
1474 return;
1475 }
1477 UpdateMenus();
1478}
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 1521 of file CommandManager.cpp.

1522{
1523 return true;
1524}

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 1257 of file CommandManager.cpp.

1258{
1259 TranslatableString disabledShortcuts;
1260
1261 for (auto& entry : mCommandList) {
1262 if (!entry->key.empty() && entry->key != entry->defaultKey) { // user assigned
1263 for (auto& entry2 : mCommandList) {
1264 if (!entry2->key.empty() && entry2->key == entry2->defaultKey) { // default
1265 if (entry2->key == entry->key) {
1266 auto name = wxT("/NewKeys/") + entry2->name.GET();
1268
1269 disabledShortcuts +=
1270 XO("\n* %s, because you have assigned the shortcut %s to %s")
1271 .Format(entry2->label.Strip(), entry->key.GET(), entry->label.Strip());
1272 }
1273 }
1274 }
1275 }
1276 }
1277
1278 return disabledShortcuts;
1279}
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 1321 of file CommandManager.cpp.

1323{
1324 auto &project = mProject;
1325 bool bAllowed = TryToMakeActionAllowed( flags, flagsRqd );
1326 if( bAllowed )
1327 return true;
1328 TellUserWhyDisallowed( Name, flags & flagsRqd, flagsRqd);
1329 return false;
1330}
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 1203 of file CommandManager.cpp.

1205{
1206 if (auto iter = mCommandNameHash.find(name);
1207 iter != mCommandNameHash.end())
1208 iter->second->flags = flags;
1209}

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 1366 of file CommandManager.cpp.

1368{
1369 // The default string for 'reason' is a catch all. I hope it won't ever be seen
1370 // and that we will get something more specific.
1371 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.");
1372 // The default title string is 'Disallowed'.
1373 auto untranslatedTitle = XO("Disallowed");
1374 wxString helpPage;
1375
1376 bool enableDefaultMessage = true;
1377 bool defaultMessage = true;
1378
1379 auto doOption = [&](const CommandFlagOptions &options) {
1380 if ( options.message ) {
1381 reason = options.message( Name );
1382 defaultMessage = false;
1383 if ( !options.title.empty() )
1384 untranslatedTitle = options.title;
1385 helpPage = options.helpPage;
1386 return true;
1387 }
1388 else {
1389 enableDefaultMessage =
1390 enableDefaultMessage && options.enableDefaultMessage;
1391 return false;
1392 }
1393 };
1394
1395 const auto &alloptions = ReservedCommandFlag::Options();
1396 auto missingFlags = flagsRequired & ~flagsGot;
1397
1398 // Find greatest priority
1399 unsigned priority = 0;
1400 for ( const auto &options : alloptions )
1401 priority = std::max( priority, options.priority );
1402
1403 // Visit all unsatisfied conditions' options, by descending priority,
1404 // stopping when we find a message
1405 ++priority;
1406 while( priority-- ) {
1407 size_t ii = 0;
1408 for ( const auto &options : alloptions ) {
1409 if (
1410 priority == options.priority
1411 &&
1412 missingFlags[ii]
1413 &&
1414 doOption( options ) )
1415 goto done;
1416
1417 ++ii;
1418 }
1419 }
1420 done:
1421
1422 if (
1423 // didn't find a message
1424 defaultMessage
1425 &&
1426 // did find a condition that suppresses the default message
1427 !enableDefaultMessage
1428 )
1429 return;
1430
1431 // Does not have the warning icon...
1433 untranslatedTitle,
1434 reason,
1435 helpPage);
1436}
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:272

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 1335 of file CommandManager.cpp.

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

References RegisteredMenuItemEnabler::Enablers(), details::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 1482 of file CommandManager.cpp.

1483{
1484 auto &project = mProject;
1485
1486 bool quick = checkActive && ReallyDoQuickCheck();
1487 auto flags = GetUpdateFlags(quick);
1488 // Return from this function if nothing's changed since
1489 // the last time we were here.
1490 if (flags == mLastFlags)
1491 return;
1492 mLastFlags = flags;
1493
1494 auto flags2 = flags;
1495
1496 // We can enable some extra items if we have select-all-on-none.
1497 //EXPLAIN-ME: Why is this here rather than in GetUpdateFlags()?
1498 //ANSWER: Because flags2 is used in the menu enable/disable.
1499 //The effect still needs flags to determine whether it will need
1500 //to actually do the 'select all' to make the command valid.
1501
1502 for ( const auto &enabler : RegisteredMenuItemEnabler::Enablers() ) {
1503 auto actual = enabler.actualFlags();
1504 if (
1505 enabler.applicable( project ) && (flags & actual) == actual
1506 )
1507 flags2 |= enabler.possibleFlags();
1508 }
1509
1510 // With select-all-on-none, some items that we don't want enabled may have
1511 // been enabled, since we changed the flags. Here we manually disable them.
1512 // 0 is grey out, 1 is Autoselect, 2 is Give warnings.
1514 flags2, // the "lax" flags
1515 (mWhatIfNoSelection == 0 ? flags2 : flags) // the "strict" flags
1516 );
1517
1518 Publish({});
1519}
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(), AudacityApplicationLogic::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 1178 of file CommandManager.cpp.

1180{
1181 xmlFile.StartTag(wxT("audacitykeyboard"));
1182 xmlFile.WriteAttr(wxT("audacityversion"), AUDACITY_VERSION_STRING);
1183
1184 for(const auto &entry : mCommandList) {
1185
1186 xmlFile.StartTag(wxT("command"));
1187 xmlFile.WriteAttr(wxT("name"), entry->name);
1188 xmlFile.WriteAttr(wxT("key"), entry->key);
1189 xmlFile.EndTag(wxT("command"));
1190 }
1191
1192 xmlFile.EndTag(wxT("audacitykeyboard"));
1193}
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 435 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 453 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 456 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 459 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 454 of file CommandManager.h.

Referenced by GetNumberOfKeysRead(), and HandleXMLTag().


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