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

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  GlobalMenuHook
 
struct  Options
 

Public Types

enum  TextualCommandResult { CommandFailure , CommandSuccess , CommandNotFound }
 
using CheckFn = std::function< bool(AudacityProject &) >
 

Public Member Functions

 CommandManager ()
 
virtual ~CommandManager ()
 
 CommandManager (const CommandManager &)=delete
 
CommandManageroperator= (const CommandManager &)=delete
 
void SetMaxList ()
 
void PurgeData ()
 
std::unique_ptr< wxMenuBar > AddMenuBar (const wxString &sMenu)
 
wxMenu * BeginMenu (const TranslatableString &tName)
 
void EndMenu ()
 This attaches a menu, if it's main, to the menubar. More...
 
void AddItemList (const CommandID &name, const ComponentInterfaceSymbol items[], size_t nItems, CommandHandlerFinder finder, CommandFunctorPointer callback, CommandFlag flags, bool bIsEffect=false)
 
void AddItem (AudacityProject &project, const CommandID &name, const TranslatableString &label_in, CommandHandlerFinder finder, CommandFunctorPointer callback, CommandFlag flags, const Options &options={})
 
void AddSeparator ()
 
void PopMenuBar ()
 
void BeginOccultCommands ()
 
void EndOccultCommands ()
 
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 FilterKeyEvent (AudacityProject *project, const wxKeyEvent &evt, bool permit=false)
 
bool HandleMenuID (AudacityProject &project, 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 (AudacityProject &)
 
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)
 
TranslatableString GetLabelFromName (const CommandID &name)
 
TranslatableString GetPrefixedLabelFromName (const CommandID &name)
 
TranslatableString GetCategoryFromName (const CommandID &name)
 
NormalizedKeyString GetKeyFromName (const CommandID &name) const
 
NormalizedKeyString GetDefaultKeyFromName (const CommandID &name)
 
bool GetEnabled (const CommandID &name)
 
int GetNumberOfKeysRead () const
 
void RemoveDuplicateShortcuts ()
 
void WriteXML (XMLWriter &xmlFile) const
 
TranslatableString DescribeCommandsAndShortcuts (const ComponentInterfaceSymbol commands[], size_t nCommands) const
 
wxMenu * CurrentMenu () const
 
void UpdateCheckmarks (AudacityProject &project)
 
wxString FormatLabelForMenu (const CommandID &id, const TranslatableString *pLabel) const
 Format a string appropriate for insertion in a menu. More...
 
- 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 ()
 

Static Public Member Functions

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

Private Member Functions

int NextIdentifier (int ID)
 
CommandListEntryNewIdentifier (const CommandID &name, const TranslatableString &label, wxMenu *menu, CommandHandlerFinder finder, CommandFunctorPointer callback, const CommandID &nameSuffix, int index, int count, const Options &options)
 
void AddGlobalCommand (const CommandID &name, const TranslatableString &label, CommandHandlerFinder finder, CommandFunctorPointer callback, const Options &options={})
 
bool HandleCommandEntry (AudacityProject &project, const CommandListEntry *entry, CommandFlag flags, bool alwaysEnabled, const wxEvent *evt=nullptr, const CommandContext *pGivenContext=nullptr)
 
void Enable (CommandListEntry *entry, bool enabled)
 
wxMenu * BeginMainMenu (const TranslatableString &tName)
 
void EndMainMenu ()
 
wxMenu * BeginSubMenu (const TranslatableString &tName)
 
void EndSubMenu ()
 
wxMenuBar * CurrentMenuBar () const
 
wxMenuBar * GetMenuBar (const wxString &sMenu) const
 
wxMenu * CurrentSubMenu () const
 
wxString FormatLabelForMenu (const CommandListEntry *entry) const
 
wxString FormatLabelForMenu (const TranslatableString &translatableLabel, const NormalizedKeyString &keyStr) const
 
wxString FormatLabelWithDisabledAccel (const CommandListEntry *entry) const
 
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
 

Private Attributes

std::vector< NormalizedKeyStringmMaxListOnly
 
MenuBarList mMenuBarList
 
SubMenuList mSubMenuList
 
CommandList mCommandList
 
CommandNameHash mCommandNameHash
 
CommandKeyHash mCommandKeyHash
 
CommandNumericIDHash mCommandNumericIDHash
 
int mCurrentID
 
int mXMLKeysRead
 
bool mbSeparatorAllowed
 
TranslatableString mCurrentMenuName
 
TranslatableString mNiceName
 
int mLastProcessId
 
std::unique_ptr< wxMenu > uCurrentMenu
 
wxMenu * mCurrentMenu {}
 
bool bMakingOccultCommands
 
std::unique_ptr< wxMenuBar > mTempMenuBar
 

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 60 of file CommandManager.h.

Member Typedef Documentation

◆ CheckFn

using CommandManager::CheckFn = std::function< bool(AudacityProject&) >

Definition at line 97 of file CommandManager.h.

Member Enumeration Documentation

◆ TextualCommandResult

Enumerator
CommandFailure 
CommandSuccess 
CommandNotFound 

Definition at line 224 of file CommandManager.h.

Constructor & Destructor Documentation

◆ CommandManager() [1/2]

CommandManager::CommandManager ( )

Standard Constructor

Definition at line 219 of file CommandManager.cpp.

219 :
220 mCurrentID(17000),
222 bMakingOccultCommands( false )
223{
224 mbSeparatorAllowed = false;
225 SetMaxList();
226 mLastProcessId = 0;
227}
#define COMMAND
TranslatableString mCurrentMenuName
bool bMakingOccultCommands

References mbSeparatorAllowed, mLastProcessId, and SetMaxList().

Here is the call graph for this function:

◆ ~CommandManager()

CommandManager::~CommandManager ( )
virtual

Class Destructor. Includes PurgeData, which removes menubars

Definition at line 232 of file CommandManager.cpp.

233{
234 //WARNING: This removes menubars that could still be assigned to windows!
235 PurgeData();
236}

References PurgeData().

Here is the call graph for this function:

◆ CommandManager() [2/2]

CommandManager::CommandManager ( const CommandManager )
delete

Member Function Documentation

◆ AddGlobalCommand()

void CommandManager::AddGlobalCommand ( const CommandID name,
const TranslatableString label,
CommandHandlerFinder  finder,
CommandFunctorPointer  callback,
const Options options = {} 
)
private

Definition at line 617 of file CommandManager.cpp.

622{
624 NewIdentifier(name, label_in, NULL, finder, callback,
625 {}, 0, 0, options);
626
627 entry->enabled = false;
628 entry->isGlobal = true;
629 entry->flags = AlwaysEnabledFlag;
630}
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:34
const TranslatableString name
Definition: Distortion.cpp:76
static ProjectFileIORegistry::AttributeWriterEntry entry
CommandListEntry * NewIdentifier(const CommandID &name, const TranslatableString &label, wxMenu *menu, CommandHandlerFinder finder, CommandFunctorPointer callback, const CommandID &nameSuffix, int index, int count, const Options &options)
CommandListEntry is a structure used by CommandManager.

References AlwaysEnabledFlag, entry, name, and NewIdentifier().

Referenced by AddItem().

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

◆ AddItem()

void CommandManager::AddItem ( AudacityProject project,
const CommandID name,
const TranslatableString label_in,
CommandHandlerFinder  finder,
CommandFunctorPointer  callback,
CommandFlag  flags,
const Options options = {} 
)

Definition at line 531 of file CommandManager.cpp.

538{
539 if (options.global) {
540 //wxASSERT( flags == AlwaysEnabledFlag );
542 name, label_in, finder, callback, options );
543 return;
544 }
545
546 wxASSERT( flags != NoFlagsSpecified );
547
550 label_in,
551 CurrentMenu(), finder, callback,
552 {}, 0, 0,
553 options);
554 entry->useStrictFlags = options.useStrictFlags;
555 int ID = entry->id;
557
558 SetCommandFlags(name, flags);
559
560
561 auto &checker = options.checker;
562 if (checker) {
563 CurrentMenu()->AppendCheckItem(ID, label);
564 CurrentMenu()->Check(ID, checker( project ));
565 }
566 else {
567 CurrentMenu()->Append(ID, label);
568 }
569
570 mbSeparatorAllowed = true;
571}
constexpr CommandFlag NoFlagsSpecified
Definition: CommandFlag.h:35
TranslatableString label
Definition: TagsEditor.cpp:165
const auto project
void AddGlobalCommand(const CommandID &name, const TranslatableString &label, CommandHandlerFinder finder, CommandFunctorPointer callback, const Options &options={})
wxString FormatLabelWithDisabledAccel(const CommandListEntry *entry) const
wxMenu * CurrentMenu() const
void SetCommandFlags(const CommandID &name, CommandFlag flags)

