Audacity  2.2.2
Public Member Functions | Static Public Member Functions | Protected 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:
XMLTagHandler

Public Member Functions

 CommandManager ()
 
virtual ~CommandManager ()
 
 CommandManager (const CommandManager &) PROHIBITED
 
CommandManageroperator= (const CommandManager &) PROHIBITED
 
void SetMaxList ()
 
void PurgeData ()
 
std::unique_ptr< wxMenuBar > AddMenuBar (const wxString &sMenu)
 
void BeginMenu (const wxString &tName)
 
void EndMenu ()
 
wxMenu * BeginSubMenu (const wxString &tName)
 
void EndSubMenu ()
 
void AddItemList (const wxString &name, const TranslatedInternalString items[], size_t nItems, CommandHandlerFinder finder, CommandFunctorPointer callback, bool bIsEffect=false)
 
void AddCheck (const wxChar *name, const wxChar *label, bool hasDialog, CommandHandlerFinder finder, CommandFunctorPointer callback, int checkmark=0)
 
void AddCheck (const wxChar *name, const wxChar *label, bool hasDialog, CommandHandlerFinder finder, CommandFunctorPointer callback, int checkmark, CommandFlag flags, CommandMask mask)
 
void AddItem (const wxChar *name, const wxChar *label, bool hasDialog, CommandHandlerFinder finder, CommandFunctorPointer callback, CommandFlag flags=NoFlagsSpecifed, CommandMask mask=NoFlagsSpecifed, bool bIsEffect=false, const CommandParameter &parameter=CommandParameter{})
 
void AddItem (const wxChar *name, const wxChar *label_in, bool hasDialog, CommandHandlerFinder finder, CommandFunctorPointer callback, const wxChar *accel, CommandFlag flags=NoFlagsSpecifed, CommandMask mask=NoFlagsSpecifed, int checkmark=-1, bool bIsEffect=false, const CommandParameter &parameter=CommandParameter{})
 
void AddSeparator ()
 
void AddCommand (const wxChar *name, const wxChar *label, CommandHandlerFinder finder, CommandFunctorPointer callback, CommandFlag flags=NoFlagsSpecifed, CommandMask mask=NoFlagsSpecifed)
 
void AddCommand (const wxChar *name, const wxChar *label, CommandHandlerFinder finder, CommandFunctorPointer callback, const wxChar *accel, CommandFlag flags=NoFlagsSpecifed, CommandMask mask=NoFlagsSpecifed)
 
void AddGlobalCommand (const wxChar *name, const wxChar *label, bool hasDialog, CommandHandlerFinder finder, CommandFunctorPointer callback, const wxChar *accel)
 
void SetDefaultFlags (CommandFlag flags, CommandMask mask)
 
CommandFlag GetDefaultFlags () const
 
CommandMask GetDefaultMask () const
 
void SetOccultCommands (bool bOccult)
 
CommandManagerSetLongName (const wxString &name)
 
void SetCommandFlags (const wxString &name, CommandFlag flags, CommandMask mask)
 
void SetCommandFlags (const wxChar **names, CommandFlag flags, CommandMask mask)
 
void SetCommandFlags (CommandFlag flags, CommandMask mask,...)
 
void EnableUsingFlags (CommandFlag flags, CommandMask mask)
 
void Enable (const wxString &name, bool enabled)
 
void Check (const wxString &name, bool checked)
 
void Modify (const wxString &name, const wxString &newLabel)
 Changes the label text of a menu item. More...
 
void SetCurrentMenu (wxMenu *menu)
 
void ClearCurrentMenu ()
 
void SetKeyFromName (const wxString &name, const NormalizedKeyString &key)
 
void SetKeyFromIndex (int i, const NormalizedKeyString &key)
 
bool FilterKeyEvent (AudacityProject *project, const wxKeyEvent &evt, bool permit=false)
 
bool HandleMenuID (int id, CommandFlag flags, CommandMask mask)
 
bool HandleTextualCommand (const wxString &Str, const CommandContext &context, CommandFlag flags, CommandMask mask)
 
void GetCategories (wxArrayString &cats)
 
void GetAllCommandNames (wxArrayString &names, bool includeMultis) const
 
void GetAllCommandLabels (wxArrayString &labels, std::vector< bool > &vHasDialog, bool includeMultis) const
 
void GetAllCommandData (wxArrayString &names, std::vector< NormalizedKeyString > &keys, std::vector< NormalizedKeyString > &default_keys, wxArrayString &labels, wxArrayString &categories, wxArrayString &prefixes, bool includeMultis)
 
wxString GetNameFromID (int id)
 
wxString GetLabelFromName (const wxString &name)
 
wxString GetPrefixedLabelFromName (const wxString &name)
 
wxString GetCategoryFromName (const wxString &name)
 
NormalizedKeyString GetKeyFromName (const wxString &name) const
 
NormalizedKeyString GetDefaultKeyFromName (const wxString &name)
 
bool GetEnabled (const wxString &name)
 
void WriteXML (XMLWriter &xmlFile) const
 
void TellUserWhyDisallowed (const wxString &Name, CommandFlag flagsGot, CommandFlag flagsRequired)
 
wxString DescribeCommandsAndShortcuts (const TranslatedInternalString commands[], size_t nCommands) const
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual void HandleXMLEndTag (const wxChar *WXUNUSED(tag))
 
virtual void HandleXMLContent (const wxString &WXUNUSED(content))
 
bool ReadXMLTag (const char *tag, const char **attrs)
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 

Static Public Member Functions

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

Protected Member Functions

int NextIdentifier (int ID)
 
CommandListEntryNewIdentifier (const wxString &name, const wxString &label, const wxString &longLabel, bool hasDialog, wxMenu *menu, CommandHandlerFinder finder, CommandFunctorPointer callback, const wxString &nameSuffix, int index, int count, bool bIsEffect)
 
CommandListEntryNewIdentifier (const wxString &name, const wxString &label, const wxString &longLabel, bool hasDialog, const wxString &accel, wxMenu *menu, CommandHandlerFinder finder, CommandFunctorPointer callback, const wxString &nameSuffix, int index, int count, bool bIsEffect, const CommandParameter &parameter)
 
bool HandleCommandEntry (const CommandListEntry *entry, CommandFlag flags, CommandMask mask, const wxEvent *evt=NULL)
 
void Enable (CommandListEntry *entry, bool enabled)
 
wxMenuBar * CurrentMenuBar () const
 
wxMenuBar * GetMenuBar (const wxString &sMenu) const
 
wxMenu * CurrentSubMenu () const
 
wxMenu * CurrentMenu () const
 
wxString GetLabel (const CommandListEntry *entry) const
 
wxString GetLabelWithDisabledAccel (const CommandListEntry *entry) const
 
bool HandleXMLTag (const wxChar *tag, const wxChar **attrs) override
 
void HandleXMLEndTag (const wxChar *tag) override
 
XMLTagHandlerHandleXMLChild (const wxChar *tag) override
 

Private Attributes

std::vector< NormalizedKeyStringmMaxListOnly
 
MenuBarList mMenuBarList
 
SubMenuList mSubMenuList
 
CommandList mCommandList
 
CommandNameHash mCommandNameHash
 
CommandKeyHash mCommandKeyHash
 
CommandIDHash mCommandIDHash
 
int mCurrentID
 
int mXMLKeysRead
 
bool mbSeparatorAllowed
 
wxString mCurrentMenuName
 
std::unique_ptr< wxMenu > uCurrentMenu
 
wxMenu * mCurrentMenu {}
 
wxString mLongNameForItem
 
CommandFlag mDefaultFlags
 
CommandMask mDefaultMask
 
bool bMakingOccultCommands
 

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

Constructor & Destructor Documentation

CommandManager::CommandManager ( )

Standard Constructor

Definition at line 428 of file CommandManager.cpp.

References mbSeparatorAllowed, mLongNameForItem, and SetMaxList().

428  :
429  mCurrentID(17000),
433  bMakingOccultCommands( false )
434 {
435  mbSeparatorAllowed = false;
436  mLongNameForItem = "";
437  SetMaxList();
438 }
bool bMakingOccultCommands
wxString mCurrentMenuName
CommandMask mDefaultMask
CommandFlag mDefaultFlags
wxString mLongNameForItem
#define COMMAND
CommandManager::~CommandManager ( )
virtual

Class Destructor. Includes PurgeData, which removes menubars

Definition at line 443 of file CommandManager.cpp.

References PurgeData().

444 {
445  //WARNING: This removes menubars that could still be assigned to windows!
446  PurgeData();
447 }
CommandManager::CommandManager ( const CommandManager )

Member Function Documentation

void CommandManager::AddCheck ( const wxChar *  name,
const wxChar *  label,
bool  hasDialog,
CommandHandlerFinder  finder,
CommandFunctorPointer  callback,
int  checkmark = 0 
)

Definition at line 784 of file CommandManager.cpp.

References AddItem(), and NoFlagsSpecifed.

Referenced by AudacityProject::CreateMenusAndCommands().

790 {
791  AddItem(name, label, hasDialog, finder, callback, wxT(""),
792  NoFlagsSpecifed, NoFlagsSpecifed, checkmark);
793 }
wxString label
Definition: Tags.cpp:727
void AddItem(const wxChar *name, const wxChar *label, bool hasDialog, CommandHandlerFinder finder, CommandFunctorPointer callback, CommandFlag flags=NoFlagsSpecifed, CommandMask mask=NoFlagsSpecifed, bool bIsEffect=false, const CommandParameter &parameter=CommandParameter{})
const wxChar * name
Definition: Distortion.cpp:94
void CommandManager::AddCheck ( const wxChar *  name,
const wxChar *  label,
bool  hasDialog,
CommandHandlerFinder  finder,
CommandFunctorPointer  callback,
int  checkmark,
CommandFlag  flags,
CommandMask  mask 
)

Definition at line 795 of file CommandManager.cpp.

References AddItem().

803 {
804  AddItem(name, label, hasDialog, finder, callback, wxT(""), flags, mask, checkmark);
805 }
wxString label
Definition: Tags.cpp:727
void AddItem(const wxChar *name, const wxChar *label, bool hasDialog, CommandHandlerFinder finder, CommandFunctorPointer callback, CommandFlag flags=NoFlagsSpecifed, CommandMask mask=NoFlagsSpecifed, bool bIsEffect=false, const CommandParameter &parameter=CommandParameter{})
const wxChar * name
Definition: Distortion.cpp:94
void CommandManager::AddCommand ( const wxChar *  name,
const wxChar *  label,
CommandHandlerFinder  finder,
CommandFunctorPointer  callback,
CommandFlag  flags = NoFlagsSpecifed,
CommandMask  mask = NoFlagsSpecifed 
)

