Audacity 3.2.0
CommandManager.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 CommandManager.cpp
6
7 Brian Gunlogson
8 Dominic Mazzoni
9
10*******************************************************************//****************************************************************//****************************************************************//****************************************************************//****************************************************************//****************************************************************//****************************************************************//****************************************************************//******************************************************************/
77
78
79
80#include "CommandManager.h"
81
82#include "CommandContext.h"
84
85#include <wx/app.h>
86#include <wx/defs.h>
87#include <wx/evtloop.h>
88#include <wx/frame.h>
89#include <wx/hash.h>
90#include <wx/intl.h>
91#include <wx/log.h>
92#include <wx/menu.h>
93#include <wx/tokenzr.h>
94
95#include "../ActiveProject.h"
96#include "../Journal.h"
97#include "../JournalOutput.h"
98#include "../JournalRegistry.h"
99#include "../Menus.h"
100#include "Project.h"
101#include "ProjectWindows.h"
102#include "../widgets/AudacityMessageBox.h"
103#include "../widgets/HelpSystem.h"
104
105
106// On wxGTK, there may be many many many plugins, but the menus don't automatically
107// allow for scrolling, so we build sub-menus. If the menu gets longer than
108// MAX_MENU_LEN, we put things in submenus that have MAX_SUBMENU_LEN items in them.
109//
110#ifdef __WXGTK__
111#define MAX_MENU_LEN 20
112#define MAX_SUBMENU_LEN 15
113#else
114#define MAX_MENU_LEN 1000
115#define MAX_SUBMENU_LEN 1000
116#endif
117
118#define COMMAND XO("Command")
119
120
122{
123 MenuBarListEntry(const wxString &name_, wxMenuBar *menubar_);
125
126 wxString name;
127 wxWeakRef<wxMenuBar> menubar; // This structure does not assume memory ownership!
128};
129
131{
132 SubMenuListEntry( const TranslatableString &name_ );
135
137 std::unique_ptr<wxMenu> menu;
138};
139
141{
142 int id;
150 wxMenu *menu;
154
155 // type of a function that determines checkmark state
156 using CheckFn = std::function< bool(AudacityProject&) >;
158
159 bool multi;
160 int index;
161 int count;
171 bool useStrictFlags{ false };
172};
173
175
177
179{
180 return true;
181}
182
183MenuBarListEntry::MenuBarListEntry(const wxString &name_, wxMenuBar *menubar_)
184 : name(name_), menubar(menubar_)
185{
186}
187
189{
190}
191
193 : name(name_), menu( std::make_unique< wxMenu >() )
194{
195}
196
198{
199}
200
203 [](AudacityProject&) {
204 return std::make_unique<CommandManager>();
205 }
206};
207
209{
210 return project.AttachedObjects::Get< CommandManager >( key );
211}
212
214{
215 return Get( const_cast< AudacityProject & >( project ) );
216}
217
222 mCurrentID(17000),
223 mCurrentMenuName(COMMAND),
224 bMakingOccultCommands( false )
225{
226 mbSeparatorAllowed = false;
227 SetMaxList();
228 mLastProcessId = 0;
229}
230
235{
236 //WARNING: This removes menubars that could still be assigned to windows!
237 PurgeData();
238}
239
240const std::vector<NormalizedKeyString> &CommandManager::ExcludedList()
241{
242 static const auto list = [] {
243 // These short cuts are for the max list only....
244 const char *const strings[] = {
245 // "Ctrl+I",
246 "Ctrl+Alt+I",
247 "Ctrl+J",
248 "Ctrl+Alt+J",
249 "Ctrl+Alt+V",
250 "Alt+X",
251 "Alt+K",
252 "Shift+Alt+X",
253 "Shift+Alt+K",
254 "Alt+L",
255 "Shift+Alt+C",
256 "Alt+I",
257 "Alt+J",
258 "Shift+Alt+J",
259 "Ctrl+Shift+A",
260 //"Q",
261 //"Shift+J",
262 //"Shift+K",
263 //"Shift+Home",
264 //"Shift+End",
265 "Ctrl+[",
266 "Ctrl+]",
267 "1",
268 "Shift+F5",
269 "Shift+F6",
270 "Shift+F7",
271 "Shift+F8",
272 "Ctrl+Shift+F5",
273 "Ctrl+Shift+F7",
274 "Ctrl+Shift+N",
275 "Ctrl+Shift+M",
276 "Ctrl+Home",
277 "Ctrl+End",
278 "Shift+C",
279 "Alt+Shift+Up",
280 "Alt+Shift+Down",
281 "Shift+P",
282 "Alt+Shift+Left",
283 "Alt+Shift+Right",
284 "Ctrl+Shift+T",
285 //"Command+M",
286 //"Option+Command+M",
287 "Shift+H",
288 "Shift+O",
289 "Shift+I",
290 "Shift+N",
291 "D",
292 "A",
293 "Alt+Shift+F6",
294 "Alt+F6",
295 };
296
297 std::vector<NormalizedKeyString> result(
298 std::begin(strings), std::end(strings)
299 );
300 std::sort( result.begin(), result.end() );
301 return result;
302 }();
303 return list;
304}
305
306// CommandManager needs to know which defaults are standard and which are in the
307// full (max) list.
309{
310
311 // This list is a DUPLICATE of the list in
312 // KeyConfigPrefs::OnImportDefaults(wxCommandEvent & event)
313
314 // TODO: At a later date get rid of the maxList entirely and
315 // instead use flags in the menu entries to indicate whether the default
316 // shortcut is standard or full.
317
318 mMaxListOnly.clear();
319
320 // if the full list, don't exclude any.
321 bool bFull = gPrefs->ReadBool(wxT("/GUI/Shortcuts/FullDefaults"),false);
322 if( bFull )
323 return;
324
326}
327
328
330{
331 // mCommandList contains pointers to CommandListEntrys
332 // mMenuBarList contains MenuBarListEntrys.
333 // mSubMenuList contains SubMenuListEntrys
334 mCommandList.clear();
335 mMenuBarList.clear();
336 mSubMenuList.clear();
337
338 mCommandNameHash.clear();
339 mCommandKeyHash.clear();
340 mCommandNumericIDHash.clear();
341
343 mCurrentID = 17000;
344}
345
346
352std::unique_ptr<wxMenuBar> CommandManager::AddMenuBar(const wxString & sMenu)
353{
354 wxMenuBar *menuBar = GetMenuBar(sMenu);
355 if (menuBar) {
356 wxASSERT(false);
357 return {};
358 }
359
360 auto result = std::make_unique<wxMenuBar>();
361 mMenuBarList.emplace_back(sMenu, result.get());
362
363 return result;
364}
365
366
370wxMenuBar * CommandManager::GetMenuBar(const wxString & sMenu) const
371{
372 for (const auto &entry : mMenuBarList)
373 {
374 if(entry.name == sMenu)
375 return entry.menubar;
376 }
377
378 return NULL;
379}
380
381
386{
387 if(mMenuBarList.empty())
388 return NULL;
389
390 return mMenuBarList.back().menubar;
391}
392
399{
400 auto iter = mMenuBarList.end();
401 if ( iter != mMenuBarList.begin() )
402 mMenuBarList.erase( --iter );
403 else
404 wxASSERT( false );
405}
406
407
412{
413 if ( mCurrentMenu )
414 return BeginSubMenu( tName );
415 else
416 return BeginMainMenu( tName );
417}
418
419
422// and in all cases ends the menu
425{
426 if ( mSubMenuList.empty() )
427 EndMainMenu();
428 else
429 EndSubMenu();
430}
431
432
437{
438 uCurrentMenu = std::make_unique<wxMenu>();
440 mCurrentMenuName = tName;
441 return mCurrentMenu;
442}
443
444
449{
450 // Add the menu to the menubar after all menu items have been
451 // added to the menu to allow OSX to rearrange special menu
452 // items like Preferences, About, and Quit.
453 wxASSERT(uCurrentMenu);
454 CurrentMenuBar()->Append(
456 mCurrentMenu = nullptr;
458}
459
460
465{
466 mSubMenuList.emplace_back( tName );
467 mbSeparatorAllowed = false;
468 return mSubMenuList.back().menu.get();
469}
470
471
477{
478 //Save the submenu's information
479 SubMenuListEntry tmpSubMenu{ std::move( mSubMenuList.back() ) };
480
481 //Pop off the NEW submenu so CurrentMenu returns the parent of the submenu
482 mSubMenuList.pop_back();
483
484 //Add the submenu to the current menu
485 auto name = tmpSubMenu.name.Translation();
486 CurrentMenu()->Append(0, name, tmpSubMenu.menu.release(),
487 name /* help string */ );
488 mbSeparatorAllowed = true;
489}
490
491
496{
497 if(mSubMenuList.empty())
498 return NULL;
499
500 return mSubMenuList.back().menu.get();
501}
502
508{
509 if(!mCurrentMenu)
510 return NULL;
511
512 wxMenu * tmpCurrentSubMenu = CurrentSubMenu();
513
514 if(!tmpCurrentSubMenu)
515 {
516 return mCurrentMenu;
517 }
518
519 return tmpCurrentSubMenu;
520}
521
523{
524 for ( const auto &entry : mCommandList ) {
525 if ( entry->menu && entry->checkmarkFn && !entry->isOccult) {
526 entry->menu->Check( entry->id, entry->checkmarkFn( project ) );
527 }
528 }
529}
530
531
532
534 const CommandID &name,
535 const TranslatableString &label_in,
537 CommandFunctorPointer callback,
538 CommandFlag flags,
539 const Options &options)
540{
541 if (options.global) {
542 //wxASSERT( flags == AlwaysEnabledFlag );
544 name, label_in, finder, callback, options );
545 return;
546 }
547
548 wxASSERT( flags != NoFlagsSpecified );
549
552 label_in,
553 CurrentMenu(), finder, callback,
554 {}, 0, 0,
555 options);
556 entry->useStrictFlags = options.useStrictFlags;
557 int ID = entry->id;
559
560 SetCommandFlags(name, flags);
561
562
563 auto &checker = options.checker;
564 if (checker) {
565 CurrentMenu()->AppendCheckItem(ID, label);
566 CurrentMenu()->Check(ID, checker( project ));
567 }
568 else {
569 CurrentMenu()->Append(ID, label);
570 }
571
572 mbSeparatorAllowed = true;
573}
574
576 const wxString key, bool defaultValue ) -> CheckFn
577{
578 return [=](AudacityProject&){ return gPrefs->ReadBool( key, defaultValue ); };
579}
580
582 const BoolSetting &setting ) -> CheckFn
583{
584 return MakeCheckFn( setting.GetPath(), setting.GetDefault() );
585}
586
594 const ComponentInterfaceSymbol items[],
595 size_t nItems,
597 CommandFunctorPointer callback,
598 CommandFlag flags,
599 bool bIsEffect)
600{
601 for (size_t i = 0, cnt = nItems; i < cnt; i++) {
604 items[i].Msgid(),
605 CurrentMenu(),
606 finder,
607 callback,
608 items[i].Internal(),
609 i,
610 cnt,
611 Options{}
612 .IsEffect(bIsEffect));
613 entry->flags = flags;
614 CurrentMenu()->Append(entry->id, FormatLabelForMenu(entry));
615 mbSeparatorAllowed = true;
616 }
617}
618
620 const TranslatableString &label_in,
622 CommandFunctorPointer callback,
623 const Options &options)
624{
626 NewIdentifier(name, label_in, NULL, finder, callback,
627 {}, 0, 0, options);
628
629 entry->enabled = false;
630 entry->isGlobal = true;
631 entry->flags = AlwaysEnabledFlag;
632}
633
635{
637 CurrentMenu()->AppendSeparator();
638 mbSeparatorAllowed = false; // boolean to prevent too many separators.
639}
640
642{
643 ID++;
644
645 //Skip the reserved identifiers used by wxWidgets
646 if((ID >= wxID_LOWEST) && (ID <= wxID_HIGHEST))
647 ID = wxID_HIGHEST+1;
648
649 return ID;
650}
651
659 wxMenu *menu,
661 CommandFunctorPointer callback,
662 const CommandID &nameSuffix,
663 int index,
664 int count,
665 const Options &options)
666{
667 bool excludeFromMacros =
668 (options.allowInMacros == 0) ||
669 ((options.allowInMacros == -1) && label.MSGID().GET().Contains("..."));
670
671 const wxString & accel = options.accel;
672 bool bIsEffect = options.bIsEffect;
673 CommandID parameter = options.parameter == "" ? nameIn : options.parameter;
674
675 // if empty, new identifier's long label will be same as label, below:
676 const auto &longLabel = options.longName;
677
678 const bool multi = !nameSuffix.empty();
679 auto name = nameIn;
680
681 // If we have the identifier already, reuse it.
683 if (!prev);
684 else if( prev->label != label );
685 else if( multi );
686 else
687 return prev;
688
689 {
690 auto entry = std::make_unique<CommandListEntry>();
691
692 TranslatableString labelPrefix;
693 if (!mSubMenuList.empty())
694 labelPrefix = mSubMenuList.back().name.Stripped();
695
696 // For key bindings for commands with a list, such as align,
697 // the name in prefs is the category name plus the effect name.
698 // This feature is not used for built-in effects.
699 if (multi)
700 name = CommandID{ { name, nameSuffix }, wxT('_') };
701
702 // wxMac 2.5 and higher will do special things with the
703 // Preferences, Exit (Quit), and About menu items,
704 // if we give them the right IDs.
705 // Otherwise we just pick increasing ID numbers for each NEW
706 // command. Note that the name string we are comparing
707 // ("About", "Preferences") is the internal command name
708 // (untranslated), not the label that actually appears in the
709 // menu (which might be translated).
710
712 entry->id = mCurrentID;
713 entry->parameter = parameter;
714
715#if defined(__WXMAC__)
716 // See bug #2642 for some history as to why these items
717 // on Mac have their IDs set explicitly and not others.
718 if (name == wxT("Preferences"))
719 entry->id = wxID_PREFERENCES;
720 else if (name == wxT("Exit"))
721 entry->id = wxID_EXIT;
722 else if (name == wxT("About"))
723 entry->id = wxID_ABOUT;
724#endif
725
726 entry->name = name;
727 entry->label = label;
728
729 // long label is the same as label unless options specified otherwise:
730 entry->longLabel = longLabel.empty() ? label : longLabel;
731
732 entry->excludeFromMacros = excludeFromMacros;
733 entry->key = NormalizedKeyString{ accel.BeforeFirst(wxT('\t')) };
734 entry->defaultKey = entry->key;
735 entry->labelPrefix = labelPrefix;
736 entry->labelTop = mCurrentMenuName.Stripped();
737 entry->menu = menu;
738 entry->finder = finder;
739 entry->callback = callback;
740 entry->isEffect = bIsEffect;
741 entry->multi = multi;
742 entry->index = index;
743 entry->count = count;
744 entry->flags = AlwaysEnabledFlag;
745 entry->enabled = true;
746 entry->skipKeydown = options.skipKeyDown;
747 entry->wantKeyup = options.wantKeyUp || entry->skipKeydown;
748 entry->allowDup = options.allowDup;
749 entry->isGlobal = false;
750 entry->isOccult = bMakingOccultCommands;
751 entry->checkmarkFn = options.checker;
752
753 // Exclude accelerators that are in the MaxList.
754 // Note that the default is unaffected, intentionally so.
755 // There are effectively two levels of default, the full (max) list
756 // and the normal reduced list.
757 if( std::binary_search( mMaxListOnly.begin(), mMaxListOnly.end(),
758 entry->key ) )
759 entry->key = {};
760
761 // Key from preferences overrides the default key given
762 gPrefs->SetPath(wxT("/NewKeys"));
763 // using GET to interpret CommandID as a config path component
764 const auto &path = entry->name.GET();
765 if (gPrefs->HasEntry(path)) {
766 entry->key =
767 NormalizedKeyString{ gPrefs->ReadObject(path, entry->key) };
768 }
769 gPrefs->SetPath(wxT("/"));
770
771 mCommandList.push_back(std::move(entry));
772 // Don't use the variable entry eny more!
773 }
774
775 // New variable
778
779#if defined(_DEBUG)
780 prev = mCommandNameHash[entry->name];
781 if (prev) {
782 // Under Linux it looks as if we may ask for a newID for the same command
783 // more than once. So it's only an error if two different commands
784 // have the exact same name.
785 if( prev->label != entry->label )
786 {
787 wxLogDebug(wxT("Command '%s' defined by '%s' and '%s'"),
788 // using GET in a log message for devs' eyes only
789 entry->name.GET(),
790 prev->label.Debug(),
791 entry->label.Debug());
792 wxFAIL_MSG(wxString::Format(wxT("Command '%s' defined by '%s' and '%s'"),
793 // using GET in an assertion violation message for devs'
794 // eyes only
795 entry->name.GET(),
796 prev->label.Debug(),
797 entry->label.Debug()));
798 }
799 }
800#endif
802
803 if (!entry->key.empty()) {
805 }
806
807 return entry;
808}
809
811 const CommandID &id, const TranslatableString *pLabel) const
812{
813 NormalizedKeyString keyStr;
814 if (auto iter = mCommandNameHash.find(id); iter != mCommandNameHash.end()) {
815 if (auto pEntry = iter->second) {
816 keyStr = pEntry->key;
817 if (!pLabel)
818 pLabel = &pEntry->label;
819 }
820 }
821 if (pLabel)
822 return FormatLabelForMenu(*pLabel, keyStr);
823 return {};
824}
825
827{
828 return FormatLabelForMenu( entry->label, entry->key );
829}
830
832 const TranslatableString &translatableLabel,
833 const NormalizedKeyString &keyStr) const
834{
835 auto label = translatableLabel.Translation();
836 auto key = keyStr.GET();
837 if (!key.empty())
838 {
839 // using GET to compose menu item name for wxWidgets
840 label += wxT("\t") + key;
841 }
842
843 return label;
844}
845
846// A label that may have its accelerator disabled.
847// The problem is that as soon as we show accelerators in the menu, the menu might
848// catch them in normal wxWidgets processing, rather than passing the key presses on
849// to the controls that had the focus. We would like all the menu accelerators to be
850// disabled, in fact.
852{
853 auto label = entry->label.Translation();
854#if 1
855 wxString Accel;
856 do{
857 if (!entry->key.empty())
858 {
859 // Dummy accelerator that looks Ok in menus but is non functional.
860 // Note the space before the key.
861#ifdef __WXMSW__
862 // using GET to compose menu item name for wxWidgets
863 auto key = entry->key.GET();
864 Accel = wxString("\t ") + key;
865 if( key.StartsWith("Left" )) break;
866 if( key.StartsWith("Right")) break;
867 if( key.StartsWith("Up" )) break;
868 if( key.StartsWith("Down")) break;
869 if( key.StartsWith("Return")) break;
870 if( key.StartsWith("Tab")) break;
871 if( key.StartsWith("Shift+Tab")) break;
872 if( key.StartsWith("0")) break;
873 if( key.StartsWith("1")) break;
874 if( key.StartsWith("2")) break;
875 if( key.StartsWith("3")) break;
876 if( key.StartsWith("4")) break;
877 if( key.StartsWith("5")) break;
878 if( key.StartsWith("6")) break;
879 if( key.StartsWith("7")) break;
880 if( key.StartsWith("8")) break;
881 if( key.StartsWith("9")) break;
882 // Uncomment the below so as not to add the illegal accelerators.
883 // Accel = "";
884 //if( entry->key.StartsWith("Space" )) break;
885 // These ones appear to be illegal already and mess up accelerator processing.
886 if( key.StartsWith("NUMPAD_ENTER" )) break;
887 if( key.StartsWith("Backspace" )) break;
888 if( key.StartsWith("Delete" )) break;
889#endif
890 //wxLogDebug("Added Accel:[%s][%s]", entry->label, entry->key );
891 // Normal accelerator.
892 // using GET to compose menu item name for wxWidgets
893 Accel = wxString("\t") + entry->key.GET();
894 }
895 } while (false );
896 label += Accel;
897#endif
898 return label;
899}
906{
907 if (!entry->menu) {
908 entry->enabled = enabled;
909 return;
910 }
911
912 // LL: Refresh from real state as we can get out of sync on the
913 // Mac due to its reluctance to enable menus when in a modal
914 // state.
915 entry->enabled = entry->menu->IsEnabled(entry->id);
916
917 // Only enabled if needed
918 if (entry->enabled != enabled) {
919 entry->menu->Enable(entry->id, enabled);
920 entry->enabled = entry->menu->IsEnabled(entry->id);
921 }
922
923 if (entry->multi) {
924 int i;
925 int ID = entry->id;
926
927 for(i=1; i<entry->count; i++) {
928 ID = NextIdentifier(ID);
929
930 // This menu item is not necessarily in the same menu, because
931 // multi-items can be spread across multiple sub menus
932 CommandListEntry *multiEntry = mCommandNumericIDHash[ID];
933 if (multiEntry) {
934 wxMenuItem *item = multiEntry->menu->FindItem(ID);
935
936 if (item) {
937 item->Enable(enabled);
938 } else {
939 // using GET in a log message for devs' eyes only
940 wxLogDebug(wxT("Warning: Menu entry with id %i in %s not found"),
941 ID, entry->name.GET());
942 }
943 } else {
944 wxLogDebug(wxT("Warning: Menu entry with id %i not in hash"), ID);
945 }
946 }
947 }
948}
949
950void CommandManager::Enable(const wxString &name, bool enabled)
951{
953 if (!entry || !entry->menu) {
954 wxLogDebug(wxT("Warning: Unknown command enabled: '%s'"),
955 (const wxChar*)name);
956 return;
957 }
958
959 Enable(entry, enabled);
960}
961
963 CommandFlag flags, CommandFlag strictFlags)
964{
965 // strictFlags are a subset of flags. strictFlags represent the real
966 // conditions now, but flags are the conditions that could be made true.
967 // Some commands use strict flags only, refusing the chance to fix
968 // conditions
969 wxASSERT( (strictFlags & ~flags).none() );
970
971 for(const auto &entry : mCommandList) {
972 if (entry->multi && entry->index != 0)
973 continue;
974 if( entry->isOccult )
975 continue;
976
977 auto useFlags = entry->useStrictFlags ? strictFlags : flags;
978
979 if (entry->flags.any()) {
980 bool enable = ((useFlags & entry->flags) == entry->flags);
981 Enable(entry.get(), enable);
982 }
983 }
984}
985
987{
989 if (!entry || !entry->menu) {
990 // using GET in a log message for devs' eyes only
991 wxLogDebug(wxT("Warning: command doesn't exist: '%s'"),
992 name.GET());
993 return false;
994 }
995 return entry->enabled;
996}
997
999{
1000 return mXMLKeysRead;
1001}
1002
1003void CommandManager::Check(const CommandID &name, bool checked)
1004{
1006 if (!entry || !entry->menu || entry->isOccult) {
1007 return;
1008 }
1009 entry->menu->Check(entry->id, checked);
1010}
1011
1013void CommandManager::Modify(const wxString &name, const TranslatableString &newLabel)
1014{
1016 if (entry && entry->menu) {
1017 entry->label = newLabel;
1018 entry->menu->SetLabel(entry->id, FormatLabelForMenu(entry));
1019 }
1020}
1021
1023 const NormalizedKeyString &key)
1024{
1026 if (entry) {
1027 entry->key = key;
1028 }
1029}
1030
1032{
1033 const auto &entry = mCommandList[i];
1034 entry->key = key;
1035}
1036
1038 const ComponentInterfaceSymbol commands[], size_t nCommands) const
1039{
1040 wxString mark;
1041 // This depends on the language setting and may change in-session after
1042 // change of preferences:
1043 bool rtl = (wxLayout_RightToLeft == wxTheApp->GetLayoutDirection());
1044 if (rtl)
1045 mark = wxT("\u200f");
1046
1047 static const wxString &separatorFormat = wxT("%s / %s");
1048 TranslatableString result;
1049 for (size_t ii = 0; ii < nCommands; ++ii) {
1050 const auto &pair = commands[ii];
1051 // If RTL, then the control character forces right-to-left sequencing of
1052 // "/" -separated command names, and puts any "(...)" shortcuts to the
1053 // left, consistently with accelerators in menus (assuming matching
1054 // operating system preferences for language), even if the command name
1055 // was missing from the translation file and defaulted to the English.
1056
1057 // Note: not putting this and other short format strings in the
1058 // translation catalogs
1059 auto piece = Verbatim( wxT("%s%s") )
1060 .Format( mark, pair.Msgid().Stripped() );
1061
1062 auto name = pair.Internal();
1063 if (!name.empty()) {
1064 auto keyStr = GetKeyFromName(name);
1065 if (!keyStr.empty()){
1066 auto keyString = keyStr.Display(true);
1067 auto format = wxT("%s %s(%s)");
1068#ifdef __WXMAC__
1069 // The unicode controls push and pop left-to-right embedding.
1070 // This keeps the directionally weak characters, such as uparrow
1071 // for Shift, left of the key name,
1072 // consistently with how menu accelerators appear, even when the
1073 // system language is RTL.
1074 format = wxT("%s %s(\u202a%s\u202c)");
1075#endif
1076 // The mark makes correctly placed parentheses for RTL, even
1077 // in the case that the piece is untranslated.
1078 piece = Verbatim( format ).Format( piece, mark, keyString );
1079 }
1080 }
1081
1082 if (result.empty())
1083 result = piece;
1084 else
1085 result = Verbatim( separatorFormat ).Format( result, piece );
1086 }
1087 return result;
1088}
1089
1093bool CommandManager::FilterKeyEvent(AudacityProject *project, const wxKeyEvent & evt, bool permit)
1094{
1095 if (!project)
1096 return false;
1097
1098 auto pWindow = FindProjectFrame( project );
1100 if (entry == NULL)
1101 {
1102 return false;
1103 }
1104
1105 int type = evt.GetEventType();
1106
1107 // Global commands aren't tied to any specific project
1108 if (entry->isGlobal && type == wxEVT_KEY_DOWN)
1109 {
1110 // Global commands are always disabled so they do not interfere with the
1111 // rest of the command handling. But, to use the common handler, we
1112 // enable them temporarily and then disable them again after handling.
1113 // LL: Why do they need to be disabled???
1114 entry->enabled = false;
1115 auto cleanup = valueRestorer( entry->enabled, true );
1116 return HandleCommandEntry(*project, entry, NoFlagsSpecified, false, &evt);
1117 }
1118
1119 wxWindow * pFocus = wxWindow::FindFocus();
1120 wxWindow * pParent = wxGetTopLevelParent( pFocus );
1121 bool validTarget = pParent == pWindow;
1122 // Bug 1557. MixerBoard should count as 'destined for project'
1123 // MixerBoard IS a TopLevelWindow, and its parent is the project.
1124 if( pParent && pParent->GetParent() == pWindow ){
1125 if(auto keystrokeHandlingWindow = dynamic_cast< TopLevelKeystrokeHandlingWindow* >( pParent ))
1126 validTarget = keystrokeHandlingWindow->HandleCommandKeystrokes();
1127 }
1128 validTarget = validTarget && wxEventLoop::GetActive()->IsMain();
1129
1130 // Any other keypresses must be destined for this project window
1131 if (!permit && !validTarget )
1132 {
1133 return false;
1134 }
1135
1136 auto flags = MenuManager::Get(*project).GetUpdateFlags();
1137
1138 wxKeyEvent temp = evt;
1139
1140 // Possibly let wxWidgets do its normal key handling IF it is one of
1141 // the standard navigation keys.
1142 if((type == wxEVT_KEY_DOWN) || (type == wxEVT_KEY_UP ))
1143 {
1144 wxWindow * pWnd = wxWindow::FindFocus();
1145 bool bIntercept =
1146 pWnd && !dynamic_cast< NonKeystrokeInterceptingWindow * >( pWnd );
1147
1148 //wxLogDebug("Focus: %p TrackPanel: %p", pWnd, pTrackPanel );
1149 // We allow the keystrokes below to be handled by wxWidgets controls IF we are
1150 // in some sub window rather than in the TrackPanel itself.
1151 // Otherwise they will go to our command handler and if it handles them
1152 // they will NOT be available to wxWidgets.
1153 if( bIntercept ){
1154 switch( evt.GetKeyCode() ){
1155 case WXK_LEFT:
1156 case WXK_RIGHT:
1157 case WXK_UP:
1158 case WXK_DOWN:
1159 // Don't trap WXK_SPACE (Bug 1727 - SPACE not starting/stopping playback
1160 // when cursor is in a time control)
1161 // case WXK_SPACE:
1162 case WXK_TAB:
1163 case WXK_BACK:
1164 case WXK_HOME:
1165 case WXK_END:
1166 case WXK_RETURN:
1167 case WXK_NUMPAD_ENTER:
1168 case WXK_DELETE:
1169 case '0':
1170 case '1':
1171 case '2':
1172 case '3':
1173 case '4':
1174 case '5':
1175 case '6':
1176 case '7':
1177 case '8':
1178 case '9':
1179 return false;
1180 }
1181 }
1182 }
1183
1184 if (type == wxEVT_KEY_DOWN)
1185 {
1186 if (entry->skipKeydown)
1187 {
1188 return true;
1189 }
1190 return HandleCommandEntry(*project, entry, flags, false, &temp);
1191 }
1192
1193 if (type == wxEVT_KEY_UP && entry->wantKeyup)
1194 {
1195 return HandleCommandEntry(*project, entry, flags, false, &temp);
1196 }
1197
1198 return false;
1199}
1200
1201namespace {
1202
1203constexpr auto JournalCode = wxT("CM"); // for CommandManager
1204
1205// Register a callback for the journal
1207[]( const wxArrayStringEx &fields )
1208{
1209 // Expect JournalCode and the command name.
1210 // To do, perhaps, is to include some parameters.
1211 bool handled = false;
1212 if ( fields.size() == 2 ) {
1213 if (auto project = GetActiveProject().lock()) {
1214 auto pManager = &CommandManager::Get( *project );
1215 auto flags = MenuManager::Get( *project ).GetUpdateFlags();
1216 const CommandContext context( *project );
1217 auto &command = fields[1];
1218 handled =
1219 pManager->HandleTextualCommand( command, context, flags, false );
1220 }
1221 }
1222 return handled;
1223}
1224};
1225
1226}
1227
1233 const CommandListEntry * entry,
1234 CommandFlag flags, bool alwaysEnabled, const wxEvent * evt,
1235 const CommandContext *pGivenContext)
1236{
1237 if (!entry )
1238 return false;
1239
1240 if (flags != AlwaysEnabledFlag && !entry->enabled)
1241 return false;
1242
1243 if (!alwaysEnabled && entry->flags.any()) {
1244
1245 const auto NiceName = entry->label.Stripped(
1247 // NB: The call may have the side effect of changing flags.
1248 bool allowed =
1250 NiceName, flags, entry->flags );
1251 // If the function was disallowed, it STILL should count as having been
1252 // handled (by doing nothing or by telling the user of the problem).
1253 // Otherwise we may get other handlers having a go at obeying the command.
1254 if (!allowed)
1255 return true;
1256 mNiceName = NiceName;
1257 }
1258 else {
1259 mNiceName = {};
1260 }
1261
1262 Journal::Output({ JournalCode, entry->name.GET() });
1263
1264 CommandContext context{ project, evt, entry->index, entry->parameter };
1265 if (pGivenContext)
1266 context.temporarySelection = pGivenContext->temporarySelection;
1267 auto &handler = entry->finder(project);
1268 (handler.*(entry->callback))(context);
1269 mLastProcessId = 0;
1270 return true;
1271}
1272
1273// Called by Contrast and Plot Spectrum Plug-ins to mark them as Last Analzers.
1274// Note that Repeat data has previously been collected
1276 if (mLastProcessId != 0) {
1277 auto& menuManager = MenuManager::Get(context.project);
1278 menuManager.mLastAnalyzerRegistration = MenuCreator::repeattypeunique;
1279 menuManager.mLastAnalyzerRegisteredId = mLastProcessId;
1280 auto lastEffectDesc = XO("Repeat %s").Format(mNiceName);
1281 Modify(wxT("RepeatLastAnalyzer"), lastEffectDesc);
1282 }
1283 return;
1284}
1285
1286// Called by Selected Tools to mark them as Last Tools.
1287// Note that Repeat data has previously been collected
1289 if (mLastProcessId != 0) {
1290 auto& menuManager = MenuManager::Get(context.project);
1291 menuManager.mLastToolRegistration = MenuCreator::repeattypeunique;
1292 menuManager.mLastToolRegisteredId = mLastProcessId;
1293 auto lastEffectDesc = XO("Repeat %s").Format(mNiceName);
1294 Modify(wxT("RepeatLastTool"), lastEffectDesc);
1295 }
1296 return;
1297}
1298
1299// Used to invoke Repeat Last Analyzer Process for built-in, non-nyquist plug-ins.
1301 mLastProcessId = 0; //Don't Process this as repeat
1303 auto& handler = entry->finder(context.project);
1304 (handler.*(entry->callback))(context);
1305}
1306
1307
1314 AudacityProject &project, int id, CommandFlag flags, bool alwaysEnabled)
1315{
1318
1319 if (GlobalMenuHook::Call(entry->name))
1320 return true;
1321
1322 return HandleCommandEntry( project, entry, flags, alwaysEnabled );
1323}
1324
1330 const CommandContext & context, CommandFlag flags, bool alwaysEnabled)
1331{
1332 if( Str.empty() )
1333 return CommandFailure;
1334 // Linear search for now...
1335 for (const auto &entry : mCommandList)
1336 {
1337 if (!entry->multi)
1338 {
1339 // Testing against labelPrefix too allows us to call Nyquist functions by name.
1340 if( Str == entry->name ||
1341 // PRL: uh oh, mixing internal string (Str) with user-visible
1342 // (labelPrefix, which was initialized from a user-visible
1343 // sub-menu name)
1344 Str == entry->labelPrefix.Translation() )
1345 {
1346 return HandleCommandEntry(
1347 context.project, entry.get(), flags, alwaysEnabled,
1348 nullptr, &context)
1350 }
1351 }
1352 else
1353 {
1354 // Handle multis too...
1355 if( Str == entry->name )
1356 {
1357 return HandleCommandEntry(
1358 context.project, entry.get(), flags, alwaysEnabled,
1359 nullptr, &context)
1361 }
1362 }
1363 }
1364 return CommandNotFound;
1365}
1366
1368{
1370
1371 for (const auto &entry : mCommandList) {
1372 auto &cat = entry->labelTop;
1373 if ( ! make_iterator_range( cats ).contains(cat) ) {
1374 cats.push_back(cat);
1375 }
1376 }
1377#if 0
1378 mCommandList.size(); i++) {
1379 if (includeMultis || !mCommandList[i]->multi)
1380 names.push_back(mCommandList[i]->name);
1381 }
1382
1383 if (p == NULL) {
1384 return;
1385 }
1386
1387 wxMenuBar *bar = p->GetMenuBar();
1388 size_t cnt = bar->GetMenuCount();
1389 for (size_t i = 0; i < cnt; i++) {
1390 cats.push_back(bar->GetMenuLabelText(i));
1391 }
1392
1393 cats.push_back(COMMAND);
1394#endif
1395
1396 return cats;
1397}
1398
1400 bool includeMultis) const
1401{
1402 for(const auto &entry : mCommandList) {
1403 if ( entry->isEffect )
1404 continue;
1405 if (!entry->multi)
1406 names.push_back(entry->name);
1407 else if( includeMultis )
1408 names.push_back(entry->name );// + wxT(":")/*+ mCommandList[i]->label*/);
1409 }
1410}
1411
1413 std::vector<bool> &vExcludeFromMacros,
1414 bool includeMultis) const
1415{
1416 vExcludeFromMacros.clear();
1417 for(const auto &entry : mCommandList) {
1418 // This is fetching commands from the menus, for use as batch commands.
1419 // Until we have properly merged EffectManager and CommandManager
1420 // we explicitly exclude effects, as they are already handled by the
1421 // effects Manager.
1422 if ( entry->isEffect )
1423 continue;
1424 if (!entry->multi)
1425 names.push_back(entry->longLabel), vExcludeFromMacros.push_back(entry->excludeFromMacros);
1426 else if( includeMultis )
1427 names.push_back(entry->longLabel), vExcludeFromMacros.push_back(entry->excludeFromMacros);
1428 }
1429}
1430
1433 std::vector<NormalizedKeyString> &keys,
1434 std::vector<NormalizedKeyString> &default_keys,
1435 TranslatableStrings &labels,
1436 TranslatableStrings &categories,
1437#if defined(EXPERIMENTAL_KEY_VIEW)
1438 TranslatableStrings &prefixes,
1439#endif
1440 bool includeMultis)
1441{
1442 for(const auto &entry : mCommandList) {
1443 // GetAllCommandData is used by KeyConfigPrefs.
1444 // It does need the effects.
1445 //if ( entry->isEffect )
1446 // continue;
1447 if ( !entry->multi || includeMultis )
1448 {
1449 names.push_back(entry->name);
1450 keys.push_back(entry->key);
1451 default_keys.push_back(entry->defaultKey);
1452 labels.push_back(entry->label);
1453 categories.push_back(entry->labelTop);
1454#if defined(EXPERIMENTAL_KEY_VIEW)
1455 prefixes.push_back(entry->labelPrefix);
1456#endif
1457 }
1458 }
1459}
1460
1462{
1464 if (!entry)
1465 return {};
1466 return entry->name;
1467}
1468
1470{
1472 if (!entry)
1473 return {};
1474
1475 return entry->longLabel;
1476}
1477
1479{
1481 if (!entry)
1482 return {};
1483
1484 if (!entry->labelPrefix.empty())
1485 return Verbatim( wxT("%s - %s") )
1486 .Format(entry->labelPrefix, entry->label)
1487 .Stripped();
1488 else
1489 return entry->label.Stripped();
1490}
1491
1493{
1495 if (!entry)
1496 return {};
1497
1498 return entry->labelTop;
1499}
1500
1502{
1504 // May create a NULL entry
1505 const_cast<CommandManager*>(this)->mCommandNameHash[name];
1506 if (!entry)
1507 return {};
1508
1509 return entry->key;
1510}
1511
1513{
1515 if (!entry)
1516 return {};
1517
1518 return entry->defaultKey;
1519}
1520
1521bool CommandManager::HandleXMLTag(const std::string_view& tag, const AttributesList &attrs)
1522{
1523 if (tag == "audacitykeyboard") {
1524 mXMLKeysRead = 0;
1525 }
1526
1527 if (tag == "command") {
1528 wxString name;
1530
1531 for (auto pair : attrs)
1532 {
1533 auto attr = pair.first;
1534 auto value = pair.second;
1535
1536 if (value.IsStringView())
1537 {
1538 const wxString strValue = value.ToWString();
1539
1540 if (attr == "name")
1541 name = strValue;
1542 else if (attr == "key")
1543 key = NormalizedKeyString{ strValue };
1544 }
1545 }
1546
1547 if (mCommandNameHash[name]) {
1548 mCommandNameHash[name]->key = key;
1549 mXMLKeysRead++;
1550 }
1551 }
1552
1553 return true;
1554}
1555
1556// This message is displayed now in KeyConfigPrefs::OnImport()
1557void CommandManager::HandleXMLEndTag(const std::string_view& tag)
1558{
1559 /*
1560 if (tag == "audacitykeyboard") {
1561 AudacityMessageBox(
1562 XO("Loaded %d keyboard shortcuts\n")
1563 .Format( mXMLKeysRead ),
1564 XO("Loading Keyboard Shortcuts"),
1565 wxOK | wxCENTRE);
1566 }
1567 */
1568}
1569
1570XMLTagHandler *CommandManager::HandleXMLChild(const std::string_view& WXUNUSED(tag))
1571{
1572 return this;
1573}
1574
1576// may throw
1577{
1578 xmlFile.StartTag(wxT("audacitykeyboard"));
1579 xmlFile.WriteAttr(wxT("audacityversion"), AUDACITY_VERSION_STRING);
1580
1581 for(const auto &entry : mCommandList) {
1582
1583 xmlFile.StartTag(wxT("command"));
1584 xmlFile.WriteAttr(wxT("name"), entry->name);
1585 xmlFile.WriteAttr(wxT("key"), entry->key);
1586 xmlFile.EndTag(wxT("command"));
1587 }
1588
1589 xmlFile.EndTag(wxT("audacitykeyboard"));
1590}
1591
1593{
1594 // To do: perhaps allow occult item switching at lower levels of the
1595 // menu tree.
1596 wxASSERT( !CurrentMenu() );
1597
1598 // Make a temporary menu bar collecting items added after.
1599 // This bar will be discarded but other side effects on the command
1600 // manager persist.
1601 mTempMenuBar = AddMenuBar(wxT("ext-menu"));
1602 bMakingOccultCommands = true;
1603}
1604
1606{
1607 PopMenuBar();
1608 bMakingOccultCommands = false;
1609 mTempMenuBar.reset();
1610}
1611
1613 CommandFlag flags)
1614{
1616 if (entry)
1617 entry->flags = flags;
1618}
1619
1620#if defined(_DEBUG)
1621void CommandManager::CheckDups()
1622{
1623 int cnt = mCommandList.size();
1624 for (size_t j = 0; (int)j < cnt; j++) {
1625 if (mCommandList[j]->key.empty()) {
1626 continue;
1627 }
1628
1629 if (mCommandList[j]->allowDup)
1630 continue;
1631
1632 for (size_t i = 0; (int)i < cnt; i++) {
1633 if (i == j) {
1634 continue;
1635 }
1636
1637 if (mCommandList[i]->key == mCommandList[j]->key) {
1638 wxString msg;
1639 msg.Printf(wxT("key combo '%s' assigned to '%s' and '%s'"),
1640 // using GET to form debug message
1641 mCommandList[i]->key.GET(),
1642 mCommandList[i]->label.Debug(),
1643 mCommandList[j]->label.Debug());
1644 wxASSERT_MSG(mCommandList[i]->key != mCommandList[j]->key, msg);
1645 }
1646 }
1647 }
1648}
1649
1650#endif
1651
1652// If a default shortcut of a command is introduced or changed, then this
1653// shortcut may be the same shortcut a user has previously assigned to another
1654// command. This function removes such duplicates by removing the shortcut
1655// from the command whose default has changed.
1656// Note that two commands may have the same shortcut if their default shortcuts
1657// are the same. However, in this function default shortcuts are checked against
1658// user assigned shortcuts. Two such commands with the same shortcut
1659// must both be in either the first or the second group, so there is no need
1660// to test for this case.
1661// Note that if a user is using the full set of default shortcuts, and one
1662// of these is changed, then if /GUI/Shortcuts/FullDefaults is not set in audacity.cfg,
1663// because the defaults appear as user assigned shortcuts in audacity.cfg,
1664// the previous default overrides the changed default, and no duplicate can
1665// be introduced.
1667{
1668 TranslatableString disabledShortcuts;
1669
1670 for (auto& entry : mCommandList) {
1671 if (!entry->key.empty() && entry->key != entry->defaultKey) { // user assigned
1672 for (auto& entry2 : mCommandList) {
1673 if (!entry2->key.empty() && entry2->key == entry2->defaultKey) { // default
1674 if (entry2->key == entry->key) {
1675 auto name = wxT("/NewKeys/") + entry2->name.GET();
1676 gPrefs->Write(name, NormalizedKeyString{});
1677
1678 disabledShortcuts +=
1679 XO("\n* %s, because you have assigned the shortcut %s to %s")
1680 .Format(entry2->label.Strip(), entry->key.GET(), entry->label.Strip());
1681 }
1682 }
1683 }
1684 }
1685 }
1686
1687 if (!disabledShortcuts.Translation().empty()) {
1688 TranslatableString message = XO("The following commands have had their shortcuts removed,"
1689 " because their default shortcut is new or changed, and is the same shortcut"
1690 " that you have assigned to another command.")
1691 + disabledShortcuts;
1692 AudacityMessageBox(message, XO("Shortcuts have been removed"), wxOK | wxCENTRE);
1693
1694 gPrefs->Flush();
1696 }
1697}
1698
1699#include "../KeyboardCapture.h"
1700
1701static KeyboardCapture::PreFilter::Scope scope1{
1702[]( wxKeyEvent & ) {
1703 // We must have a project since we will be working with the
1704 // CommandManager, which is tied to individual projects.
1705 auto project = GetActiveProject().lock();
1706 return project && GetProjectFrame( *project ).IsEnabled();
1707} };
1708static KeyboardCapture::PostFilter::Scope scope2{
1709[]( wxKeyEvent &key ) {
1710 // Capture handler window didn't want it, so ask the CommandManager.
1711 if (auto project = GetActiveProject().lock()) {
1712 auto &manager = CommandManager::Get( *project );
1713 return manager.FilterKeyEvent(project.get(), key);
1714 }
1715 else
1716 return false;
1717} };
1718
AUDACITY_DLL_API std::weak_ptr< AudacityProject > GetActiveProject()
wxT("CloseDown"))
@ Internal
Indicates internal failure from Audacity.
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:35
std::bitset< NCommandFlags > CommandFlag
Definition: CommandFlag.h:31
constexpr CommandFlag NoFlagsSpecified
Definition: CommandFlag.h:36
void(CommandHandlerObject::*)(const CommandContext &context) CommandFunctorPointer
std::function< CommandHandlerObject &(AudacityProject &) > CommandHandlerFinder
static KeyboardCapture::PostFilter::Scope scope2
static const AudacityProject::AttachedObjects::RegisteredFactory key
#define COMMAND
static KeyboardCapture::PreFilter::Scope scope1
const TranslatableString name
Definition: Distortion.cpp:82
@ none
Definition: Dither.h:20
int format
Definition: ExportPCM.cpp:56
std::vector< CommandID > CommandIDs
Definition: Identifier.h:233
#define XO(s)
Definition: Internat.h:31
NormalizedKeyString KeyEventToKeyString(const wxKeyEvent &event)
Definition: Keyboard.cpp:83
ValueRestorer< T > valueRestorer(T &var)
inline functions provide convenient parameter type deduction
Definition: MemoryX.h:234
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:431
FileConfig * gPrefs
Definition: Prefs.cpp:71
static ProjectFileIORegistry::AttributeWriterEntry entry
wxFrame * FindProjectFrame(AudacityProject *project)
Get a pointer to the window associated with a project, or null if the given pointer is null,...
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
accessors for certain important windows associated with each project
static const AttachedProjectObjects::RegisteredFactory manager
TranslatableString label
Definition: TagsEditor.cpp:163
static TranslatableStrings names
Definition: TagsEditor.cpp:151
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
std::vector< TranslatableString > TranslatableStrings
int id
std::vector< Attribute > AttributesList
Definition: XMLTagHandler.h:40
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
This specialization of Setting for bool adds a Toggle method to negate the saved value.
Definition: Prefs.h:339
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:266
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
TemporarySelection temporarySelection
AudacityProject & project
CommandManager implements a system for organizing all user-callable commands.
void WriteXML(XMLWriter &xmlFile) const
CommandList mCommandList
void Enable(const wxString &name, bool enabled)
void HandleXMLEndTag(const std::string_view &tag) override
void AddItemList(const CommandID &name, const ComponentInterfaceSymbol items[], size_t nItems, CommandHandlerFinder finder, CommandFunctorPointer callback, CommandFlag flags, bool bIsEffect=false)
void AddGlobalCommand(const CommandID &name, const TranslatableString &label, CommandHandlerFinder finder, CommandFunctorPointer callback, const Options &options={})
void RegisterLastTool(const CommandContext &context)
wxMenu * CurrentSubMenu() const
CommandListEntry * NewIdentifier(const CommandID &name, const TranslatableString &label, wxMenu *menu, CommandHandlerFinder finder, CommandFunctorPointer callback, const CommandID &nameSuffix, int index, int count, const Options &options)
wxMenu * BeginMenu(const TranslatableString &tName)
wxString FormatLabelForMenu(const CommandID &id, const TranslatableString *pLabel) const
Format a string appropriate for insertion in a menu.
CommandNameHash mCommandNameHash
wxString FormatLabelWithDisabledAccel(const CommandListEntry *entry) const
void UpdateCheckmarks(AudacityProject &project)
bool HandleMenuID(AudacityProject &project, int id, CommandFlag flags, bool alwaysEnabled)
TranslatableStrings GetCategories(AudacityProject &)
std::unique_ptr< wxMenuBar > mTempMenuBar
TranslatableString mCurrentMenuName
TranslatableString DescribeCommandsAndShortcuts(const ComponentInterfaceSymbol commands[], size_t nCommands) const
MenuBarList mMenuBarList
SubMenuList mSubMenuList
bool FilterKeyEvent(AudacityProject *project, const wxKeyEvent &evt, bool permit=false)
wxMenu * CurrentMenu() const
void DoRepeatProcess(const CommandContext &context, int)
XMLTagHandler * HandleXMLChild(const std::string_view &tag) override
std::vector< NormalizedKeyString > mMaxListOnly
wxMenuBar * CurrentMenuBar() const
void Modify(const wxString &name, const TranslatableString &newLabel)
Changes the label text of a menu item.
void RegisterLastAnalyzer(const CommandContext &context)
static CommandManager & Get(AudacityProject &project)
std::unique_ptr< wxMenu > uCurrentMenu
void EndMenu()
This attaches a menu, if it's main, to the menubar.
wxMenu * BeginSubMenu(const TranslatableString &tName)
void RemoveDuplicateShortcuts()
void GetAllCommandLabels(TranslatableStrings &labels, std::vector< bool > &vExcludeFromMacros, bool includeMultis) const
void AddItem(AudacityProject &project, const CommandID &name, const TranslatableString &label_in, CommandHandlerFinder finder, CommandFunctorPointer callback, CommandFlag flags, const Options &options={})
TextualCommandResult HandleTextualCommand(const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)
wxMenu * BeginMainMenu(const TranslatableString &tName)
TranslatableString GetLabelFromName(const CommandID &name)
bool bMakingOccultCommands
int NextIdentifier(int ID)
TranslatableString GetCategoryFromName(const CommandID &name)
void GetAllCommandData(CommandIDs &names, std::vector< NormalizedKeyString > &keys, std::vector< NormalizedKeyString > &default_keys, TranslatableStrings &labels, TranslatableStrings &categories, bool includeMultis)
static const std::vector< NormalizedKeyString > & ExcludedList()
CommandKeyHash mCommandKeyHash
std::function< bool(AudacityProject &) > CheckFn
void SetCommandFlags(const CommandID &name, CommandFlag flags)
bool GetEnabled(const CommandID &name)
void SetKeyFromName(const CommandID &name, const NormalizedKeyString &key)
wxMenu * mCurrentMenu
NormalizedKeyString GetKeyFromName(const CommandID &name) const
void Check(const CommandID &name, bool checked)
bool HandleXMLTag(const std::string_view &tag, const AttributesList &attrs) override
wxMenuBar * GetMenuBar(const wxString &sMenu) const
CommandID GetNameFromNumericID(int id)
void GetAllCommandNames(CommandIDs &names, bool includeMultis) const
void EnableUsingFlags(CommandFlag flags, CommandFlag strictFlags)
NormalizedKeyString GetDefaultKeyFromName(const CommandID &name)
bool HandleCommandEntry(AudacityProject &project, const CommandListEntry *entry, CommandFlag flags, bool alwaysEnabled, const wxEvent *evt=nullptr, const CommandContext *pGivenContext=nullptr)
virtual ~CommandManager()
void SetKeyFromIndex(int i, const NormalizedKeyString &key)
int GetNumberOfKeysRead() const
std::unique_ptr< wxMenuBar > AddMenuBar(const wxString &sMenu)
TranslatableString GetPrefixedLabelFromName(const CommandID &name)
TranslatableString mNiceName
CommandNumericIDHash mCommandNumericIDHash
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
virtual bool HasEntry(const wxString &strName) const wxOVERRIDE
Definition: FileConfig.cpp:138
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
virtual void SetPath(const wxString &strPath) wxOVERRIDE
Definition: FileConfig.cpp:93
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.
bool empty() const
Definition: Identifier.h:61
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
static void RebuildAllMenuBars()
Definition: Menus.cpp:687
@ repeattypeunique
Definition: Menus.h:63
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:71
bool ReportIfActionNotAllowed(const TranslatableString &Name, CommandFlag &flags, CommandFlag flagsRqd)
Definition: Menus.cpp:705
CommandFlag GetUpdateFlags(bool checkActive=false) const
Definition: Menus.cpp:553
Holds a msgid for the translation catalog; may also bind format arguments.
Identifier MSGID() const
MSGID is the English lookup key in the catalog, not necessarily for user's eyes if locale is some oth...
wxString Translation() const
TranslatableString & Format(Args &&...args) &
Capture variadic format arguments (by copy) when there is no plural.
wxString Debug() const
Format as an English string for debugging logs and developers' eyes, not for end users.
TranslatableString Stripped(unsigned options=MenuCodes) const
non-mutating, constructs another TranslatableString object
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:42
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:26
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
void Output(const wxString &string)
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
STL namespace.
CommandListEntry is a structure used by CommandManager.
bool isGlobal
CommandFlag flags
bool allowDup
CommandID name
bool isOccult
bool multi
int count
wxMenu * menu
TranslatableString longLabel
std::function< bool(AudacityProject &) > CheckFn
int id
CommandParameter parameter
bool wantKeyup
bool isEffect
CommandHandlerFinder finder
int index
bool enabled
TranslatableString label
TranslatableString labelTop
bool skipKeydown
CheckFn checkmarkFn
bool useStrictFlags
NormalizedKeyString defaultKey
bool excludeFromMacros
TranslatableString labelPrefix
NormalizedKeyString key
CommandFunctorPointer callback
TranslatableString longName
static CheckFn MakeCheckFn(const wxString key, bool defaultValue)
Options && IsEffect(bool value=true) &&
CommandParameter parameter
MenuBarListEntry is a structure used by CommandManager.
wxWeakRef< wxMenuBar > menubar
MenuBarListEntry(const wxString &name_, wxMenuBar *menubar_)
~MenuBarListEntry()
wxString name
SubMenuListEntry is a structure used by CommandManager.
std::unique_ptr< wxMenu > menu
SubMenuListEntry(const TranslatableString &name_)
~SubMenuListEntry()
SubMenuListEntry(SubMenuListEntry &&)=default
TranslatableString name