References AddGlobalCommand(), CommandManager::Options::checker, CurrentMenu(), entry, FormatLabelWithDisabledAccel(), CommandManager::Options::global, label, mbSeparatorAllowed, name, NewIdentifier(), NoFlagsSpecified, project, SetCommandFlags(), and CommandManager::Options::useStrictFlags.

Here is the call graph for this function:

◆ AddItemList()

void CommandManager::AddItemList ( const CommandID name,
const ComponentInterfaceSymbol  items[],
size_t  nItems,
CommandHandlerFinder  finder,
CommandFunctorPointer  callback,
CommandFlag  flags,
bool  bIsEffect = false 
)

Add a list of menu items to the current menu. When the user selects any one of these, the given functor will be called with its position in the list as the index number. When you call Enable on this command name, it will enable or disable all of the items at once.

Definition at line 591 of file CommandManager.cpp.

598{
599 for (size_t i = 0, cnt = nItems; i < cnt; i++) {
602 items[i].Msgid(),
603 CurrentMenu(),
604 finder,
605 callback,
606 items[i].Internal(),
607 i,
608 cnt,
609 Options{}
610 .IsEffect(bIsEffect));
611 entry->flags = flags;
612 CurrentMenu()->Append(entry->id, FormatLabelForMenu(entry));
613 mbSeparatorAllowed = true;
614 }
615}
@ Internal
Indicates internal failure from Audacity.
wxString FormatLabelForMenu(const CommandID &id, const TranslatableString *pLabel) const
Format a string appropriate for insertion in a menu.
Options && IsEffect(bool value=true) &&

References CurrentMenu(), entry, FormatLabelForMenu(), Internal, CommandManager::Options::IsEffect(), mbSeparatorAllowed, name, and NewIdentifier().

Here is the call graph for this function:

◆ AddMenuBar()

std::unique_ptr< wxMenuBar > CommandManager::AddMenuBar ( const wxString &  sMenu)

Makes a NEW menubar for placement on the top of a project Names it according to the passed-in string argument.

If the menubar already exists, that's unexpected.

Definition at line 350 of file CommandManager.cpp.

351{
352 wxMenuBar *menuBar = GetMenuBar(sMenu);
353 if (menuBar) {
354 wxASSERT(false);
355 return {};
356 }
357
358 auto result = std::make_unique<wxMenuBar>();
359 mMenuBarList.emplace_back(sMenu, result.get());
360
361 return result;
362}
MenuBarList mMenuBarList
wxMenuBar * GetMenuBar(const wxString &sMenu) const

References GetMenuBar(), and mMenuBarList.

Referenced by BeginOccultCommands().

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

◆ AddSeparator()

void CommandManager::AddSeparator ( )

Definition at line 632 of file CommandManager.cpp.

633{
635 CurrentMenu()->AppendSeparator();
636 mbSeparatorAllowed = false; // boolean to prevent too many separators.
637}

References CurrentMenu(), and mbSeparatorAllowed.

Here is the call graph for this function:

◆ BeginMainMenu()

wxMenu * CommandManager::BeginMainMenu ( const TranslatableString tName)
private

This starts a NEW menu

Definition at line 434 of file CommandManager.cpp.

435{
436 uCurrentMenu = std::make_unique<wxMenu>();
438 mCurrentMenuName = tName;
439 return mCurrentMenu;
440}
std::unique_ptr< wxMenu > uCurrentMenu
wxMenu * mCurrentMenu

References mCurrentMenu, mCurrentMenuName, and uCurrentMenu.

Referenced by BeginMenu().

Here is the caller graph for this function:

◆ BeginMenu()

wxMenu * CommandManager::BeginMenu ( const TranslatableString tName)

This starts a NEW menu

Definition at line 409 of file CommandManager.cpp.

410{
411 if ( mCurrentMenu )
412 return BeginSubMenu( tName );
413 else
414 return BeginMainMenu( tName );
415}
wxMenu * BeginSubMenu(const TranslatableString &tName)
wxMenu * BeginMainMenu(const TranslatableString &tName)

References BeginMainMenu(), BeginSubMenu(), and mCurrentMenu.

Here is the call graph for this function:

◆ BeginOccultCommands()

void CommandManager::BeginOccultCommands ( )

Definition at line 1612 of file CommandManager.cpp.

1613{
1614 // To do: perhaps allow occult item switching at lower levels of the
1615 // menu tree.
1616 wxASSERT( !CurrentMenu() );
1617
1618 // Make a temporary menu bar collecting items added after.
1619 // This bar will be discarded but other side effects on the command
1620 // manager persist.
1621 mTempMenuBar = AddMenuBar(wxT("ext-menu"));
1622 bMakingOccultCommands = true;
1623}
wxT("CloseDown"))
std::unique_ptr< wxMenuBar > mTempMenuBar
std::unique_ptr< wxMenuBar > AddMenuBar(const wxString &sMenu)

References AddMenuBar(), bMakingOccultCommands, CurrentMenu(), mTempMenuBar, and wxT().

Here is the call graph for this function:

◆ BeginSubMenu()

wxMenu * CommandManager::BeginSubMenu ( const TranslatableString tName)
private

This starts a NEW submenu, and names it according to the function's argument.

Definition at line 462 of file CommandManager.cpp.

463{
464 mSubMenuList.emplace_back( tName );
465 mbSeparatorAllowed = false;
466 return mSubMenuList.back().menu.get();
467}
SubMenuList mSubMenuList

References mbSeparatorAllowed, and mSubMenuList.

Referenced by BeginMenu().

Here is the caller graph for this function:

◆ Check()

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

Definition at line 1009 of file CommandManager.cpp.

1010{
1012 if (!entry || !entry->menu || entry->isOccult) {
1013 return;
1014 }
1015 entry->menu->Check(entry->id, checked);
1016}
CommandNameHash mCommandNameHash

References entry, mCommandNameHash, and name.

◆ CurrentMenu()

wxMenu * CommandManager::CurrentMenu ( ) const

This returns the current menu that we're appending to - note that it could be a submenu if BeginSubMenu was called and we haven't reached EndSubMenu yet.

Definition at line 505 of file CommandManager.cpp.

506{
507 if(!mCurrentMenu)
508 return NULL;
509
510 wxMenu * tmpCurrentSubMenu = CurrentSubMenu();
511
512 if(!tmpCurrentSubMenu)
513 {
514 return mCurrentMenu;
515 }
516
517 return tmpCurrentSubMenu;
518}
wxMenu * CurrentSubMenu() const

References CurrentSubMenu(), and mCurrentMenu.

Referenced by AddItem(), AddItemList(), AddSeparator(), BeginOccultCommands(), and EndSubMenu().

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

◆ CurrentMenuBar()

wxMenuBar * CommandManager::CurrentMenuBar ( ) const
private

Retrieve the 'current' menubar; either NULL or the last on in the mMenuBarList.

Definition at line 383 of file CommandManager.cpp.

384{
385 if(mMenuBarList.empty())
386 return NULL;
387
388 return mMenuBarList.back().menubar;
389}

References mMenuBarList.

Referenced by EndMainMenu().

Here is the caller graph for this function:

◆ CurrentSubMenu()

wxMenu * CommandManager::CurrentSubMenu ( ) const
private