Add a command that doesn't appear in a menu. When the key is pressed, the given function pointer will be called (via the CommandManagerListener)

Definition at line 898 of file CommandManager.cpp.

904 {
905  AddCommand(name, label, finder, callback, wxT(""), flags, mask);
906 }
void AddCommand(const wxChar *name, const wxChar *label, CommandHandlerFinder finder, CommandFunctorPointer callback, CommandFlag flags=NoFlagsSpecifed, CommandMask mask=NoFlagsSpecifed)
wxString label
Definition: Tags.cpp:727
const wxChar * name
Definition: Distortion.cpp:94
void CommandManager::AddCommand ( const wxChar *  name,
const wxChar *  label,
CommandHandlerFinder  finder,
CommandFunctorPointer  callback,
const wxChar *  accel,
CommandFlag  flags = NoFlagsSpecifed,
CommandMask  mask = NoFlagsSpecifed 
)

Definition at line 908 of file CommandManager.cpp.

References NewIdentifier(), NoFlagsSpecifed, and SetCommandFlags().

915 {
916  NewIdentifier(name, label_in, label_in, false, accel, NULL, finder, callback, {}, 0, 0, false, {});
917 
918  if (flags != NoFlagsSpecifed || mask != NoFlagsSpecifed) {
919  SetCommandFlags(name, flags, mask);
920  }
921 }
void SetCommandFlags(const wxString &name, CommandFlag flags, CommandMask mask)
CommandListEntry * NewIdentifier(const wxString &name, const wxString &label, const wxString &longLabel, bool hasDialog, wxMenu *menu, CommandHandlerFinder finder, CommandFunctorPointer callback, const wxString &nameSuffix, int index, int count, bool bIsEffect)
const wxChar * name
Definition: Distortion.cpp:94
void CommandManager::AddGlobalCommand ( const wxChar *  name,
const wxChar *  label,
bool  hasDialog,
CommandHandlerFinder  finder,
CommandFunctorPointer  callback,
const wxChar *  accel 
)

Definition at line 923 of file CommandManager.cpp.

References AlwaysEnabledFlag, CommandListEntry::enabled, CommandListEntry::flags, CommandListEntry::isGlobal, CommandListEntry::mask, and NewIdentifier().

Referenced by AudacityProject::CreateMenusAndCommands().

929 {
930  CommandListEntry *entry =
931  NewIdentifier(name, label_in, label_in, hasDialog, accel, NULL, finder, callback,
932  {}, 0, 0, false, {});
933 
934  entry->enabled = false;
935  entry->isGlobal = true;
936  entry->flags = AlwaysEnabledFlag;
937  entry->mask = AlwaysEnabledFlag;
938 }
CommandMask mask
bool enabled
CommandListEntry is a structure used by CommandManager.
CommandListEntry * NewIdentifier(const wxString &name, const wxString &label, const wxString &longLabel, bool hasDialog, wxMenu *menu, CommandHandlerFinder finder, CommandFunctorPointer callback, const wxString &nameSuffix, int index, int count, bool bIsEffect)
bool isGlobal
const wxChar * name
Definition: Distortion.cpp:94
CommandFlag flags
void CommandManager::AddItem ( const wxChar *  name,
const wxChar *  label,
bool  hasDialog,
CommandHandlerFinder  finder,
CommandFunctorPointer  callback,
CommandFlag  flags = NoFlagsSpecifed,
CommandMask  mask = NoFlagsSpecifed,
bool  bIsEffect = false,
const CommandParameter parameter = CommandParameter{} 
)

Definition at line 807 of file CommandManager.cpp.

Referenced by AddCheck(), AudacityProject::AddEffectMenuItemGroup(), AudacityProject::CreateMenusAndCommands(), and AudacityProject::PopulateMacrosMenu().

816 {
817  AddItem(name, label, hasDialog, finder, callback, wxT(""), flags, mask, -1, bIsEffect, parameter);
818 }
wxString label
Definition: Tags.cpp:727
void AddItem(const wxChar *name, const wxChar *label, bool hasDialog, CommandHandlerFinder finder, CommandFunctorPointer callback, CommandFlag flags=NoFlagsSpecifed, CommandMask mask=NoFlagsSpecifed, bool bIsEffect=false, const CommandParameter &parameter=CommandParameter{})
const wxChar * name
Definition: Distortion.cpp:94
void CommandManager::AddItem ( const wxChar *  name,
const wxChar *  label_in,
bool  hasDialog,
CommandHandlerFinder  finder,
CommandFunctorPointer  callback,
const wxChar *  accel,
CommandFlag  flags = NoFlagsSpecifed,
CommandMask  mask = NoFlagsSpecifed,
int  checkmark = -1,
bool  bIsEffect = false,
const CommandParameter parameter = CommandParameter{} 
)

Definition at line 820 of file CommandManager.cpp.

References CurrentMenu(), GetLabelWithDisabledAccel(), CommandListEntry::id, mbSeparatorAllowed, mLongNameForItem, name, NewIdentifier(), NoFlagsSpecifed, and SetCommandFlags().

831 {
832  wxString cookedParameter;
833  if( parameter == "" )
834  cookedParameter = name;
835  else
836  cookedParameter = parameter;
837  CommandListEntry *entry =
839  label_in,
841  hasDialog,
842  accel, CurrentMenu(), finder, callback,
843  {}, 0, 0, bIsEffect, cookedParameter);
844  mLongNameForItem = "";
845  int ID = entry->id;
846  wxString label = GetLabelWithDisabledAccel(entry);
847 
848  if (flags != NoFlagsSpecifed || mask != NoFlagsSpecifed) {
849  SetCommandFlags(name, flags, mask);
850  }
851 
852 
853  if (checkmark >= 0) {
854  CurrentMenu()->AppendCheckItem(ID, label);
855  CurrentMenu()->Check(ID, checkmark != 0);
856  }
857  else {
858  CurrentMenu()->Append(ID, label);
859  }
860 
861  mbSeparatorAllowed = true;
862 }
int id
wxString GetLabelWithDisabledAccel(const CommandListEntry *entry) const
wxString label
Definition: Tags.cpp:727
void SetCommandFlags(const wxString &name, CommandFlag flags, CommandMask mask)
wxMenu * CurrentMenu() const
CommandListEntry is a structure used by CommandManager.
CommandListEntry * NewIdentifier(const wxString &name, const wxString &label, const wxString &longLabel, bool hasDialog, wxMenu *menu, CommandHandlerFinder finder, CommandFunctorPointer callback, const wxString &nameSuffix, int index, int count, bool bIsEffect)
const wxChar * name
Definition: Distortion.cpp:94
wxString mLongNameForItem
void CommandManager::AddItemList ( const wxString &  name,
const TranslatedInternalString  items[],
size_t  nItems,
CommandHandlerFinder  finder,
CommandFunctorPointer  callback,
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 870 of file CommandManager.cpp.

References CurrentMenu(), GetLabel(), CommandListEntry::id, mbSeparatorAllowed, and NewIdentifier().

Referenced by AudacityProject::CreateMenusAndCommands().

876 {
877  for (size_t i = 0, cnt = nItems; i < cnt; i++) {
879  items[i].TranslatedForMenu(),
880  items[i].TranslatedForMenu(),
881  // No means yet to specify !
882  false,
883  CurrentMenu(),
884  finder,
885  callback,
886  items[i].Internal(),
887  i,
888  cnt,
889  bIsEffect);
890  CurrentMenu()->Append(entry->id, GetLabel(entry));
891  mbSeparatorAllowed = true;
892  }
893 }
int id
wxMenu * CurrentMenu() const
CommandListEntry is a structure used by CommandManager.
wxString GetLabel(const CommandListEntry *entry) const
CommandListEntry * NewIdentifier(const wxString &name, const wxString &label, const wxString &longLabel, bool hasDialog, wxMenu *menu, CommandHandlerFinder finder, CommandFunctorPointer callback, const wxString &nameSuffix, int index, int count, bool bIsEffect)
const wxChar * name
Definition: Distortion.cpp:94
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 560 of file CommandManager.cpp.

References GetMenuBar(), and mMenuBarList.

Referenced by AudacityProject::CreateMenusAndCommands().

561 {
562  wxMenuBar *menuBar = GetMenuBar(sMenu);
563  if (menuBar) {
564  wxASSERT(false);
565  return {};
566  }
567 
568  auto result = std::make_unique<wxMenuBar>();
569  mMenuBarList.emplace_back(sMenu, result.get());
570 
571  return result;
572 }
wxMenuBar * GetMenuBar(const wxString &sMenu) const
MenuBarList mMenuBarList
void CommandManager::AddSeparator ( )

Definition at line 940 of file CommandManager.cpp.

References CurrentMenu(), and mbSeparatorAllowed.

Referenced by AudacityProject::CreateMenusAndCommands(), and AudacityProject::PopulateEffectsMenu().

941 {
942  if( mbSeparatorAllowed )
943  CurrentMenu()->AppendSeparator();
944  mbSeparatorAllowed = false; // boolean to prevent too many separators.
945 }
wxMenu * CurrentMenu() const
void CommandManager::BeginMenu ( const wxString &  tName)

This starts a NEW menu

Definition at line 605 of file CommandManager.cpp.

References mCurrentMenu, mCurrentMenuName, and uCurrentMenu.

Referenced by AudacityProject::CreateMenusAndCommands().

606 {
607  uCurrentMenu = std::make_unique<wxMenu>();
608  mCurrentMenu = uCurrentMenu.get();
609  mCurrentMenuName = tName;
610 }
std::unique_ptr< wxMenu > uCurrentMenu
wxString mCurrentMenuName
wxMenu * mCurrentMenu
wxMenu * CommandManager::BeginSubMenu ( const wxString &  tName)

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

Definition at line 631 of file CommandManager.cpp.

References mbSeparatorAllowed, and mSubMenuList.

Referenced by AudacityProject::AddEffectMenuItemGroup(), AudacityProject::AddEffectMenuItems(), Scrubber::AddMenuItems(), AudacityProject::CreateMenusAndCommands(), and AudacityProject::CreateRecentFilesMenu().

632 {
633  mSubMenuList.push_back
634  (std::make_unique< SubMenuListEntry > ( tName, std::make_unique<wxMenu>() ));
635  mbSeparatorAllowed = false;
636  return mSubMenuList.back()->menu.get();
637 }
SubMenuList mSubMenuList
void CommandManager::Check ( const wxString &  name,
bool  checked 
)

