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