This returns the 'Current' Submenu, which is the one at the end of the mSubMenuList (or NULL, if it doesn't exist).

Definition at line 493 of file CommandManager.cpp.

494{
495 if(mSubMenuList.empty())
496 return NULL;
497
498 return mSubMenuList.back().menu.get();
499}

References mSubMenuList.

Referenced by CurrentMenu().

Here is the caller graph for this function:

◆ DescribeCommandsAndShortcuts()

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

Formatting summaries that include shortcut keys

Definition at line 1043 of file CommandManager.cpp.

1045{
1046 wxString mark;
1047 // This depends on the language setting and may change in-session after
1048 // change of preferences:
1049 bool rtl = (wxLayout_RightToLeft == wxTheApp->GetLayoutDirection());
1050 if (rtl)
1051 mark = wxT("\u200f");
1052
1053 static const wxString &separatorFormat = wxT("%s / %s");
1054 TranslatableString result;
1055 for (size_t ii = 0; ii < nCommands; ++ii) {
1056 const auto &pair = commands[ii];
1057 // If RTL, then the control character forces right-to-left sequencing of
1058 // "/" -separated command names, and puts any "(...)" shortcuts to the
1059 // left, consistently with accelerators in menus (assuming matching
1060 // operating system preferences for language), even if the command name
1061 // was missing from the translation file and defaulted to the English.
1062
1063 // Note: not putting this and other short format strings in the
1064 // translation catalogs
1065 auto piece = Verbatim( wxT("%s%s") )
1066 .Format( mark, pair.Msgid().Stripped() );
1067
1068 auto name = pair.Internal();
1069 if (!name.empty()) {
1070 auto keyStr = GetKeyFromName(name);
1071 if (!keyStr.empty()){
1072 auto keyString = keyStr.Display(true);
1073 auto format = wxT("%s %s(%s)");
1074#ifdef __WXMAC__
1075 // The unicode controls push and pop left-to-right embedding.
1076 // This keeps the directionally weak characters, such as uparrow
1077 // for Shift, left of the key name,
1078 // consistently with how menu accelerators appear, even when the
1079 // system language is RTL.
1080 format = wxT("%s %s(\u202a%s\u202c)");
1081#endif
1082 // The mark makes correctly placed parentheses for RTL, even
1083 // in the case that the piece is untranslated.
1084 piece = Verbatim( format ).Format( piece, mark, keyString );
1085 }
1086 }
1087
1088 if (result.empty())
1089 result = piece;
1090 else
1091 result = Verbatim( separatorFormat ).Format( result, piece );
1092 }
1093 return result;
1094}
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.

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

Here is the call graph for this function:

◆ DoRepeatProcess()

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

Definition at line 1315 of file CommandManager.cpp.

1315 {
1316 mLastProcessId = 0; //Don't Process this as repeat
1318 // Discriminate the union entry->callback by entry->finder
1319 if (auto &finder = entry->finder) {
1320 auto &handler = finder(context.project);
1321 (handler.*(entry->callback.memberFn))(context);
1322 }
1323 else
1324 (entry->callback.nonMemberFn)(context);
1325}
int id
AudacityProject & project
CommandNumericIDHash mCommandNumericIDHash

References entry, cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, id, 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 911 of file CommandManager.cpp.

912{
913 if (!entry->menu) {
914 entry->enabled = enabled;
915 return;
916 }
917
918 // LL: Refresh from real state as we can get out of sync on the
919 // Mac due to its reluctance to enable menus when in a modal
920 // state.
921 entry->enabled = entry->menu->IsEnabled(entry->id);
922
923 // Only enabled if needed
924 if (entry->enabled != enabled) {
925 entry->menu->Enable(entry->id, enabled);
926 entry->enabled = entry->menu->IsEnabled(entry->id);
927 }
928
929 if (entry->multi) {
930 int i;
931 int ID = entry->id;
932
933 for(i=1; i<entry->count; i++) {
934 ID = NextIdentifier(ID);
935
936 // This menu item is not necessarily in the same menu, because
937 // multi-items can be spread across multiple sub menus
938 CommandListEntry *multiEntry = mCommandNumericIDHash[ID];
939 if (multiEntry) {
940 wxMenuItem *item = multiEntry->menu->FindItem(ID);
941
942 if (item) {
943 item->Enable(enabled);
944 } else {
945 // using GET in a log message for devs' eyes only
946 wxLogDebug(wxT("Warning: Menu entry with id %i in %s not found"),
947 ID, entry->name.GET());
948 }
949 } else {
950 wxLogDebug(wxT("Warning: Menu entry with id %i not in hash"), ID);
951 }
952 }
953 }
954}
int NextIdentifier(int ID)
wxMenu * menu

References entry, mCommandNumericIDHash, CommandListEntry::menu, 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 956 of file CommandManager.cpp.

957{
959 if (!entry || !entry->menu) {
960 wxLogDebug(wxT("Warning: Unknown command enabled: '%s'"),
961 (const wxChar*)name);
962 return;
963 }
964
965 Enable(entry, enabled);
966}
void Enable(const wxString &name, bool enabled)

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

Referenced by Enable(), and EnableUsingFlags().

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

970{
971 // strictFlags are a subset of flags. strictFlags represent the real
972 // conditions now, but flags are the conditions that could be made true.
973 // Some commands use strict flags only, refusing the chance to fix
974 // conditions
975 wxASSERT( (strictFlags & ~flags).none() );
976
977 for(const auto &entry : mCommandList) {
978 if (entry->multi && entry->index != 0)
979 continue;
980 if( entry->isOccult )
981 continue;
982
983 auto useFlags = entry->useStrictFlags ? strictFlags : flags;
984
985 if (entry->flags.any()) {
986 bool enable = ((useFlags & entry->flags) == entry->flags);
987 Enable(entry.get(), enable);
988 }
989 }
990}
@ none
Definition: Dither.h:20
CommandList mCommandList

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

Here is the call graph for this function:

◆ EndMainMenu()

void CommandManager::EndMainMenu ( )
private

This attaches a menu to the menubar and ends the menu

Definition at line 446 of file CommandManager.cpp.

447{
448 // Add the menu to the menubar after all menu items have been
449 // added to the menu to allow OSX to rearrange special menu
450 // items like Preferences, About, and Quit.
451 wxASSERT(uCurrentMenu);
452 CurrentMenuBar()->Append(
454 mCurrentMenu = nullptr;
456}
wxMenuBar * CurrentMenuBar() const
wxString Translation() const

References COMMAND, CurrentMenuBar(), mCurrentMenu, mCurrentMenuName, TranslatableString::Translation(), and uCurrentMenu.

Referenced by EndMenu().

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

◆ EndMenu()

void CommandManager::EndMenu ( )

This attaches a menu, if it's main, to the menubar.

Definition at line 422 of file CommandManager.cpp.

423{
424 if ( mSubMenuList.empty() )
425 EndMainMenu();
426 else
427 EndSubMenu();
428}

References EndMainMenu(), EndSubMenu(), and mSubMenuList.

Here is the call graph for this function:

◆ EndOccultCommands()

void CommandManager::EndOccultCommands ( )

Definition at line 1625 of file CommandManager.cpp.

1626{
1627 PopMenuBar();
1628 bMakingOccultCommands = false;
1629 mTempMenuBar.reset();
1630}

References bMakingOccultCommands, mTempMenuBar, and PopMenuBar().

Here is the call graph for this function:

◆ EndSubMenu()

void CommandManager::EndSubMenu ( )
private

This function is called after the final item of a SUBmenu is added. Submenu items are added just like regular menu items; they just happen after BeginSubMenu() is called but before EndSubMenu() is called.

Definition at line 474 of file CommandManager.cpp.

475{
476 //Save the submenu's information
477 SubMenuListEntry tmpSubMenu{ std::move( mSubMenuList.back() ) };
478
479 //Pop off the NEW submenu so CurrentMenu returns the parent of the submenu
480 mSubMenuList.pop_back();
481
482 //Add the submenu to the current menu
483 auto name = tmpSubMenu.name.Translation();
484 CurrentMenu()->Append(0, name, tmpSubMenu.menu.release(),
485 name /* help string */ );
486 mbSeparatorAllowed = true;
487}
SubMenuListEntry is a structure used by CommandManager.

References CurrentMenu(), mbSeparatorAllowed, mSubMenuList, name, and TranslatableString::Translation().

Referenced by EndMenu().

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

239{
240 static const auto list = [] {
241 // These short cuts are for the max list only....
242 const char *const strings[] = {
243 // "Ctrl+I",
244 "Ctrl+Alt+I",
245 "Ctrl+J",
246 "Ctrl+Alt+J",
247 "Ctrl+Alt+V",
248 "Alt+X",
249 "Alt+K",
250 "Shift+Alt+X",
251 "Shift+Alt+K",
252 "Alt+L",
253 "Shift+Alt+C",
254 "Alt+I",
255 "Alt+J",
256 "Shift+Alt+J",
257 "Ctrl+Shift+A",
258 //"Q",
259 //"Shift+J",
260 //"Shift+K",
261 //"Shift+Home",
262 //"Shift+End",
263 "Ctrl+[",
264 "Ctrl+]",
265 "1",
266 "Shift+F5",
267 "Shift+F6",
268 "Shift+F7",
269 "Shift+F8",
270 "Ctrl+Shift+F5",
271 "Ctrl+Shift+F7",
272 "Ctrl+Shift+N",
273 "Ctrl+Shift+M",
274 "Ctrl+Home",
275 "Ctrl+End",
276 "Shift+C",
277 "Alt+Shift+Up",
278 "Alt+Shift+Down",
279 "Shift+P",
280 "Alt+Shift+Left",
281 "Alt+Shift+Right",
282 "Ctrl+Shift+T",
283 //"Command+M",
284 //"Option+Command+M",
285 "Shift+H",
286 "Shift+O",
287 "Shift+I",
288 "Shift+N",
289 "D",
290 "A",
291 "Alt+Shift+F6",
292 "Alt+F6",
293 };
294
295 std::vector<NormalizedKeyString> result(
296 std::begin(strings), std::end(strings)
297 );
298 std::sort( result.begin(), result.end() );
299 return result;
300 }();
301 return list;
302}
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 SetMaxList().

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

◆ FilterKeyEvent()

bool CommandManager::FilterKeyEvent ( AudacityProject project,
const wxKeyEvent &  evt,
bool  permit = false 
)

Definition at line 1099 of file CommandManager.cpp.

1100{
1101 if (!project)
1102 return false;
1103
1104 auto pWindow = FindProjectFrame( project );
1106 if (entry == NULL)
1107 {
1108 return false;
1109 }
1110
1111 int type = evt.GetEventType();
1112
1113 // Global commands aren't tied to any specific project
1114 if (entry->isGlobal && type == wxEVT_KEY_DOWN)
1115 {
1116 // Global commands are always disabled so they do not interfere with the
1117 // rest of the command handling. But, to use the common handler, we
1118 // enable them temporarily and then disable them again after handling.
1119 // LL: Why do they need to be disabled???
1120 entry->enabled = false;
1121 auto cleanup = valueRestorer( entry->enabled, true );
1122 return HandleCommandEntry(*project, entry, NoFlagsSpecified, false, &evt);
1123 }
1124
1125 wxWindow * pFocus = wxWindow::FindFocus();
1126 wxWindow * pParent = wxGetTopLevelParent( pFocus );
1127 bool validTarget = pParent == pWindow;
1128 // Bug 1557. MixerBoard should count as 'destined for project'
1129 // MixerBoard IS a TopLevelWindow, and its parent is the project.
1130 if( pParent && pParent->GetParent() == pWindow ){
1131 if(auto keystrokeHandlingWindow = dynamic_cast< TopLevelKeystrokeHandlingWindow* >( pParent ))
1132 validTarget = keystrokeHandlingWindow->HandleCommandKeystrokes();
1133 }
1134 validTarget = validTarget && wxEventLoop::GetActive()->IsMain();
1135
1136 // Any other keypresses must be destined for this project window
1137 if (!permit && !validTarget )
1138 {
1139 return false;
1140 }
1141
1142 auto flags = MenuManager::Get(*project).GetUpdateFlags();
1143
1144 wxKeyEvent temp = evt;
1145
1146 // Possibly let wxWidgets do its normal key handling IF it is one of
1147 // the standard navigation keys.
1148 if((type == wxEVT_KEY_DOWN) || (type == wxEVT_KEY_UP ))
1149 {
1150 wxWindow * pWnd = wxWindow::FindFocus();
1151 bool bIntercept =
1152 pWnd && !dynamic_cast< NonKeystrokeInterceptingWindow * >( pWnd );
1153
1154 //wxLogDebug("Focus: %p TrackPanel: %p", pWnd, pTrackPanel );
1155 // We allow the keystrokes below to be handled by wxWidgets controls IF we are
1156 // in some sub window rather than in the TrackPanel itself.
1157 // Otherwise they will go to our command handler and if it handles them
1158 // they will NOT be available to wxWidgets.
1159 if( bIntercept ){
1160 switch( evt.GetKeyCode() ){
1161 case WXK_LEFT:
1162 case WXK_RIGHT:
1163 case WXK_UP:
1164 case WXK_DOWN:
1165 // Don't trap WXK_SPACE (Bug 1727 - SPACE not starting/stopping playback
1166 // when cursor is in a time control)
1167 // case WXK_SPACE:
1168 case WXK_TAB:
1169 case WXK_BACK:
1170 case WXK_HOME:
1171 case WXK_END:
1172 case WXK_RETURN:
1173 case WXK_NUMPAD_ENTER:
1174 case WXK_DELETE:
1175 case '0':
1176 case '1':
1177 case '2':
1178 case '3':
1179 case '4':
1180 case '5':
1181 case '6':
1182 case '7':
1183 case '8':
1184 case '9':
1185 return false;
1186 case ',':
1187 case '.':
1188 if (!evt.HasAnyModifiers())
1189 return false;
1190 }
1191 }
1192 }
1193
1194 if (type == wxEVT_KEY_DOWN)
1195 {
1196 if (entry->skipKeydown)
1197 {
1198 return true;
1199 }
1200 return HandleCommandEntry(*project, entry, flags, false, &temp);
1201 }
1202
1203 if (type == wxEVT_KEY_UP && entry->wantKeyup)
1204 {
1205 return HandleCommandEntry(*project, entry, flags, false, &temp);
1206 }
1207
1208 return false;
1209}
NormalizedKeyString KeyEventToKeyString(const wxKeyEvent &event)
Definition: Keyboard.cpp:83
ValueRestorer< T > valueRestorer(T &var)
inline functions provide convenient parameter type deduction
Definition: MemoryX.h:251
wxFrame * FindProjectFrame(AudacityProject *project)
Get a pointer to the window associated with a project, or null if the given pointer is null,...
CommandKeyHash mCommandKeyHash
bool HandleCommandEntry(AudacityProject &project, const CommandListEntry *entry, CommandFlag flags, bool alwaysEnabled, const wxEvent *evt=nullptr, const CommandContext *pGivenContext=nullptr)
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:69
CommandFlag GetUpdateFlags(bool checkActive=false) const
Definition: Menus.cpp:528
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:343

References entry, BasicUI::FindFocus(), FindProjectFrame(), MenuManager::Get(), MenuManager::GetUpdateFlags(), HandleCommandEntry(), KeyEventToKeyString(), mCommandKeyHash, NoFlagsSpecified, project, and valueRestorer().

Here is the call graph for this function:

◆ FormatLabelForMenu() [1/3]

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

810{
811 NormalizedKeyString keyStr;
812 if (auto iter = mCommandNameHash.find(id); iter != mCommandNameHash.end()) {
813 if (auto pEntry = iter->second) {
814 keyStr = pEntry->key;
815 if (!pLabel)
816 pLabel = &pEntry->label;
817 }
818 }
819 if (pLabel)
820 return FormatLabelForMenu(*pLabel, keyStr);
821 return {};
822}

References FormatLabelForMenu(), and mCommandNameHash.

Referenced by AddItemList(), FormatLabelForMenu(), and Modify().

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

◆ FormatLabelForMenu() [2/3]

wxString CommandManager::FormatLabelForMenu ( const CommandListEntry entry) const
private

Definition at line 824 of file CommandManager.cpp.

825{
826 return FormatLabelForMenu( entry->label, entry->key );
827}

References entry, and FormatLabelForMenu().

Here is the call graph for this function:

◆ FormatLabelForMenu() [3/3]

wxString CommandManager::FormatLabelForMenu ( const TranslatableString translatableLabel,
const NormalizedKeyString keyStr 
) const
private

Definition at line 829 of file CommandManager.cpp.

832{
833 auto label = translatableLabel.Translation();
834 auto key = keyStr.GET();
835 if (!key.empty())
836 {
837 // using GET to compose menu item name for wxWidgets
838 label += wxT("\t") + key;
839 }
840
841 return label;
842}
static const AudacityProject::AttachedObjects::RegisteredFactory key
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
Definition: Identifier.h:66

References Identifier::GET(), key, label, TranslatableString::Translation(), and wxT().

Here is the call graph for this function:

◆ FormatLabelWithDisabledAccel()

wxString CommandManager::FormatLabelWithDisabledAccel ( const CommandListEntry entry) const
private

Definition at line 849 of file CommandManager.cpp.

850{
851 auto label = entry->label.Translation();
852#if 1
853 wxString Accel;
854 do{
855 if (!entry->key.empty())
856 {
857 // Dummy accelerator that looks Ok in menus but is non functional.
858 // Note the space before the key.
859#ifdef __WXMSW__
860 // using GET to compose menu item name for wxWidgets
861 auto key = entry->key.GET();
862 Accel = wxString("\t ") + key;
863 if( key.StartsWith("Left" )) break;
864 if( key.StartsWith("Right")) break;
865 if( key.StartsWith("Up" )) break;
866 if( key.StartsWith("Down")) break;
867 if( key.StartsWith("Return")) break;
868 if( key.StartsWith("Tab")) break;
869 if( key.StartsWith("Shift+Tab")) break;
870 if( key.StartsWith("0")) break;
871 if( key.StartsWith("1")) break;
872 if( key.StartsWith("2")) break;
873 if( key.StartsWith("3")) break;
874 if( key.StartsWith("4")) break;
875 if( key.StartsWith("5")) break;
876 if( key.StartsWith("6")) break;
877 if( key.StartsWith("7")) break;
878 if( key.StartsWith("8")) break;
879 if( key.StartsWith("9")) break;
880 // Uncomment the below so as not to add the illegal accelerators.
881 // Accel = "";
882 //if( entry->key.StartsWith("Space" )) break;
883 // These ones appear to be illegal already and mess up accelerator processing.
884 if( key.StartsWith("NUMPAD_ENTER" )) break;
885 if( key.StartsWith("Backspace" )) break;
886 if( key.StartsWith("Delete" )) break;
887
888 // https://github.com/audacity/audacity/issues/4457
889 // This code was proposed by David Bailes to fix
890 // the decimal separator input in wxTextCtrls that
891 // are children of the main window.
892 if( key.StartsWith(",") ) break;
893 if( key.StartsWith(".") ) break;
894
895#endif
896 //wxLogDebug("Added Accel:[%s][%s]", entry->label, entry->key );
897 // Normal accelerator.
898 // using GET to compose menu item name for wxWidgets
899 Accel = wxString("\t") + entry->key.GET();
900 }
901 } while (false );
902 label += Accel;
903#endif
904 return label;
905}

References entry, key, and label.

Referenced by AddItem().

Here is the caller graph for this function:

◆ Get() [1/2]

CommandManager & CommandManager::Get ( AudacityProject project)
static

Definition at line 206 of file CommandManager.cpp.

207{
208 return project.AttachedObjects::Get< CommandManager >( key );
209}
CommandManager implements a system for organizing all user-callable commands.

References key, and project.

Referenced by SelectUtilities::ActivatePlayRegion(), MacroCommands::ApplyCommand(), ScreenshotCommand::CaptureCommands(), ScreenshotCommand::CapturePreferences(), MenuCreator::CreateMenusAndCommands(), CommonTrackPanelCell::DoContextMenu(), EffectUI::DoEffect(), GetInfoCommand::ExploreMenu(), ToolBarButtons::ForAllButtons(), Get(), SelectUtilities::InactivatePlayRegion(), AudacityApp::InitPart2(), MacroCommandsCatalog::MacroCommandsCatalog(), ToolManager::ModifyToolbarMenus(), MenuManager::ModifyUndoMenuItems(), ViewActions::Handler::OnAdvancedVZoom(), 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(), LyricsPanel::OnKeyEvent(), MixerBoardFrame::OnKeyEvent(), anonymous_namespace{BatchProcessDialog.cpp}::OnManageMacros(), ProjectWindow::OnMenu(), anonymous_namespace{FreqWindow.cpp}::OnPlotSpectrum(), anonymous_namespace{PluginMenus.cpp}::OnRepeatLastAnalyzer(), anonymous_namespace{BatchProcessDialog.cpp}::OnRepeatLastTool(), anonymous_namespace{Screenshot.cpp}::OnScreenshot(), ViewActions::Handler::OnShowClipping(), ViewActions::Handler::OnShowExtraMenus(), ViewActions::Handler::OnShowNameOverlay(), anonymous_namespace{PluginMenus.cpp}::OnSimulateRecordingErrors(), KeyConfigPrefs::Populate(), SelectHandle::Preview(), MenuCreator::RebuildMenuBar(), MenuManager::ReportIfActionNotAllowed(), ToolBar::SetButtonToolTip(), anonymous_namespace{TimelineMenus.cpp}::SetTimeDisplayMode(), MuteButtonHandle::Tip(), SoloButtonHandle::Tip(), MenuButtonHandle::Tip(), CloseButtonHandle::Tip(), and MenuManager::UpdateMenus().

Here is the caller graph for this function:

◆ Get() [2/2]

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

Definition at line 211 of file CommandManager.cpp.

212{
213 return Get( const_cast< AudacityProject & >( project ) );
214}
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 1451 of file CommandManager.cpp.

1461{
1462 for(const auto &entry : mCommandList) {
1463 // GetAllCommandData is used by KeyConfigPrefs.
1464 // It does need the effects.
1465 //if ( entry->isEffect )
1466 // continue;
1467 if ( !entry->multi || includeMultis )
1468 {
1469 names.push_back(entry->name);
1470 keys.push_back(entry->key);
1471 default_keys.push_back(entry->defaultKey);
1472 labels.push_back(entry->label);
1473 categories.push_back(entry->labelTop);
1474#if defined(EXPERIMENTAL_KEY_VIEW)
1475 prefixes.push_back(entry->labelPrefix);
1476#endif
1477 }
1478 }
1479}
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 1432 of file CommandManager.cpp.

1435{
1436 vExcludeFromMacros.clear();
1437 for(const auto &entry : mCommandList) {
1438 // This is fetching commands from the menus, for use as batch commands.
1439 // Until we have properly merged EffectManager and CommandManager
1440 // we explicitly exclude effects, as they are already handled by the
1441 // effects Manager.
1442 if ( entry->isEffect )
1443 continue;
1444 if (!entry->multi)
1445 names.push_back(entry->longLabel), vExcludeFromMacros.push_back(entry->excludeFromMacros);
1446 else if( includeMultis )
1447 names.push_back(entry->longLabel), vExcludeFromMacros.push_back(entry->excludeFromMacros);
1448 }
1449}

References entry, mCommandList, and names.

◆ GetAllCommandNames()

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

Definition at line 1419 of file CommandManager.cpp.

1421{
1422 for(const auto &entry : mCommandList) {
1423 if ( entry->isEffect )
1424 continue;
1425 if (!entry->multi)
1426 names.push_back(entry->name);
1427 else if( includeMultis )
1428 names.push_back(entry->name );// + wxT(":")/*+ mCommandList[i]->label*/);
1429 }
1430}

References entry, mCommandList, and names.

◆ GetCategories()

TranslatableStrings CommandManager::GetCategories ( AudacityProject )

Definition at line 1387 of file CommandManager.cpp.

1388{
1390
1391 for (const auto &entry : mCommandList) {
1392 auto &cat = entry->labelTop;
1393 if ( ! make_iterator_range( cats ).contains(cat) ) {
1394 cats.push_back(cat);
1395 }
1396 }
1397#if 0
1398 mCommandList.size(); i++) {
1399 if (includeMultis || !mCommandList[i]->multi)
1400 names.push_back(mCommandList[i]->name);
1401 }
1402
1403 if (p == NULL) {
1404 return;
1405 }
1406
1407 wxMenuBar *bar = p->GetMenuBar();
1408 size_t cnt = bar->GetMenuCount();
1409 for (size_t i = 0; i < cnt; i++) {
1410 cats.push_back(bar->GetMenuLabelText(i));
1411 }
1412
1413 cats.push_back(COMMAND);
1414#endif
1415
1416 return cats;
1417}
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:448
std::vector< TranslatableString > TranslatableStrings

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)