Definition at line 1285 of file CommandManager.cpp.

References CommandListEntry::id, CommandListEntry::isOccult, mCommandNameHash, CommandListEntry::menu, and name.

Referenced by Scrubber::CheckMenuItems(), AudacityProject::ModifyToolbarMenus(), AudacityProject::OnDetectUpstreamDropouts(), AudacityProject::OnFullScreen(), AudacityProject::OnShowClipping(), AudacityProject::OnShowExtraMenus(), AudacityProject::OnSimulateRecordingErrors(), and Scrubber::PopulatePopupMenu().

1286 {
1288  if (!entry || !entry->menu || entry->isOccult) {
1289  return;
1290  }
1291  entry->menu->Check(entry->id, checked);
1292 }
int id
wxMenu * menu
CommandNameHash mCommandNameHash
CommandListEntry is a structure used by CommandManager.
const wxChar * name
Definition: Distortion.cpp:94
bool isOccult
void CommandManager::ClearCurrentMenu ( )

Definition at line 699 of file CommandManager.cpp.

References mCurrentMenu, and uCurrentMenu.

700 {
701  // uCurrentMenu ought to be null in correct usage
702  wxASSERT(!uCurrentMenu);
703  // Make sure of it anyway
704  uCurrentMenu.reset();
705 
706  mCurrentMenu = nullptr;
707 }
std::unique_ptr< wxMenu > uCurrentMenu
wxMenu * mCurrentMenu
wxMenu * CommandManager::CurrentMenu ( ) const
protected

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

References CurrentSubMenu(), and mCurrentMenu.

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

675 {
676  if(!mCurrentMenu)
677  return NULL;
678 
679  wxMenu * tmpCurrentSubMenu = CurrentSubMenu();
680 
681  if(!tmpCurrentSubMenu)
682  {
683  return mCurrentMenu;
684  }
685 
686  return tmpCurrentSubMenu;
687 }
wxMenu * mCurrentMenu
wxMenu * CurrentSubMenu() const
wxMenuBar * CommandManager::CurrentMenuBar ( ) const
protected

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

Definition at line 593 of file CommandManager.cpp.

References mMenuBarList.

Referenced by EndMenu().

594 {
595  if(mMenuBarList.empty())
596  return NULL;
597 
598  return mMenuBarList.back().menubar;
599 }
MenuBarList mMenuBarList
wxMenu * CommandManager::CurrentSubMenu ( ) const
protected

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

References mSubMenuList.

Referenced by CurrentMenu().

663 {
664  if(mSubMenuList.empty())
665  return NULL;
666 
667  return mSubMenuList.back()->menu.get();
668 }
SubMenuList mSubMenuList
wxString CommandManager::DescribeCommandsAndShortcuts ( const TranslatedInternalString  commands[],
size_t  nCommands 
) const

Formatting summaries that include shortcut keys

Definition at line 1383 of file CommandManager.cpp.

References format, GetKeyFromName(), and TranslatedInternalString::Internal().

1384 {
1385  wxString mark;
1386  // This depends on the language setting and may change in-session after
1387  // change of preferences:
1388  bool rtl = (wxLayout_RightToLeft == wxTheApp->GetLayoutDirection());
1389  if (rtl)
1390  mark = wxT("\u200f");
1391 
1392  static const wxString &separatorFormat = wxT("%s / %s");
1393  wxString result;
1394  for (size_t ii = 0; ii < nCommands; ++ii) {
1395  const auto &pair = commands[ii];
1396  // If RTL, then the control character forces right-to-left sequencing of
1397  // "/" -separated command names, and puts any "(...)" shortcuts to the
1398  // left, consistently with accelerators in menus (assuming matching
1399  // operating system prefernces for language), even if the command name
1400  // was missing from the translation file and defaulted to the English.
1401  auto piece = wxString::Format(wxT("%s%s"), mark, pair.Translated());
1402 
1403  wxString name{ pair.Internal() };
1404  if (!name.empty()) {
1405  auto keyStr = GetKeyFromName(name);
1406  if (!keyStr.empty()){
1407  auto keyString = keyStr.Display(true);
1408  auto format = wxT("%s %s(%s)");
1409 #ifdef __WXMAC__
1410  // The unicode controls push and pop left-to-right embedding.
1411  // This keeps the directionally weak characters, such as uparrow
1412  // for Shift, left of the key name,
1413  // consistently with how menu accelerators appear, even when the
1414  // system language is RTL.
1415  format = wxT("%s %s(\u202a%s\u202c)");
1416 #endif
1417  // The mark makes correctly placed parentheses for RTL, even
1418  // in the case that the piece is untranslated.
1419  piece = wxString::Format(format, piece, mark, keyString);
1420  }
1421  }
1422 
1423  if (result.empty())
1424  result = piece;
1425  else
1426  result = wxString::Format(separatorFormat, result, piece);
1427  }
1428  return result;
1429 }
int format
Definition: ExportPCM.cpp:56
const wxChar * name
Definition: Distortion.cpp:94
NormalizedKeyString GetKeyFromName(const wxString &name) const
void CommandManager::Enable ( const wxString &  name,
bool  enabled 
)

Definition at line 1245 of file CommandManager.cpp.

References mCommandNameHash, CommandListEntry::menu, and name.

Referenced by EnableUsingFlags(), AudacityProject::ModifyUndoMenuItems(), and AudacityProject::UpdateMenus().

1246 {
1248  if (!entry || !entry->menu) {
1249  wxLogDebug(wxT("Warning: Unknown command enabled: '%s'"),
1250  (const wxChar*)name);
1251  return;
1252  }
1253 
1254  Enable(entry, enabled);
1255 }
wxMenu * menu
CommandNameHash mCommandNameHash
void Enable(const wxString &name, bool enabled)
CommandListEntry is a structure used by CommandManager.
const wxChar * name
Definition: Distortion.cpp:94
void CommandManager::Enable ( CommandListEntry entry,
bool  enabled 
)
protected

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

References CommandListEntry::count, CommandListEntry::enabled, CommandListEntry::id, mCommandIDHash, CommandListEntry::menu, CommandListEntry::multi, CommandListEntry::name, and NextIdentifier().

1202 {
1203  if (!entry->menu) {
1204  entry->enabled = enabled;
1205  return;
1206  }
1207 
1208  // LL: Refresh from real state as we can get out of sync on the
1209  // Mac due to its reluctance to enable menus when in a modal
1210  // state.
1211  entry->enabled = entry->menu->IsEnabled(entry->id);
1212 
1213  // Only enabled if needed
1214  if (entry->enabled != enabled) {
1215  entry->menu->Enable(entry->id, enabled);
1216  entry->enabled = entry->menu->IsEnabled(entry->id);
1217  }
1218 
1219  if (entry->multi) {
1220  int i;
1221  int ID = entry->id;
1222 
1223  for(i=1; i<entry->count; i++) {
1224  ID = NextIdentifier(ID);
1225 
1226  // This menu item is not necessarily in the same menu, because
1227  // multi-items can be spread across multiple sub menus
1228  CommandListEntry *multiEntry = mCommandIDHash[ID];
1229  if (multiEntry) {
1230  wxMenuItem *item = multiEntry->menu->FindItem(ID);
1231 
1232  if (item) {
1233  item->Enable(enabled);
1234  } else {
1235  wxLogDebug(wxT("Warning: Menu entry with id %i in %s not found"),
1236  ID, (const wxChar*)entry->name);
1237  }
1238  } else {
1239  wxLogDebug(wxT("Warning: Menu entry with id %i not in hash"), ID);
1240  }
1241  }
1242  }
1243 }
int id
int count
bool enabled
int NextIdentifier(int ID)
wxMenu * menu
CommandListEntry is a structure used by CommandManager.
bool multi
wxString name
CommandIDHash mCommandIDHash
void CommandManager::EnableUsingFlags ( CommandFlag  flags,
CommandMask  mask 
)

Definition at line 1257 of file CommandManager.cpp.

References Enable(), CommandListEntry::flags, CommandListEntry::index, CommandListEntry::isOccult, CommandListEntry::mask, mCommandList, and CommandListEntry::multi.

Referenced by AudacityProject::UpdateMenus().

1258 {
1259  for(const auto &entry : mCommandList) {
1260  if (entry->multi && entry->index != 0)
1261  continue;
1262  if( entry->isOccult )
1263  continue;
1264 
1265  auto combinedMask = (mask & entry->mask);
1266  if (combinedMask) {
1267  bool enable = ((flags & combinedMask) ==
1268  (entry->flags & combinedMask));
1269  Enable(entry.get(), enable);
1270  }
1271  }
1272 }
CommandList mCommandList
void Enable(const wxString &name, bool enabled)
void CommandManager::EndMenu ( )

This attaches a menu to the menubar and ends the menu

Definition at line 616 of file CommandManager.cpp.

References COMMAND, CurrentMenuBar(), mCurrentMenu, mCurrentMenuName, and uCurrentMenu.

Referenced by AudacityProject::CreateMenusAndCommands().

617 {
618  // Add the menu to the menubar after all menu items have been
619  // added to the menu to allow OSX to rearrange special menu
620  // items like Preferences, About, and Quit.
621  wxASSERT(uCurrentMenu);
622  CurrentMenuBar()->Append(uCurrentMenu.release(), mCurrentMenuName);
623  mCurrentMenu = nullptr;
625 }
std::unique_ptr< wxMenu > uCurrentMenu
wxString mCurrentMenuName
wxMenuBar * CurrentMenuBar() const
wxMenu * mCurrentMenu
#define COMMAND
void CommandManager::EndSubMenu ( )

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

References CurrentMenu(), mbSeparatorAllowed, and mSubMenuList.

Referenced by AudacityProject::AddEffectMenuItemGroup(), AudacityProject::AddEffectMenuItems(), AudacityProject::CreateMenusAndCommands(), and AudacityProject::CreateRecentFilesMenu().

645 {
646  //Save the submenu's information
647  SubMenuListEntry tmpSubMenu { std::move( *mSubMenuList.back() ) };
648 
649  //Pop off the NEW submenu so CurrentMenu returns the parent of the submenu
650  mSubMenuList.pop_back();
651 
652  //Add the submenu to the current menu
653  CurrentMenu()->Append
654  (0, tmpSubMenu.name, tmpSubMenu.menu.release(), tmpSubMenu.name);
655  mbSeparatorAllowed = true;
656 }
SubMenuList mSubMenuList
wxMenu * CurrentMenu() const
SubMenuListEntry is a structure used by CommandManager.
const std::vector< NormalizedKeyString > & CommandManager::ExcludedList ( )
static

Definition at line 449 of file CommandManager.cpp.

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

450 {
451  static const auto list = [] {
452  // These short cuts are for the max list only....
453  const char *const strings[] = {
454  "Ctrl+I",
455  "Ctrl+Alt+I",
456  "Ctrl+J",
457  "Ctrl+Alt+J",
458  "Ctrl+Alt+V",
459  "Alt+X",
460  "Alt+K",
461  "Shift+Alt+X",
462  "Shift+Alt+K",
463  "Alt+L",
464  "Shift+Alt+C",
465  "Alt+I",
466  "Alt+J",
467  "Shift+Alt+J",
468  "Ctrl+Shift+A",
469  "Q",
470  //"Shift+J",
471  //"Shift+K",
472  //"Shift+Home",
473  //"Shift+End",
474  "Ctrl+[",
475  "Ctrl+]",
476  "1",
477  "Shift+F5",
478  "Shift+F6",
479  "Shift+F7",
480  "Shift+F8",
481  "Ctrl+Shift+F5",
482  "Ctrl+Shift+F7",
483  "Ctrl+Shift+N",
484  "Ctrl+Shift+M",
485  "Ctrl+Home",
486  "Ctrl+End",
487  "Shift+C",
488  "Alt+Shift+Up",
489  "Alt+Shift+Down",
490  "Shift+P",
491  "Alt+Shift+Left",
492  "Alt+Shift+Right",
493  "Ctrl+Shift+T",
494  //"Command+M",
495  //"Option+Command+M",
496  "Shift+H",
497  "Shift+O",
498  "Shift+I",
499  "Shift+N",
500  "D",
501  "A",
502  "Alt+Shift+F6",
503  "Alt+F6",
504  };
505 
506  std::vector<NormalizedKeyString> result(
507  strings, strings + sizeof(strings)/sizeof(*strings) );
508  std::sort( result.begin(), result.end() );
509  return result;
510  }();
511  return list;
512 }
bool CommandManager::FilterKeyEvent ( AudacityProject project,
const wxKeyEvent &  evt,
bool  permit = false 
)

Definition at line 1434 of file CommandManager.cpp.

References CommandListEntry::enabled, GetActiveProject(), AudacityProject::GetTrackPanel(), AudacityProject::GetUpdateFlags(), HandleCommandEntry(), CommandListEntry::isGlobal, KeyEventToKeyString(), mCommandKeyHash, NoFlagsSpecifed, CommandListEntry::skipKeydown, valueRestorer(), and CommandListEntry::wantKeyup.

Referenced by CommandManagerEventMonitor::FilterEvent(), LyricsPanel::OnKeyEvent(), and MixerBoardFrame::OnKeyEvent().

1435 {
1437  if (entry == NULL)
1438  {
1439  return false;
1440  }
1441 
1442  int type = evt.GetEventType();
1443 
1444  // Global commands aren't tied to any specific project
1445  if (entry->isGlobal && type == wxEVT_KEY_DOWN)
1446  {
1447  // Global commands are always disabled so they do not interfere with the
1448  // rest of the command handling. But, to use the common handler, we
1449  // enable them temporarily and then disable them again after handling.
1450  // LL: Why do they need to be disabled???
1451  entry->enabled = false;
1452  auto cleanup = valueRestorer( entry->enabled, true );
1453  return HandleCommandEntry(entry, NoFlagsSpecifed, NoFlagsSpecifed, &evt);
1454  }
1455 
1456  wxWindow * pFocus = wxWindow::FindFocus();
1457  wxWindow * pParent = wxGetTopLevelParent( pFocus );
1458  bool validTarget = pParent == project;
1459  // Bug 1557. MixerBoard should count as 'destined for project'
1460  // MixerBoard IS a TopLevelWindow, and its parent is the project.
1461  if( pParent && pParent->GetParent() == project){
1462  if( dynamic_cast<MixerBoardFrame*>( pParent) != NULL )
1463  validTarget = true;
1464  }
1465  validTarget = validTarget && wxEventLoop::GetActive()->IsMain();
1466 
1467  // Any other keypresses must be destined for this project window
1468  if (!permit && !validTarget )
1469  {
1470  return false;
1471  }
1472 
1473  auto flags = project->GetUpdateFlags();
1474 
1475  wxKeyEvent temp = evt;
1476 
1477  // Possibly let wxWidgets do its normal key handling IF it is one of
1478  // the standard navigation keys.
1479  if((type == wxEVT_KEY_DOWN) || (type == wxEVT_KEY_UP ))
1480  {
1481  wxWindow * pWnd = wxWindow::FindFocus();
1482  wxWindow * pTrackPanel = (wxWindow*)GetActiveProject()->GetTrackPanel();
1483  bool bIntercept = pWnd != pTrackPanel;
1484  // Intercept keys from windows that are NOT the Lyrics panel
1485  if( bIntercept ){
1486  bIntercept = pWnd && ( dynamic_cast<LyricsPanel*>(pWnd) == NULL );
1487  }
1488  //wxLogDebug("Focus: %p TrackPanel: %p", pWnd, pTrackPanel );
1489  // We allow the keystrokes below to be handled by wxWidgets controls IF we are
1490  // in some sub window rather than in the TrackPanel itself.
1491  // Otherwise they will go to our command handler and if it handles them
1492  // they will NOT be available to wxWidgets.
1493  if( bIntercept ){
1494  switch( evt.GetKeyCode() ){
1495  case WXK_LEFT:
1496  case WXK_RIGHT:
1497  case WXK_UP:
1498  case WXK_DOWN:
1499  // Don't trap WXK_SPACE (Bug 1727 - SPACE not starting/stopping playback
1500  // when cursor is in a time control)
1501  // case WXK_SPACE:
1502  case WXK_TAB:
1503  case WXK_BACK:
1504  case WXK_HOME:
1505  case WXK_END:
1506  case WXK_RETURN:
1507  case WXK_NUMPAD_ENTER:
1508  case WXK_DELETE:
1509  case '0':
1510  case '1':
1511  case '2':
1512  case '3':
1513  case '4':
1514  case '5':
1515  case '6':
1516  case '7':
1517  case '8':
1518  case '9':
1519  return false;
1520  }
1521  }
1522  }
1523 
1524  if (type == wxEVT_KEY_DOWN)
1525  {
1526  if (entry->skipKeydown)
1527  {
1528  return true;
1529  }
1530  return HandleCommandEntry(entry, flags, NoFlagsSpecifed, &temp);
1531  }
1532 
1533  if (type == wxEVT_KEY_UP && entry->wantKeyup)
1534  {
1535  return HandleCommandEntry(entry, flags, NoFlagsSpecifed, &temp);
1536  }
1537 
1538  return false;
1539 }
bool enabled
NormalizedKeyString KeyEventToKeyString(const wxKeyEvent &event)
Definition: Keyboard.cpp:78
CommandKeyHash mCommandKeyHash
CommandListEntry is a structure used by CommandManager.
bool skipKeydown
bool isGlobal
bool HandleCommandEntry(const CommandListEntry *entry, CommandFlag flags, CommandMask mask, const wxEvent *evt=NULL)
bool wantKeyup
LyricsPanel is a panel that paints the bouncing ball and the lyrics text.
Definition: Lyrics.h:71
ValueRestorer< T > valueRestorer(T &var)
Definition: MemoryX.h:494
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
TrackPanel * GetTrackPanel()
Definition: Project.h:307
CommandFlag GetUpdateFlags(bool checkActive=false)
Definition: Menus.cpp:2181
void CommandManager::GetAllCommandData ( wxArrayString &  names,
std::vector< NormalizedKeyString > &  keys,
std::vector< NormalizedKeyString > &  default_keys,
wxArrayString &  labels,
wxArrayString &  categories,
wxArrayString &  prefixes,
bool  includeMultis 
)

Definition at line 1721 of file CommandManager.cpp.

References CommandListEntry::defaultKey, CommandListEntry::key, CommandListEntry::label, CommandListEntry::labelPrefix, CommandListEntry::labelTop, mCommandList, CommandListEntry::multi, and CommandListEntry::name.

Referenced by KeyConfigPrefs::RefreshBindings().

1731 {
1732  for(const auto &entry : mCommandList) {
1733  // GetAllCommandData is used by KeyConfigPrefs.
1734  // It does need the effects.
1735  //if ( entry->isEffect )
1736  // continue;
1737  if (!entry->multi)
1738  {
1739  names.Add(entry->name);
1740  keys.push_back(entry->key);
1741  default_keys.push_back(entry->defaultKey);
1742  labels.Add(entry->label);
1743  categories.Add(entry->labelTop);
1744 #if defined(EXPERIMENTAL_KEY_VIEW)
1745  prefixes.Add(entry->labelPrefix);
1746 #endif
1747  }
1748  else if( includeMultis )
1749  {
1750  names.Add(entry->name);
1751  keys.push_back(entry->key);
1752  default_keys.push_back(entry->defaultKey);
1753  labels.Add(entry->label);
1754  categories.Add(entry->labelTop);
1755 #if defined(EXPERIMENTAL_KEY_VIEW)
1756  prefixes.Add(entry->labelPrefix);
1757 #endif
1758  }
1759  }
1760 }
static wxArrayString names()
Definition: Tags.cpp:697
CommandList mCommandList
void CommandManager::GetAllCommandLabels ( wxArrayString &  labels,
std::vector< bool > &  vHasDialog,
bool  includeMultis 
) const

Definition at line 1702 of file CommandManager.cpp.

References CommandListEntry::hasDialog, CommandListEntry::isEffect, CommandListEntry::longLabel, mCommandList, and CommandListEntry::multi.

1705 {
1706  vHasDialog.clear();
1707  for(const auto &entry : mCommandList) {
1708  // This is fetching commands from the menus, for use as batch commands.
1709  // Until we have properly merged EffectManager and CommandManager
1710  // we explicitly exclude effects, as they are already handled by the
1711  // effects Manager.
1712  if ( entry->isEffect )
1713  continue;
1714  if (!entry->multi)
1715  names.Add(entry->longLabel), vHasDialog.push_back(entry->hasDialog);
1716  else if( includeMultis )
1717  names.Add(entry->longLabel), vHasDialog.push_back(entry->hasDialog);
1718  }
1719 }
static wxArrayString names()
Definition: Tags.cpp:697
CommandList mCommandList
void CommandManager::GetAllCommandNames ( wxArrayString &  names,
bool  includeMultis 
) const

Definition at line 1689 of file CommandManager.cpp.

References CommandListEntry::isEffect, mCommandList, CommandListEntry::multi, and CommandListEntry::name.