Definition at line 1512 of file CommandManager.cpp.

1513{
1515 if (!entry)
1516 return {};
1517
1518 return entry->labelTop;
1519}

References entry, mCommandNameHash, and name.

Referenced by KeyConfigPrefs::OnSet().

Here is the caller graph for this function:

◆ GetDefaultKeyFromName()

NormalizedKeyString CommandManager::GetDefaultKeyFromName ( const CommandID name)

Definition at line 1532 of file CommandManager.cpp.

1533{
1535 if (!entry)
1536 return {};
1537
1538 return entry->defaultKey;
1539}

References entry, mCommandNameHash, and name.

Referenced by KeyConfigPrefs::OnSet().

Here is the caller graph for this function:

◆ GetEnabled()

bool CommandManager::GetEnabled ( const CommandID name)

Definition at line 992 of file CommandManager.cpp.

993{
995 if (!entry || !entry->menu) {
996 // using GET in a log message for devs' eyes only
997 wxLogDebug(wxT("Warning: command doesn't exist: '%s'"),
998 name.GET());
999 return false;
1000 }
1001 return entry->enabled;
1002}

References entry, 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 1521 of file CommandManager.cpp.

1522{
1524 // May create a NULL entry
1525 const_cast<CommandManager*>(this)->mCommandNameHash[name];
1526 if (!entry)
1527 return {};
1528
1529 return entry->key;
1530}