1691 {
1692  for(const auto &entry : mCommandList) {
1693  if ( entry->isEffect )
1694  continue;
1695  if (!entry->multi)
1696  names.Add(entry->name);
1697  else if( includeMultis )
1698  names.Add(entry->name );// + wxT(":")/*+ mCommandList[i]->label*/);
1699  }
1700 }
static wxArrayString names()
Definition: Tags.cpp:697
CommandList mCommandList
void CommandManager::GetCategories ( wxArrayString &  cats)

Definition at line 1658 of file CommandManager.cpp.

References COMMAND, GetActiveProject(), CommandListEntry::labelTop, and mCommandList.

1659 {
1660  cats.Clear();
1661 
1662  for (const auto &entry : mCommandList) {
1663  wxString cat = entry->labelTop;
1664  if (cats.Index(cat) == wxNOT_FOUND) {
1665  cats.Add(cat);
1666  }
1667  }
1668 #if 0
1669  mCommandList.GetCount(); i++) {
1670  if (includeMultis || !mCommandList[i]->multi)
1671  names.Add(mCommandList[i]->name);
1672  }
1673 
1675  if (p == NULL) {
1676  return;
1677  }
1678 
1679  wxMenuBar *bar = p->GetMenuBar();
1680  size_t cnt = bar->GetMenuCount();
1681  for (size_t i = 0; i < cnt; i++) {
1682  cats.Add(bar->GetMenuLabelText(i));
1683  }
1684 
1685  cats.Add(COMMAND);
1686 #endif
1687 }
static wxArrayString names()
Definition: Tags.cpp:697
CommandList mCommandList
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
const wxChar * name
Definition: Distortion.cpp:94
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
#define COMMAND
wxString CommandManager::GetCategoryFromName ( const wxString &  name)

Definition at line 1796 of file CommandManager.cpp.

References CommandListEntry::labelTop, mCommandNameHash, and name.

Referenced by KeyConfigPrefs::OnSet().

1797 {
1799  if (!entry)
1800  return wxT("");
1801 
1802  return entry->labelTop;
1803 }
CommandNameHash mCommandNameHash
CommandListEntry is a structure used by CommandManager.
const wxChar * name
Definition: Distortion.cpp:94
wxString labelTop
CommandFlag CommandManager::GetDefaultFlags ( ) const
inline

Definition at line 234 of file CommandManager.h.

234 { return mDefaultFlags; }
CommandFlag mDefaultFlags
NormalizedKeyString CommandManager::GetDefaultKeyFromName ( const wxString &  name)

Definition at line 1816 of file CommandManager.cpp.

References CommandListEntry::defaultKey, mCommandNameHash, and name.

Referenced by HandleXMLTag().

1817 {
1819  if (!entry)
1820  return {};
1821 
1822  return entry->defaultKey;
1823 }
CommandNameHash mCommandNameHash
CommandListEntry is a structure used by CommandManager.
const wxChar * name
Definition: Distortion.cpp:94
NormalizedKeyString defaultKey
CommandMask CommandManager::GetDefaultMask ( ) const
inline

Definition at line 235 of file CommandManager.h.

235 { return mDefaultMask; }
CommandMask mDefaultMask
bool CommandManager::GetEnabled ( const wxString &  name)

Definition at line 1274 of file CommandManager.cpp.

References CommandListEntry::enabled, mCommandNameHash, CommandListEntry::menu, and name.

Referenced by Scrubber::CanScrub(), and EditToolBar::ForAllButtons().

1275 {
1277  if (!entry || !entry->menu) {
1278  wxLogDebug(wxT("Warning: command doesn't exist: '%s'"),
1279  (const wxChar*)name);
1280  return false;
1281  }
1282  return entry->enabled;
1283 }
bool enabled
wxMenu * menu
CommandNameHash mCommandNameHash
CommandListEntry is a structure used by CommandManager.
const wxChar * name
Definition: Distortion.cpp:94
NormalizedKeyString CommandManager::GetKeyFromName ( const wxString &  name) const

Definition at line 1805 of file CommandManager.cpp.

References CommandListEntry::key, and mCommandNameHash.

Referenced by DescribeCommandsAndShortcuts(), and SelectHandle::Preview().

1806 {
1807  CommandListEntry *entry =
1808  // May create a NULL entry
1809  const_cast<CommandManager*>(this)->mCommandNameHash[name];
1810  if (!entry)
1811  return {};
1812 
1813  return entry->key;
1814 }
CommandNameHash mCommandNameHash
CommandListEntry is a structure used by CommandManager.
CommandManager implements a system for organizing all user-callable commands.
const wxChar * name
Definition: Distortion.cpp:94
NormalizedKeyString key
wxString CommandManager::GetLabel ( const CommandListEntry entry) const
protected

Definition at line 1133 of file CommandManager.cpp.

References CommandListEntry::key, CommandListEntry::label, label, and NormalizedKeyString::Raw().

Referenced by AddItemList(), and Modify().

1134 {
1135  wxString label = entry->label;
1136  if (!entry->key.empty())
1137  {
1138  label += wxT("\t") + entry->key.Raw();
1139  }
1140 
1141  return label;
1142 }
wxString label
wxString label
Definition: Tags.cpp:727
NormalizedKeyString key
const wxString & Raw() const
Definition: Keyboard.h:27
wxString CommandManager::GetLabelFromName ( const wxString &  name)

Definition at line 1770 of file CommandManager.cpp.

References CommandListEntry::longLabel, mCommandNameHash, and name.

1771 {
1773  if (!entry)
1774  return wxT("");
1775 
1776  return entry->longLabel;
1777 }
CommandNameHash mCommandNameHash
CommandListEntry is a structure used by CommandManager.
const wxChar * name
Definition: Distortion.cpp:94
wxString longLabel
wxString CommandManager::GetLabelWithDisabledAccel ( const CommandListEntry entry) const
protected

Definition at line 1149 of file CommandManager.cpp.

References CommandListEntry::key, CommandListEntry::label, label, and NormalizedKeyString::Raw().

Referenced by AddItem().

1150 {
1151  wxString label = entry->label;
1152 #if 1
1153  wxString Accel = "";
1154  do{
1155  if (!entry->key.empty())
1156  {
1157  // Dummy accelerator that looks Ok in menus but is non functional.
1158  // Note the space before the key.
1159 #ifdef __WXMSW__
1160  auto key = entry->key.Raw();
1161  Accel = wxString("\t ") + key;
1162  if( key.StartsWith("Left" )) break;
1163  if( key.StartsWith("Right")) break;
1164  if( key.StartsWith("Up" )) break;
1165  if( key.StartsWith("Down")) break;
1166  if( key.StartsWith("Return")) break;
1167  if( key.StartsWith("Tab")) break;
1168  if( key.StartsWith("Shift+Tab")) break;
1169  if( key.StartsWith("0")) break;
1170  if( key.StartsWith("1")) break;
1171  if( key.StartsWith("2")) break;
1172  if( key.StartsWith("3")) break;
1173  if( key.StartsWith("4")) break;
1174  if( key.StartsWith("5")) break;
1175  if( key.StartsWith("6")) break;
1176  if( key.StartsWith("7")) break;
1177  if( key.StartsWith("8")) break;
1178  if( key.StartsWith("9")) break;
1179  // Uncomment the below so as not to add the illegal accelerators.
1180  // Accel = "";
1181  //if( entry->key.StartsWith("Space" )) break;
1182  // These ones appear to be illegal already and mess up accelerator processing.
1183  if( key.StartsWith("NUMPAD_ENTER" )) break;
1184  if( key.StartsWith("Backspace" )) break;
1185  if( key.StartsWith("Delete" )) break;
1186 #endif
1187  //wxLogDebug("Added Accel:[%s][%s]", entry->label, entry->key );
1188  // Normal accelerator.
1189  Accel = wxString("\t") + entry->key.Raw();
1190  }
1191  } while (false );
1192  label += Accel;
1193 #endif
1194  return label;
1195 }
wxString label
wxString label
Definition: Tags.cpp:727
NormalizedKeyString key
const wxString & Raw() const
Definition: Keyboard.h:27
wxMenuBar * CommandManager::GetMenuBar ( const wxString &  sMenu) const
protected

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

Definition at line 578 of file CommandManager.cpp.

References mMenuBarList.

Referenced by AddMenuBar().

579 {
580  for (const auto &entry : mMenuBarList)
581  {
582  if(!entry.name.Cmp(sMenu))
583  return entry.menubar;
584  }
585 
586  return NULL;
587 }
MenuBarList mMenuBarList
wxString CommandManager::GetNameFromID ( int  id)

Definition at line 1762 of file CommandManager.cpp.

References mCommandIDHash, and CommandListEntry::name.

Referenced by GetInfoCommand::ExploreMenu().

1763 {
1764  CommandListEntry *entry = mCommandIDHash[id];
1765  if (!entry)
1766  return wxT("");
1767  return entry->name;
1768 }
CommandListEntry is a structure used by CommandManager.
wxString name
CommandIDHash mCommandIDHash
wxString CommandManager::GetPrefixedLabelFromName ( const wxString &  name)

Definition at line 1779 of file CommandManager.cpp.

References CommandListEntry::label, CommandListEntry::labelPrefix, mCommandNameHash, and name.

Referenced by KeyConfigPrefs::OnSet().

1780 {
1782  if (!entry)
1783  return wxT("");
1784 
1785 #if defined(EXPERIMENTAL_KEY_VIEW)
1786  wxString prefix;
1787  if (!entry->labelPrefix.IsEmpty()) {
1788  prefix = entry->labelPrefix + wxT(" - ");
1789  }
1790  return wxMenuItem::GetLabelText(prefix + entry->label);
1791 #else
1792  return wxString(entry->labelPrefix + wxT(" ") + entry->label).Trim(false).Trim(true);
1793 #endif
1794 }
wxString labelPrefix
wxString label
CommandNameHash mCommandNameHash
CommandListEntry is a structure used by CommandManager.
const wxChar * name
Definition: Distortion.cpp:94
bool CommandManager::HandleCommandEntry ( const CommandListEntry entry,
CommandFlag  flags,
CommandMask  mask,
const wxEvent *  evt = NULL 
)
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 1545 of file CommandManager.cpp.

References CommandListEntry::callback, CommandListEntry::enabled, CommandListEntry::finder, CommandListEntry::flags, GetActiveProject(), CommandListEntry::index, CommandListEntry::label, CommandListEntry::mask, and CommandListEntry::parameter.

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

1547 {
1548  if (!entry || !entry->enabled)
1549  return false;
1550 
1551  auto proj = GetActiveProject();
1552 
1553  auto combinedMask = (mask & entry->mask);
1554  if (combinedMask) {
1555 
1556  wxASSERT( proj );
1557  if( !proj )
1558  return false;
1559 
1560  wxString NiceName = entry->label;
1561  NiceName.Replace("&", "");// remove &
1562  NiceName.Replace(".","");// remove ...
1563  // NB: The call may have the side effect of changing flags.
1564  bool allowed = proj->ReportIfActionNotAllowed(
1565  NiceName, flags, entry->flags, combinedMask );
1566  // If the function was disallowed, it STILL should count as having been
1567  // handled (by doing nothing or by telling the user of the problem).
1568  // Otherwise we may get other handlers having a go at obeying the command.
1569  if (!allowed)
1570  return true;
1571  }
1572 
1573  const CommandContext context{ *proj, evt, entry->index, entry->parameter };
1574  auto &handler = entry->finder(*proj);
1575  (handler.*(entry->callback))(context);
1576 
1577  return true;
1578 }
CommandMask mask
wxString label
bool enabled
CommandContext provides addiitonal information to an 'Apply()' command. It provides the project...
int index
CommandParameter parameter
CommandFunctorPointer callback
CommandHandlerFinder finder
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
CommandFlag flags
bool CommandManager::HandleMenuID ( int  id,
CommandFlag  flags,
CommandMask  mask 
)

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

References GetActiveProject(), HandleCommandEntry(), mCommandIDHash, CommandListEntry::name, AudacityProject::RebuildAllMenuBars(), and PrefsDialog::ShowModal().

Referenced by AudacityProject::OnMenu().

1588 {
1589  CommandListEntry *entry = mCommandIDHash[id];
1590 
1591 #ifdef EXPERIMENTAL_EASY_CHANGE_KEY_BINDINGS
1592  if (::wxGetMouseState().ShiftDown()) {
1593  // Only want one page of the preferences
1594  KeyConfigPrefsFactory keyConfigPrefsFactory{ entry->name };
1595  PrefsDialog::Factories factories;
1596  factories.push_back(&keyConfigPrefsFactory);
1597  GlobalPrefsDialog dialog(GetActiveProject(), factories);
1598  dialog.ShowModal();
1600  return true;
1601  }
1602 #endif
1603 
1604  return HandleCommandEntry( entry, flags, mask );
1605 }
static void RebuildAllMenuBars()
Definition: Menus.cpp:4660
CommandListEntry is a structure used by CommandManager.
std::vector< PrefsNode > Factories
Definition: PrefsDialog.h:50
bool HandleCommandEntry(const CommandListEntry *entry, CommandFlag flags, CommandMask mask, const wxEvent *evt=NULL)
wxString name
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
CommandIDHash mCommandIDHash
bool CommandManager::HandleTextualCommand ( const wxString &  Str,
const CommandContext context,
CommandFlag  flags,
CommandMask  mask 
)

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

Definition at line 1610 of file CommandManager.cpp.

References AudacityProject::DoEffect(), EffectManager::Get(), PluginManager::Get(), GetActiveProject(), EffectManager::GetCommandIdentifier(), PluginManager::GetFirstPlugin(), PluginDescriptor::GetID(), PluginManager::GetNextPlugin(), HandleCommandEntry(), AudacityProject::OnEffectFlags::kConfigured, CommandListEntry::labelPrefix, mCommandList, CommandListEntry::multi, CommandListEntry::name, and PluginTypeEffect.

Referenced by MacroCommands::ApplyCommand(), ScreenshotCommand::CaptureCommands(), ScreenshotCommand::CapturePreferences(), and EditToolBar::OnButton().

1611 {
1612  if( Str.IsEmpty() )
1613  return false;
1614  // Linear search for now...
1615  for (const auto &entry : mCommandList)
1616  {
1617  if (!entry->multi)
1618  {
1619  // Testing against labelPrefix too allows us to call Nyquist functions by name.
1620  if( Str.IsSameAs( entry->name, false ) || Str.IsSameAs( entry->labelPrefix, false ))
1621  {
1622  return HandleCommandEntry( entry.get(), flags, mask);
1623  }
1624  }
1625  else
1626  {
1627  // Handle multis too...
1628  if( Str.IsSameAs( entry->name, false ) )
1629  {
1630  return HandleCommandEntry( entry.get(), flags, mask);
1631  }
1632  }
1633  }
1634  // Not one of the singleton commands.
1635  // We could/should try all the list-style commands.
1636  // instead we only try the effects.
1637  AudacityProject * proj = GetActiveProject();
1638  if( !proj )
1639  {
1640  return false;
1641  }
1642 
1646  while (plug)
1647  {
1648  if (em.GetCommandIdentifier(plug->GetID()).IsSameAs(Str, false))
1649  {
1650  return proj->DoEffect(plug->GetID(), context, AudacityProject::OnEffectFlags::kConfigured);
1651  }
1652  plug = pm.GetNextPlugin(PluginTypeEffect);
1653  }
1654 
1655  return false;
1656 }
const PluginDescriptor * GetFirstPlugin(int type)
static const int kConfigured
Definition: Project.h:493
CommandList mCommandList
bool DoEffect(const PluginID &ID, const CommandContext &context, int flags)
Definition: Menus.cpp:4519
const PluginDescriptor * GetNextPlugin(int type)
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:45
bool HandleCommandEntry(const CommandListEntry *entry, CommandFlag flags, CommandMask mask, const wxEvent *evt=NULL)
static EffectManager & Get()
PluginManager maintains a list of all plug ins. That covers modules, effects, generators, analysis-effects, commands. It also has functions for shared and private configs - which need to move out.
const wxString & GetID() const
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
wxString GetCommandIdentifier(const PluginID &ID)
static PluginManager & Get()
XMLTagHandler * CommandManager::HandleXMLChild ( const wxChar *  tag)
overrideprotectedvirtual

Implements XMLTagHandler.

Definition at line 1869 of file CommandManager.cpp.

1870 {
1871  return this;
1872 }
void CommandManager::HandleXMLEndTag ( const wxChar *  tag)
overrideprotected

Definition at line 1859 of file CommandManager.cpp.

References _(), AudacityMessageBox(), and mXMLKeysRead.

1860 {
1861  if (!wxStrcmp(tag, wxT("audacitykeyboard"))) {
1862  AudacityMessageBox(wxString::Format(_("Loaded %d keyboard shortcuts\n"),
1863  mXMLKeysRead),
1864  _("Loading Keyboard Shortcuts"),
1865  wxOK | wxCENTRE);
1866  }
1867 }
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
bool CommandManager::HandleXMLTag ( const wxChar *  tag,
const wxChar **  attrs 
)
overrideprotectedvirtual

Implements XMLTagHandler.

Definition at line 1825 of file CommandManager.cpp.

References GetDefaultKeyFromName(), XMLValueChecker::IsGoodString(), mCommandNameHash, mXMLKeysRead, and name.

1826 {
1827  if (!wxStrcmp(tag, wxT("audacitykeyboard"))) {
1828  mXMLKeysRead = 0;
1829  }
1830 
1831  if (!wxStrcmp(tag, wxT("command"))) {
1832  wxString name;
1833  NormalizedKeyString key;
1834 
1835  while(*attrs) {
1836  const wxChar *attr = *attrs++;
1837  const wxChar *value = *attrs++;
1838 
1839  if (!value)
1840  break;
1841 
1842  if (!wxStrcmp(attr, wxT("name")) && XMLValueChecker::IsGoodString(value))
1843  name = value;
1844  if (!wxStrcmp(attr, wxT("key")) && XMLValueChecker::IsGoodString(value))
1845  key = NormalizedKeyString{ value };
1846  }
1847 
1848  if (mCommandNameHash[name]) {
1849  if (GetDefaultKeyFromName(name) != key) {
1850  mCommandNameHash[name]->key = key;
1851  mXMLKeysRead++;
1852  }
1853  }
1854  }
1855 
1856  return true;
1857 }
NormalizedKeyString GetDefaultKeyFromName(const wxString &name)
CommandNameHash mCommandNameHash
static bool IsGoodString(const wxString &str)
const wxChar * name
Definition: Distortion.cpp:94
void CommandManager::Modify ( const wxString &  name,
const wxString &  newLabel 
)

Changes the label text of a menu item.

Definition at line 1295 of file CommandManager.cpp.

References GetLabel(), CommandListEntry::id, CommandListEntry::label, mCommandNameHash, CommandListEntry::menu, and name.

Referenced by AudacityProject::DoEffect(), and AudacityProject::ModifyUndoMenuItems().

1296 {
1298  if (entry && entry->menu) {
1299  entry->label = newLabel;
1300  entry->menu->SetLabel(entry->id, GetLabel(entry));
1301  }
1302 }
int id
wxString label
wxMenu * menu
CommandNameHash mCommandNameHash
CommandListEntry is a structure used by CommandManager.
wxString GetLabel(const CommandListEntry *entry) const
const wxChar * name
Definition: Distortion.cpp:94
CommandListEntry * CommandManager::NewIdentifier ( const wxString &  name,
const wxString &  label,
const wxString &  longLabel,
bool  hasDialog,
wxMenu *  menu,
CommandHandlerFinder  finder,
CommandFunctorPointer  callback,
const wxString &  nameSuffix,
int  index,
int  count,
bool  bIsEffect 
)
protected

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

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

974 {
975  return NewIdentifier(name,
976  label.BeforeFirst(wxT('\t')),
977  longLabel.BeforeFirst(wxT('\t')),
978  hasDialog,
979  label.AfterFirst(wxT('\t')),
980  menu,
981  finder,
982  callback,
983  nameSuffix,
984  index,
985  count,
986  bIsEffect,
987  {});
988 }
wxString label
Definition: Tags.cpp:727
CommandListEntry * NewIdentifier(const wxString &name, const wxString &label, const wxString &longLabel, bool hasDialog, wxMenu *menu, CommandHandlerFinder finder, CommandFunctorPointer callback, const wxString &nameSuffix, int index, int count, bool bIsEffect)
const wxChar * name
Definition: Distortion.cpp:94
CommandListEntry * CommandManager::NewIdentifier ( const wxString &  name,
const wxString &  label,
const wxString &  longLabel,
bool  hasDialog,
const wxString &  accel,
wxMenu *  menu,
CommandHandlerFinder  finder,
CommandFunctorPointer  callback,
const wxString &  nameSuffix,
int  index,
int  count,
bool  bIsEffect,
const CommandParameter parameter 
)
protected

Definition at line 990 of file CommandManager.cpp.