References entry, 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)

Definition at line 1489 of file CommandManager.cpp.

1490{
1492 if (!entry)
1493 return {};
1494
1495 return entry->longLabel;
1496}

References entry, mCommandNameHash, and name.

◆ GetMenuBar()

wxMenuBar * CommandManager::GetMenuBar ( const wxString &  sMenu) const
private

Retrieves the menubar based on the name given in AddMenuBar(name)

Definition at line 368 of file CommandManager.cpp.

369{
370 for (const auto &entry : mMenuBarList)
371 {
372 if(entry.name == sMenu)
373 return entry.menubar;
374 }
375
376 return NULL;
377}

References entry, and mMenuBarList.

Referenced by AddMenuBar().

Here is the caller graph for this function:

◆ GetNameFromNumericID()

CommandID CommandManager::GetNameFromNumericID ( int  id)

Definition at line 1481 of file CommandManager.cpp.

1482{
1484 if (!entry)
1485 return {};
1486 return entry->name;
1487}

References entry, id, and mCommandNumericIDHash.

◆ GetNumberOfKeysRead()

int CommandManager::GetNumberOfKeysRead ( ) const

Definition at line 1004 of file CommandManager.cpp.

1005{
1006 return mXMLKeysRead;
1007}

References mXMLKeysRead.

Referenced by KeyConfigPrefs::OnImport().

Here is the caller graph for this function:

◆ GetPrefixedLabelFromName()

TranslatableString CommandManager::GetPrefixedLabelFromName ( const CommandID name)

Definition at line 1498 of file CommandManager.cpp.

1499{
1501 if (!entry)
1502 return {};
1503
1504 if (!entry->labelPrefix.empty())
1505 return Verbatim( wxT("%s - %s") )
1506 .Format(entry->labelPrefix, entry->label)
1507 .Stripped();
1508 else
1509 return entry->label.Stripped();
1510}
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:

◆ HandleCommandEntry()

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

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

1246{
1247 if (!entry )
1248 return false;
1249
1250 if (flags != AlwaysEnabledFlag && !entry->enabled)
1251 return false;
1252
1253 if (!alwaysEnabled && entry->flags.any()) {
1254
1255 const auto NiceName = entry->label.Stripped(
1257 // NB: The call may have the side effect of changing flags.
1258 bool allowed =
1260 NiceName, flags, entry->flags );
1261 // If the function was disallowed, it STILL should count as having been
1262 // handled (by doing nothing or by telling the user of the problem).
1263 // Otherwise we may get other handlers having a go at obeying the command.
1264 if (!allowed)
1265 return true;
1266 mNiceName = NiceName;
1267 }
1268 else {
1269 mNiceName = {};
1270 }
1271
1272 Journal::Output({ JournalCode, entry->name.GET() });
1273
1274 CommandContext context{ project, evt, entry->index, entry->parameter };
1275 if (pGivenContext)
1276 context.temporarySelection = pGivenContext->temporarySelection;
1277 // Discriminate the union entry->callback by entry->finder
1278 if (auto &finder = entry->finder) {
1279 auto &handler = finder(project);
1280 (handler.*(entry->callback.memberFn))(context);
1281 }
1282 else
1283 (entry->callback.nonMemberFn)(context);
1284 mLastProcessId = 0;
1285 return true;
1286}
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
TemporarySelection temporarySelection
TranslatableString mNiceName
bool ReportIfActionNotAllowed(const TranslatableString &Name, CommandFlag &flags, CommandFlag flagsRqd)
Definition: Menus.cpp:632
void Output(const wxString &string)

References AlwaysEnabledFlag, TranslatableString::Ellipses, entry, MenuManager::Get(), cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, anonymous_namespace{CommandManager.cpp}::JournalCode, TranslatableString::MenuCodes, mLastProcessId, mNiceName, Journal::Output(), project, MenuManager::ReportIfActionNotAllowed(), and CommandContext::temporarySelection.

Referenced by FilterKeyEvent(), HandleMenuID(), and HandleTextualCommand().

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

◆ HandleMenuID()