References bMakingOccultCommands, CommandListEntry::callback, CommandListEntry::count, CommandListEntry::defaultKey, CommandListEntry::enabled, CommandListEntry::finder, CommandListEntry::flags, gPrefs, CommandListEntry::hasDialog, CommandListEntry::id, CommandListEntry::index, CommandListEntry::isEffect, CommandListEntry::isGlobal, CommandListEntry::isOccult, CommandListEntry::key, CommandListEntry::label, label, CommandListEntry::labelPrefix, CommandListEntry::labelTop, CommandListEntry::longLabel, CommandListEntry::mask, mCommandIDHash, mCommandKeyHash, mCommandList, mCommandNameHash, mCurrentID, mCurrentMenuName, mDefaultFlags, mDefaultMask, CommandListEntry::menu, mMaxListOnly, mSubMenuList, CommandListEntry::multi, CommandListEntry::name, name, NextIdentifier(), CommandListEntry::parameter, NormalizedKeyString::Raw(), CommandListEntry::skipKeydown, and CommandListEntry::wantKeyup.

1003 {
1004  const bool multi = !nameSuffix.empty();
1005  wxString name = nameIn;
1006 
1007  // If we have the identifier already, reuse it.
1009  if (!prev);
1010  else if( prev->label != label );
1011  else if( multi );
1012  else
1013  return prev;
1014 
1015  {
1016  // Make a unique_ptr or shared_ptr as appropriate:
1017  auto entry = std::make_unique<CommandListEntry>();
1018 
1019  wxString labelPrefix;
1020  if (!mSubMenuList.empty()) {
1021  labelPrefix = mSubMenuList.back()->name;
1022  }
1023 
1024  // For key bindings for commands with a list, such as align,
1025  // the name in prefs is the category name plus the effect name.
1026  // This feature is not used for built-in effects.
1027  if (multi) {
1028  // The name needs to be clean for use by automation.
1029  wxString cleanedName = wxString::Format(wxT("%s_%s"), name, nameSuffix);
1030  cleanedName.Replace( "/", "" );
1031  cleanedName.Replace( "&", "" );
1032  cleanedName.Replace( " ", "" );
1033  name = cleanedName;
1034  }
1035 
1036  // wxMac 2.5 and higher will do special things with the
1037  // Preferences, Exit (Quit), and About menu items,
1038  // if we give them the right IDs.
1039  // Otherwise we just pick increasing ID numbers for each NEW
1040  // command. Note that the name string we are comparing
1041  // ("About", "Preferences") is the internal command name
1042  // (untranslated), not the label that actually appears in the
1043  // menu (which might be translated).
1044 
1046  entry->id = mCurrentID;
1047  entry->parameter = parameter;
1048 
1049 #if defined(__WXMAC__)
1050  if (name == wxT("Preferences"))
1051  entry->id = wxID_PREFERENCES;
1052  else if (name == wxT("Exit"))
1053  entry->id = wxID_EXIT;
1054  else if (name == wxT("About"))
1055  entry->id = wxID_ABOUT;
1056 #endif
1057 
1058  entry->name = name;
1059  entry->label = label;
1060  entry->longLabel = longLabel.IsEmpty() ? label : longLabel;
1061  entry->hasDialog = hasDialog;
1062  entry->key = NormalizedKeyString{ accel.BeforeFirst(wxT('\t')) };
1063  entry->defaultKey = entry->key;
1064  entry->labelPrefix = labelPrefix;
1065  entry->labelTop = wxMenuItem::GetLabelText(mCurrentMenuName);
1066  entry->menu = menu;
1067  entry->finder = finder;
1068  entry->callback = callback;
1069  entry->isEffect = bIsEffect;
1070  entry->multi = multi;
1071  entry->index = index;
1072  entry->count = count;
1073  entry->flags = mDefaultFlags;
1074  entry->mask = mDefaultMask;
1075  entry->enabled = true;
1076  entry->skipKeydown = (accel.Find(wxT("\tskipKeydown")) != wxNOT_FOUND);
1077  entry->wantKeyup = (accel.Find(wxT("\twantKeyup")) != wxNOT_FOUND) || entry->skipKeydown;
1078  entry->isGlobal = false;
1079  entry->isOccult = bMakingOccultCommands;
1080 
1081  // Exclude accelerators that are in the MaxList.
1082  // Note that the default is unaffected, intentionally so.
1083  // There are effectively two levels of default, the full (max) list
1084  // and the normal reduced list.
1085  if( std::binary_search( mMaxListOnly.begin(), mMaxListOnly.end(),
1086  entry->key ) )
1087  entry->key = {};
1088 
1089  // Key from preferences overrides the default key given
1090  gPrefs->SetPath(wxT("/NewKeys"));
1091  if (gPrefs->HasEntry(entry->name)) {
1092  entry->key =
1093  NormalizedKeyString{ gPrefs->Read(entry->name, entry->key.Raw()) };
1094  }
1095  gPrefs->SetPath(wxT("/"));
1096 
1097  mCommandList.push_back(std::move(entry));
1098  // Don't use the variable entry eny more!
1099  }
1100 
1101  // New variable
1102  CommandListEntry *entry = &*mCommandList.back();
1103  mCommandIDHash[entry->id] = entry;
1104 
1105 #if defined(__WXDEBUG__)
1106  prev = mCommandNameHash[entry->name];
1107  if (prev) {
1108  // Under Linux it looks as if we may ask for a newID for the same command
1109  // more than once. So it's only an error if two different commands
1110  // have the exact same name.
1111  if( prev->label != entry->label )
1112  {
1113  wxLogDebug(wxT("Command '%s' defined by '%s' and '%s'"),
1114  entry->name,
1115  prev->label.BeforeFirst(wxT('\t')),
1116  entry->label.BeforeFirst(wxT('\t')));
1117  wxFAIL_MSG(wxString::Format(wxT("Command '%s' defined by '%s' and '%s'"),
1118  entry->name,
1119  prev->label.BeforeFirst(wxT('\t')),
1120  entry->label.BeforeFirst(wxT('\t'))));
1121  }
1122  }
1123 #endif
1124  mCommandNameHash[entry->name] = entry;
1125 
1126  if (!entry->key.empty()) {
1127  mCommandKeyHash[entry->key] = entry;
1128  }
1129 
1130  return entry;
1131 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
bool bMakingOccultCommands
int id
wxString label
CommandList mCommandList
wxString label
Definition: Tags.cpp:727
SubMenuList mSubMenuList
int NextIdentifier(int ID)
CommandKeyHash mCommandKeyHash
wxString mCurrentMenuName
std::vector< NormalizedKeyString > mMaxListOnly
CommandNameHash mCommandNameHash
CommandListEntry is a structure used by CommandManager.
wxString name
CommandMask mDefaultMask
const wxChar * name
Definition: Distortion.cpp:94
CommandFlag mDefaultFlags
NormalizedKeyString key
CommandIDHash mCommandIDHash
int CommandManager::NextIdentifier ( int  ID)
protected

Definition at line 947 of file CommandManager.cpp.

Referenced by Enable(), and NewIdentifier().

948 {
949  ID++;
950 
951  //Skip the reserved identifiers used by wxWidgets
952  if((ID >= wxID_LOWEST) && (ID <= wxID_HIGHEST))
953  ID = wxID_HIGHEST+1;
954 
955  return ID;
956 }
CommandManager& CommandManager::operator= ( const CommandManager )
void CommandManager::PurgeData ( )

Definition at line 537 of file CommandManager.cpp.

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

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

538 {
539  // mCommandList contains pointers to CommandListEntrys
540  // mMenuBarList contains MenuBarListEntrys.
541  // mSubMenuList contains SubMenuListEntrys
542  mCommandList.clear();
543  mMenuBarList.clear();
544  mSubMenuList.clear();
545 
546  mCommandNameHash.clear();
547  mCommandKeyHash.clear();
548  mCommandIDHash.clear();
549 
551  mCurrentID = 17000;
552 }
CommandList mCommandList
SubMenuList mSubMenuList
CommandKeyHash mCommandKeyHash
wxString mCurrentMenuName
CommandNameHash mCommandNameHash
MenuBarList mMenuBarList
#define COMMAND
CommandIDHash mCommandIDHash
void CommandManager::SetCommandFlags ( const wxString &  name,
CommandFlag  flags,
CommandMask  mask 
)

Definition at line 1905 of file CommandManager.cpp.

References CommandListEntry::flags, CommandListEntry::mask, mCommandNameHash, and name.

Referenced by AddCommand(), AddItem(), AudacityProject::CreateMenusAndCommands(), and SetCommandFlags().

1907 {
1909  if (entry) {
1910  entry->flags = flags;
1911  entry->mask = mask;
1912  }
1913 }
CommandMask mask
CommandNameHash mCommandNameHash
CommandListEntry is a structure used by CommandManager.
const wxChar * name
Definition: Distortion.cpp:94
CommandFlag flags
void CommandManager::SetCommandFlags ( const wxChar **  names,
CommandFlag  flags,
CommandMask  mask 
)

Definition at line 1915 of file CommandManager.cpp.

References names(), and SetCommandFlags().

1917 {
1918  const wxChar **nptr = names;
1919  while(*nptr) {
1920  SetCommandFlags(wxString(*nptr), flags, mask);
1921  nptr++;
1922  }
1923 }
static wxArrayString names()
Definition: Tags.cpp:697
void SetCommandFlags(const wxString &name, CommandFlag flags, CommandMask mask)
void CommandManager::SetCommandFlags ( CommandFlag  flags,
CommandMask  mask,
  ... 
)

Definition at line 1925 of file CommandManager.cpp.

References SetCommandFlags().

1926 {
1927  va_list list;
1928  va_start(list, mask);
1929  for(;;) {
1930  const wxChar *name = va_arg(list, const wxChar *);
1931  if (!name)
1932  break;
1933  SetCommandFlags(wxString(name), flags, mask);
1934  }
1935  va_end(list);
1936 }
void SetCommandFlags(const wxString &name, CommandFlag flags, CommandMask mask)
const wxChar * name
Definition: Distortion.cpp:94
void CommandManager::SetCurrentMenu ( wxMenu *  menu)

Definition at line 689 of file CommandManager.cpp.

References mCurrentMenu, and uCurrentMenu.

690 {
691  // uCurrentMenu ought to be null in correct usage
692  wxASSERT(!uCurrentMenu);
693  // Make sure of it anyway
694  uCurrentMenu.reset();
695 
696  mCurrentMenu = menu;
697 }
std::unique_ptr< wxMenu > uCurrentMenu
wxMenu * mCurrentMenu
void CommandManager::SetDefaultFlags ( CommandFlag  flags,
CommandMask  mask 
)

Definition at line 1894 of file CommandManager.cpp.

References mDefaultFlags, and mDefaultMask.

Referenced by AudacityProject::CreateMenusAndCommands().

1895 {
1896  mDefaultFlags = flags;
1897  mDefaultMask = mask;
1898 }
CommandMask mDefaultMask
CommandFlag mDefaultFlags
void CommandManager::SetKeyFromIndex ( int  i,
const NormalizedKeyString key 
)

Definition at line 1313 of file CommandManager.cpp.

References CommandListEntry::key, and mCommandList.

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

1314 {
1315  const auto &entry = mCommandList[i];
1316  entry->key = key;
1317 }
CommandList mCommandList
void CommandManager::SetKeyFromName ( const wxString &  name,
const NormalizedKeyString key 
)

Definition at line 1304 of file CommandManager.cpp.

References CommandListEntry::key, mCommandNameHash, and name.

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

1306 {
1308  if (entry) {
1309  entry->key = key;
1310  }
1311 }
CommandNameHash mCommandNameHash
CommandListEntry is a structure used by CommandManager.
const wxChar * name
Definition: Distortion.cpp:94
NormalizedKeyString key
CommandManager* CommandManager::SetLongName ( const wxString &  name)
inline

Definition at line 238 of file CommandManager.h.

References name.

Referenced by AudacityProject::CreateMenusAndCommands().

238  {
240  return this;
241  }
const wxChar * name
Definition: Distortion.cpp:94
wxString mLongNameForItem
void CommandManager::SetMaxList ( )

Definition at line 516 of file CommandManager.cpp.

References ExcludedList(), gPrefs, and mMaxListOnly.

Referenced by CommandManager(), and AudacityProject::CreateMenusAndCommands().

517 {
518 
519  // This list is a DUPLICATE of the list in
520  // KeyConfigPrefs::OnImportDefaults(wxCommandEvent & event)
521 
522  // TODO: At a later date get rid of the maxList entirely and
523  // instead use flags in the menu entrys to indicate whether the default
524  // shortcut is standard or full.
525 
526  mMaxListOnly.clear();
527 
528  // if the full list, don't exclude any.
529  bool bFull = gPrefs->ReadBool(wxT("/GUI/Shortcuts/FullDefaults"),false);
530  if( bFull )
531  return;
532 
534 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
std::vector< NormalizedKeyString > mMaxListOnly
static const std::vector< NormalizedKeyString > & ExcludedList()
void CommandManager::SetOccultCommands ( bool  bOccult)

Definition at line 1900 of file CommandManager.cpp.

References bMakingOccultCommands.

Referenced by AudacityProject::CreateMenusAndCommands().

1901 {
1902  bMakingOccultCommands = bOccult;
1903 }
bool bMakingOccultCommands
void CommandManager::TellUserWhyDisallowed ( const wxString &  Name,
CommandFlag  flagsGot,
CommandFlag  flagsRequired 
)

Definition at line 1319 of file CommandManager.cpp.

References _(), AudioIONotBusyFlag, CutCopyAvailableFlag, ShowErrorDialog(), StereoRequiredFlag, TimeSelectedFlag, TrackPanelHasFocus, TracksExistFlag, TracksSelectedFlag, and WaveTracksSelectedFlag.

Referenced by AudacityProject::ReportIfActionNotAllowed().

1320 {
1321  // The default string for 'reason' is a catch all. I hope it won't ever be seen
1322  // and that we will get something more specific.
1323  wxString reason = _("There was a problem with your last action. If you think\nthis is a bug, please tell us exactly where it occurred.");
1324  // The default title string is 'Disallowed'.
1325  wxString title = _("Disallowed");
1326  wxString helpPage ="";
1327 
1328  auto missingFlags = flagsRequired & (~flagsGot );
1329  if( missingFlags & AudioIONotBusyFlag )
1330  // This reason will not be shown, because options that require it will be greyed our.
1331  reason = _("You can only do this when playing and recording are\nstopped. (Pausing is not sufficient.)");
1332  else if( missingFlags & StereoRequiredFlag )
1333  // This reason will not be shown, because the stereo-to-mono is greyed out if not allowed.
1334  reason = _("You must first select some stereo audio to perform this\naction. (You cannot use this with mono.)");
1335  // In reporting the issue with cut or copy, we don't tell the user they could also select some text in a label.
1336  else if(( missingFlags & TimeSelectedFlag ) || (missingFlags &CutCopyAvailableFlag )){
1337  title = _("No Audio Selected");
1338 #ifdef EXPERIMENTAL_DA
1339  // i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
1340  reason = wxString::Format( _("You must first select some audio for '%s' to act on.\n\nCtrl + A selects all audio."), Name );
1341 #else
1342 #ifdef __WXMAC__
1343  // i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
1344  reason = wxString::Format( _("Select the audio for %s to use (for example, Cmd + A to Select All) then try again."
1345  // No need to explain what a help button is for.
1346  // "\n\nClick the Help button to learn more about selection methods."
1347  ), Name );
1348 
1349 #else
1350  // i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
1351  reason = wxString::Format( _("Select the audio for %s to use (for example, Ctrl + A to Select All) then try again."
1352  // No need to explain what a help button is for.
1353  // "\n\nClick the Help button to learn more about selection methods."
1354  ), Name );
1355 #endif
1356 #endif
1357  helpPage = "Selecting_Audio_-_the_basics";
1358  }
1359  else if( missingFlags & WaveTracksSelectedFlag)
1360  reason = _("You must first select some audio to perform this action.\n(Selecting other kinds of track won't work.)");
1361  else if ( missingFlags & TracksSelectedFlag )
1362  // i18n-hint: %s will be replaced by the name of an action, such as "Remove Tracks".
1363  reason = wxString::Format(_("\"%s\" requires one or more tracks to be selected."), Name);
1364  // If the only thing wrong was no tracks, we do nothing and don't report a problem
1365  else if( missingFlags == TracksExistFlag )
1366  return;
1367  // Likewise return if it was just no tracks, and track panel did not have focus. (e.g. up-arrow to move track)
1368  else if( missingFlags == (TracksExistFlag | TrackPanelHasFocus) )
1369  return;
1370  // Likewise as above too...
1371  else if( missingFlags == TrackPanelHasFocus )
1372  return;
1373 
1374  // Does not have the warning icon...
1376  NULL,
1377  title,
1378  reason,
1379  helpPage);
1380 }
void ShowErrorDialog(wxWindow *parent, const wxString &dlogTitle, const wxString &message, const wxString &helpPage, const bool Close)
Displays an error dialog with a button that offers help.
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void CommandManager::WriteXML ( XMLWriter xmlFile) const

Definition at line 1874 of file CommandManager.cpp.

References AUDACITY_VERSION_STRING, CommandListEntry::key, CommandListEntry::label, mCommandList, CommandListEntry::name, and NormalizedKeyString::Raw().

Referenced by KeyConfigPrefs::OnExport().

1876 {
1877  xmlFile.StartTag(wxT("audacitykeyboard"));
1878  xmlFile.WriteAttr(wxT("audacityversion"), AUDACITY_VERSION_STRING);
1879 
1880  for(const auto &entry : mCommandList) {
1881  wxString label = entry->label;
1882  label = wxMenuItem::GetLabelText(label.BeforeFirst(wxT('\t')));
1883 
1884  xmlFile.StartTag(wxT("command"));
1885  xmlFile.WriteAttr(wxT("name"), entry->name);
1886  xmlFile.WriteAttr(wxT("label"), label);
1887  xmlFile.WriteAttr(wxT("key"), entry->key.Raw());
1888  xmlFile.EndTag(wxT("command"));
1889  }
1890 
1891  xmlFile.EndTag(wxT("audacitykeyboard"));
1892 }
#define AUDACITY_VERSION_STRING
Definition: Audacity.h:81
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:78
virtual void WriteAttr(const wxString &name, const wxString &value)
Definition: XMLWriter.cpp:131
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:101
CommandList mCommandList
wxString label
Definition: Tags.cpp:727

Member Data Documentation

bool CommandManager::bMakingOccultCommands
private

Definition at line 419 of file CommandManager.h.

Referenced by NewIdentifier(), and SetOccultCommands().

bool CommandManager::mbSeparatorAllowed
private
CommandIDHash CommandManager::mCommandIDHash
private

Definition at line 405 of file CommandManager.h.

Referenced by Enable(), GetNameFromID(), HandleMenuID(), NewIdentifier(), and PurgeData().

CommandKeyHash CommandManager::mCommandKeyHash
private

Definition at line 404 of file CommandManager.h.

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

CommandList CommandManager::mCommandList
private
CommandNameHash CommandManager::mCommandNameHash
private
int CommandManager::mCurrentID
private

Definition at line 406 of file CommandManager.h.

Referenced by NewIdentifier(), and PurgeData().

wxMenu* CommandManager::mCurrentMenu {}
private

Definition at line 413 of file CommandManager.h.

Referenced by BeginMenu(), ClearCurrentMenu(), CurrentMenu(), EndMenu(), and SetCurrentMenu().

wxString CommandManager::mCurrentMenuName
private

Definition at line 411 of file CommandManager.h.

Referenced by BeginMenu(), EndMenu(), NewIdentifier(), and PurgeData().

CommandFlag CommandManager::mDefaultFlags
private

Definition at line 417 of file CommandManager.h.

Referenced by NewIdentifier(), and SetDefaultFlags().

CommandMask CommandManager::mDefaultMask
private

Definition at line 418 of file CommandManager.h.

Referenced by NewIdentifier(), and SetDefaultFlags().

wxString CommandManager::mLongNameForItem
private

Definition at line 415 of file CommandManager.h.

Referenced by AddItem(), and CommandManager().

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

Definition at line 398 of file CommandManager.h.

Referenced by NewIdentifier(), and SetMaxList().

MenuBarList CommandManager::mMenuBarList
private

Definition at line 400 of file CommandManager.h.

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

SubMenuList CommandManager::mSubMenuList
private

Definition at line 401 of file CommandManager.h.

Referenced by BeginSubMenu(), CurrentSubMenu(), EndSubMenu(), NewIdentifier(), and PurgeData().

int CommandManager::mXMLKeysRead
private

Definition at line 407 of file CommandManager.h.

Referenced by HandleXMLEndTag(), and HandleXMLTag().

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

Definition at line 412 of file CommandManager.h.

Referenced by BeginMenu(), ClearCurrentMenu(), EndMenu(), and SetCurrentMenu().


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