bool CommandManager::HandleMenuID ( AudacityProject project,
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 1333 of file CommandManager.cpp.

1335{
1338
1339 if (GlobalMenuHook::Call(entry->name))
1340 return true;
1341
1342 return HandleCommandEntry( project, entry, flags, alwaysEnabled );
1343}
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, mLastProcessId, and project.

Here is the call graph for this function:

◆ HandleTextualCommand()

CommandManager::TextualCommandResult CommandManager::HandleTextualCommand ( const CommandID Str,
const CommandContext context,
CommandFlag  flags,
bool  alwaysEnabled 
)

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

1351{
1352 if( Str.empty() )
1353 return CommandFailure;
1354 // Linear search for now...
1355 for (const auto &entry : mCommandList)
1356 {
1357 if (!entry->multi)
1358 {
1359 // Testing against labelPrefix too allows us to call Nyquist functions by name.
1360 if( Str == entry->name ||
1361 // PRL: uh oh, mixing internal string (Str) with user-visible
1362 // (labelPrefix, which was initialized from a user-visible
1363 // sub-menu name)
1364 Str == entry->labelPrefix.Translation() )
1365 {
1366 return HandleCommandEntry(
1367 context.project, entry.get(), flags, alwaysEnabled,
1368 nullptr, &context)
1370 }
1371 }
1372 else
1373 {
1374 // Handle multis too...
1375 if( Str == entry->name )
1376 {
1377 return HandleCommandEntry(
1378 context.project, entry.get(), flags, alwaysEnabled,
1379 nullptr, &context)
1381 }
1382 }
1383 }
1384 return CommandNotFound;
1385}
bool empty() const
Definition: Identifier.h:61

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

Referenced by CommandDispatch::HandleTextualCommand().

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

◆ HandleXMLChild()

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

Implements XMLTagHandler.

Definition at line 1590 of file CommandManager.cpp.

1591{
1592 return this;
1593}

◆ HandleXMLEndTag()

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

Definition at line 1577 of file CommandManager.cpp.

1578{
1579 /*
1580 if (tag == "audacitykeyboard") {
1581 AudacityMessageBox(
1582 XO("Loaded %d keyboard shortcuts\n")
1583 .Format( mXMLKeysRead ),
1584 XO("Loading Keyboard Shortcuts"),
1585 wxOK | wxCENTRE);
1586 }
1587 */
1588}

◆ HandleXMLTag()

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

Implements XMLTagHandler.

Definition at line 1541 of file CommandManager.cpp.

1542{
1543 if (tag == "audacitykeyboard") {
1544 mXMLKeysRead = 0;
1545 }
1546
1547 if (tag == "command") {
1548 wxString name;
1550
1551 for (auto pair : attrs)
1552 {
1553 auto attr = pair.first;
1554 auto value = pair.second;
1555
1556 if (value.IsStringView())
1557 {
1558 const wxString strValue = value.ToWString();
1559
1560 if (attr == "name")
1561 name = strValue;
1562 else if (attr == "key")
1563 key = NormalizedKeyString{ strValue };
1564 }
1565 }
1566
1567 if (mCommandNameHash[name]) {
1568 mCommandNameHash[name]->key = key;
1569 mXMLKeysRead++;
1570 }
1571 }
1572
1573 return true;
1574}

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

1020{
1022 if (entry && entry->menu) {
1023 entry->label = newLabel;
1024 entry->menu->SetLabel(entry->id, FormatLabelForMenu(entry));
1025 }
1026}

References entry, FormatLabelForMenu(), mCommandNameHash, and name.

Referenced by RegisterLastAnalyzer(), and RegisterLastTool().

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

◆ NewIdentifier()

CommandListEntry * CommandManager::NewIdentifier ( const CommandID nameIn,
const TranslatableString label,
wxMenu *  menu,
CommandHandlerFinder  finder,
CommandFunctorPointer  callback,
const CommandID nameSuffix,
int  index,
int  count,
const Options options 
)
private

Given all of the information for a command, comes up with a NEW unique ID, adds it to a list, and returns the ID. WARNING: Does this conflict with the identifiers set for controls/windows? If it does, a workaround may be to keep controls below wxID_LOWEST and keep menus above wxID_HIGHEST

Definition at line 655 of file CommandManager.cpp.

664{
665 bool excludeFromMacros =
666 (options.allowInMacros == 0) ||
667 ((options.allowInMacros == -1) && label.MSGID().GET().Contains("..."));
668
669 const wxString & accel = options.accel;
670 bool bIsEffect = options.bIsEffect;
671 CommandID parameter = options.parameter == "" ? nameIn : options.parameter;
672
673 // if empty, new identifier's long label will be same as label, below:
674 const auto &longLabel = options.longName;
675
676 const bool multi = !nameSuffix.empty();
677 auto name = nameIn;
678
679 // If we have the identifier already, reuse it.
681 if (!prev);
682 else if( prev->label != label );
683 else if( multi );
684 else
685 return prev;
686
687 {
688 auto entry = std::make_unique<CommandListEntry>();
689
690 TranslatableString labelPrefix;
691 if (!mSubMenuList.empty())
692 labelPrefix = mSubMenuList.back().name.Stripped();
693
694 // For key bindings for commands with a list, such as align,
695 // the name in prefs is the category name plus the effect name.
696 // This feature is not used for built-in effects.
697 if (multi)
698 name = CommandID{ { name, nameSuffix }, wxT('_') };
699
700 // wxMac 2.5 and higher will do special things with the
701 // Preferences, Exit (Quit), and About menu items,
702 // if we give them the right IDs.
703 // Otherwise we just pick increasing ID numbers for each NEW
704 // command. Note that the name string we are comparing
705 // ("About", "Preferences") is the internal command name
706 // (untranslated), not the label that actually appears in the
707 // menu (which might be translated).
708
710 entry->id = mCurrentID;
711 entry->parameter = parameter;
712
713#if defined(__WXMAC__)
714 // See bug #2642 for some history as to why these items
715 // on Mac have their IDs set explicitly and not others.
716 if (name == wxT("Preferences"))
717 entry->id = wxID_PREFERENCES;
718 else if (name == wxT("Exit"))
719 entry->id = wxID_EXIT;
720 else if (name == wxT("About"))
721 entry->id = wxID_ABOUT;
722#endif
723
724 entry->name = name;
725 entry->label = label;
726
727 // long label is the same as label unless options specified otherwise:
728 entry->longLabel = longLabel.empty() ? label : longLabel;
729
730 entry->excludeFromMacros = excludeFromMacros;
731 entry->key = NormalizedKeyString{ accel.BeforeFirst(wxT('\t')) };
732 entry->defaultKey = entry->key;
733 entry->labelPrefix = labelPrefix;
734 entry->labelTop = mCurrentMenuName.Stripped();
735 entry->menu = menu;
736 entry->finder = finder;
737 entry->callback = callback;
738 entry->isEffect = bIsEffect;
739 entry->multi = multi;
740 entry->index = index;
741 entry->count = count;
742 entry->flags = AlwaysEnabledFlag;
743 entry->enabled = true;
744 entry->skipKeydown = options.skipKeyDown;
745 entry->wantKeyup = options.wantKeyUp || entry->skipKeydown;
746 entry->allowDup = options.allowDup;
747 entry->isGlobal = false;
748 entry->isOccult = bMakingOccultCommands;
749 entry->checkmarkFn = options.checker;
750
751 // Exclude accelerators that are in the MaxList.
752 // Note that the default is unaffected, intentionally so.
753 // There are effectively two levels of default, the full (max) list
754 // and the normal reduced list.
755 if( std::binary_search( mMaxListOnly.begin(), mMaxListOnly.end(),
756 entry->key ) )
757 {
758 entry->key = {};
759 }
760 auto newKeysGroup = gPrefs->BeginGroup("/NewKeys");
761 // using GET to interpret CommandID as a config path component
762 const auto &path = entry->name.GET();
763 if (gPrefs->HasEntry(path)) {
764 // Key from preferences overrides the default key given
765 entry->key =
766 NormalizedKeyString{ gPrefs->Read(path, entry->key) };
767 }
768
769 mCommandList.push_back(std::move(entry));
770 // Don't use the variable entry eny more!
771 }
772
773 // New variable
776
777#if defined(_DEBUG)
778 prev = mCommandNameHash[entry->name];
779 if (prev) {
780 // Under Linux it looks as if we may ask for a newID for the same command
781 // more than once. So it's only an error if two different commands
782 // have the exact same name.
783 if( prev->label != entry->label )
784 {
785 wxLogDebug(wxT("Command '%s' defined by '%s' and '%s'"),
786 // using GET in a log message for devs' eyes only
787 entry->name.GET(),
788 prev->label.Debug(),
789 entry->label.Debug());
790 wxFAIL_MSG(wxString::Format(wxT("Command '%s' defined by '%s' and '%s'"),
791 // using GET in an assertion violation message for devs'
792 // eyes only
793 entry->name.GET(),
794 prev->label.Debug(),
795 entry->label.Debug()));
796 }
797 }
798#endif
800
801 if (!entry->key.empty()) {
803 }
804
805 return entry;
806}
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
std::vector< NormalizedKeyString > mMaxListOnly
Identifier MSGID() const
MSGID is the English lookup key in the catalog, not necessarily for user's eyes if locale is some oth...
wxString Debug() const
Format as an English string for debugging logs and developers' eyes, not for end users.
GroupScope BeginGroup(const wxString &prefix)
Appends a prefix to the current group or sets a new absolute path. Group that was set as current befo...
virtual bool HasEntry(const wxString &key) const =0
Checks whether specified key exists within the current group.
virtual bool Read(const wxString &key, bool *value) const =0
TranslatableString label

References CommandManager::Options::accel, CommandManager::Options::allowDup, CommandManager::Options::allowInMacros, AlwaysEnabledFlag, audacity::BasicSettings::BeginGroup(), CommandManager::Options::bIsEffect, bMakingOccultCommands, CommandManager::Options::checker, TranslatableString::Debug(), Identifier::empty(), entry, Identifier::GET(), gPrefs, audacity::BasicSettings::HasEntry(), CommandListEntry::label, label, CommandManager::Options::longName, mCommandKeyHash, mCommandList, mCommandNameHash, mCommandNumericIDHash, mCurrentID, mCurrentMenuName, mMaxListOnly, TranslatableString::MSGID(), mSubMenuList, name, NextIdentifier(), CommandManager::Options::parameter, audacity::BasicSettings::Read(), CommandManager::Options::skipKeyDown, TranslatableString::Stripped(), CommandManager::Options::wantKeyUp, and wxT().

Referenced by AddGlobalCommand(), AddItem(), and AddItemList().

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

◆ NextIdentifier()

int CommandManager::NextIdentifier ( int  ID)
private

Definition at line 639 of file CommandManager.cpp.

640{
641 ID++;
642
643 //Skip the reserved identifiers used by wxWidgets
644 if((ID >= wxID_LOWEST) && (ID <= wxID_HIGHEST))
645 ID = wxID_HIGHEST+1;
646
647 return ID;
648}

Referenced by Enable(), and NewIdentifier().

Here is the caller graph for this function:

◆ operator=()

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

◆ PopMenuBar()

void CommandManager::PopMenuBar ( )

Typically used to switch back and forth between adding to a hidden menu bar and adding to one that is visible

Definition at line 396 of file CommandManager.cpp.

397{
398 auto iter = mMenuBarList.end();
399 if ( iter != mMenuBarList.begin() )
400 mMenuBarList.erase( --iter );
401 else
402 wxASSERT( false );
403}

References mMenuBarList.

Referenced by EndOccultCommands().

Here is the caller graph for this function:

◆ PurgeData()

void CommandManager::PurgeData ( )

Definition at line 327 of file CommandManager.cpp.

328{
329 // mCommandList contains pointers to CommandListEntrys
330 // mMenuBarList contains MenuBarListEntrys.
331 // mSubMenuList contains SubMenuListEntrys
332 mCommandList.clear();
333 mMenuBarList.clear();
334 mSubMenuList.clear();
335
336 mCommandNameHash.clear();
337 mCommandKeyHash.clear();
338 mCommandNumericIDHash.clear();
339
341 mCurrentID = 17000;
342}

References COMMAND, mCommandKeyHash, mCommandList, mCommandNameHash, mCommandNumericIDHash, mCurrentID, mCurrentMenuName, mMenuBarList, and mSubMenuList.

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

Here is the caller graph for this function:

◆ RegisterLastAnalyzer()

void CommandManager::RegisterLastAnalyzer ( const CommandContext context)

Definition at line 1290 of file CommandManager.cpp.

1290 {
1291 if (mLastProcessId != 0) {
1292 auto& menuManager = MenuManager::Get(context.project);
1293 menuManager.mLastAnalyzerRegistration = MenuCreator::repeattypeunique;
1294 menuManager.mLastAnalyzerRegisteredId = mLastProcessId;
1295 auto lastEffectDesc = XO("Repeat %s").Format(mNiceName);
1296 Modify(wxT("RepeatLastAnalyzer"), lastEffectDesc);
1297 }
1298 return;
1299}
XO("Cut/Copy/Paste")
void Modify(const wxString &name, const TranslatableString &newLabel)
Changes the label text of a menu item.
@ repeattypeunique
Definition: Menus.h:62

References MenuManager::Get(), mLastProcessId, mNiceName, Modify(), CommandContext::project, MenuCreator::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 1303 of file CommandManager.cpp.

1303 {
1304 if (mLastProcessId != 0) {
1305 auto& menuManager = MenuManager::Get(context.project);
1306 menuManager.mLastToolRegistration = MenuCreator::repeattypeunique;
1307 menuManager.mLastToolRegisteredId = mLastProcessId;
1308 auto lastEffectDesc = XO("Repeat %s").Format(mNiceName);
1309 Modify(wxT("RepeatLastTool"), lastEffectDesc);
1310 }
1311 return;
1312}

References MenuManager::Get(), mLastProcessId, mNiceName, Modify(), CommandContext::project, MenuCreator::repeattypeunique, wxT(), and XO().

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

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

◆ RemoveDuplicateShortcuts()

void CommandManager::RemoveDuplicateShortcuts ( )

Definition at line 1686 of file CommandManager.cpp.

1687{
1688 TranslatableString disabledShortcuts;
1689
1690 for (auto& entry : mCommandList) {
1691 if (!entry->key.empty() && entry->key != entry->defaultKey) { // user assigned
1692 for (auto& entry2 : mCommandList) {
1693 if (!entry2->key.empty() && entry2->key == entry2->defaultKey) { // default
1694 if (entry2->key == entry->key) {
1695 auto name = wxT("/NewKeys/") + entry2->name.GET();
1697
1698 disabledShortcuts +=
1699 XO("\n* %s, because you have assigned the shortcut %s to %s")
1700 .Format(entry2->label.Strip(), entry->key.GET(), entry->label.Strip());
1701 }
1702 }
1703 }
1704 }
1705 }
1706
1707 if (!disabledShortcuts.Translation().empty()) {
1708 TranslatableString message = XO("The following commands have had their shortcuts removed,"
1709 " because their default shortcut is new or changed, and is the same shortcut"
1710 " that you have assigned to another command.")
1711 + disabledShortcuts;
1712 AudacityMessageBox(message, XO("Shortcuts have been removed"), wxOK | wxCENTRE);
1713
1714 gPrefs->Flush();
1716 }
1717}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
static void RebuildAllMenuBars()
Definition: Menus.cpp:614
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0

References AudacityMessageBox(), entry, audacity::BasicSettings::Flush(), gPrefs, mCommandList, name, MenuCreator::RebuildAllMenuBars(), TranslatableString::Translation(), audacity::BasicSettings::Write(), wxT(), and XO().

Referenced by AudacityApp::InitPart2().

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

1634{
1636 if (entry)
1637 entry->flags = flags;
1638}

References entry, mCommandNameHash, and name.

Referenced by AddItem().

Here is the caller graph for this function:

◆ SetKeyFromIndex()

void CommandManager::SetKeyFromIndex ( int  i,
const NormalizedKeyString key 
)

Definition at line 1037 of file CommandManager.cpp.

1038{
1039 const auto &entry = mCommandList[i];
1040 entry->key = key;
1041}

References entry, key, and mCommandList.

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

Here is the caller graph for this function:

◆ SetKeyFromName()

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

Definition at line 1028 of file CommandManager.cpp.

1030{
1032 if (entry) {
1033 entry->key = key;
1034 }
1035}

References entry, key, mCommandNameHash, and name.

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

Here is the caller graph for this function:

◆ SetMaxList()

void CommandManager::SetMaxList ( )

Definition at line 306 of file CommandManager.cpp.

307{
308
309 // This list is a DUPLICATE of the list in
310 // KeyConfigPrefs::OnImportDefaults(wxCommandEvent & event)
311
312 // TODO: At a later date get rid of the maxList entirely and
313 // instead use flags in the menu entries to indicate whether the default
314 // shortcut is standard or full.
315
316 mMaxListOnly.clear();
317
318 // if the full list, don't exclude any.
319 bool bFull = gPrefs->ReadBool(wxT("/GUI/Shortcuts/FullDefaults"),false);
320 if( bFull )
321 return;
322
324}
static const std::vector< NormalizedKeyString > & ExcludedList()
bool ReadBool(const wxString &key, bool defaultValue) const

References ExcludedList(), gPrefs, mMaxListOnly, audacity::BasicSettings::ReadBool(), and wxT().

Referenced by CommandManager().

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

◆ UpdateCheckmarks()

void CommandManager::UpdateCheckmarks ( AudacityProject project)

Definition at line 520 of file CommandManager.cpp.

521{
522 for ( const auto &entry : mCommandList ) {
523 if ( entry->menu && entry->checkmarkFn && !entry->isOccult) {
524 entry->menu->Check( entry->id, entry->checkmarkFn( project ) );
525 }
526 }
527}

References entry, mCommandList, and project.

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

Here is the caller graph for this function:

◆ WriteXML()

void CommandManager::WriteXML ( XMLWriter xmlFile) const

Definition at line 1595 of file CommandManager.cpp.

1597{
1598 xmlFile.StartTag(wxT("audacitykeyboard"));
1599 xmlFile.WriteAttr(wxT("audacityversion"), AUDACITY_VERSION_STRING);
1600
1601 for(const auto &entry : mCommandList) {
1602
1603 xmlFile.StartTag(wxT("command"));
1604 xmlFile.WriteAttr(wxT("name"), entry->name);
1605 xmlFile.WriteAttr(wxT("key"), entry->key);
1606 xmlFile.EndTag(wxT("command"));
1607 }
1608
1609 xmlFile.EndTag(wxT("audacitykeyboard"));
1610}
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, 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

◆ bMakingOccultCommands

bool CommandManager::bMakingOccultCommands
private

Definition at line 387 of file CommandManager.h.

Referenced by BeginOccultCommands(), EndOccultCommands(), and NewIdentifier().

◆ mbSeparatorAllowed

bool CommandManager::mbSeparatorAllowed
private

◆ mCommandKeyHash

CommandKeyHash CommandManager::mCommandKeyHash
private

Definition at line 374 of file CommandManager.h.

Referenced by FilterKeyEvent(), NewIdentifier(), and PurgeData().

◆ mCommandList

CommandList CommandManager::mCommandList
private

◆ mCommandNameHash

CommandNameHash CommandManager::mCommandNameHash
private

◆ mCommandNumericIDHash

CommandNumericIDHash CommandManager::mCommandNumericIDHash
private

◆ mCurrentID

int CommandManager::mCurrentID
private

Definition at line 376 of file CommandManager.h.

Referenced by NewIdentifier(), and PurgeData().

◆ mCurrentMenu

wxMenu* CommandManager::mCurrentMenu {}
private

Definition at line 385 of file CommandManager.h.

Referenced by BeginMainMenu(), BeginMenu(), CurrentMenu(), and EndMainMenu().

◆ mCurrentMenuName

TranslatableString CommandManager::mCurrentMenuName
private

Definition at line 381 of file CommandManager.h.

Referenced by BeginMainMenu(), EndMainMenu(), NewIdentifier(), and PurgeData().

◆ mLastProcessId

int CommandManager::mLastProcessId
private

◆ mMaxListOnly

std::vector<NormalizedKeyString> CommandManager::mMaxListOnly
private

Definition at line 368 of file CommandManager.h.

Referenced by NewIdentifier(), and SetMaxList().

◆ mMenuBarList

MenuBarList CommandManager::mMenuBarList
private

Definition at line 370 of file CommandManager.h.

Referenced by AddMenuBar(), CurrentMenuBar(), GetMenuBar(), PopMenuBar(), and PurgeData().

◆ mNiceName

TranslatableString CommandManager::mNiceName
private

Definition at line 382 of file CommandManager.h.

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

◆ mSubMenuList

SubMenuList CommandManager::mSubMenuList
private

◆ mTempMenuBar

std::unique_ptr< wxMenuBar > CommandManager::mTempMenuBar
private

Definition at line 388 of file CommandManager.h.

Referenced by BeginOccultCommands(), and EndOccultCommands().

◆ mXMLKeysRead

int CommandManager::mXMLKeysRead
private

Definition at line 377 of file CommandManager.h.

Referenced by GetNumberOfKeysRead(), and HandleXMLTag().

◆ uCurrentMenu

std::unique_ptr<wxMenu> CommandManager::uCurrentMenu
private

Definition at line 384 of file CommandManager.h.

Referenced by BeginMainMenu(), and EndMainMenu().


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