43#include <unordered_set>
46#include <wx/windowptr.h>
66 return std::make_shared< MenuManager >( project ); }
93 bool bSelectAllIfNone;
94 gPrefs->Read(
wxT(
"/GUI/SelectAllOnNone"), &bSelectAllIfNone,
false);
109 bool isExtension =
false;
120 isExtension = pWhole->extension;
160 bool separate =
false;
191) :
GroupItem{ internalName, move(items) }
200) :
GroupItem{ internalName, move(items) }
201 , condition{ condition }
213, finder{ finder_ }, callback{ callback_ }
214, flags{ flags_ }, options{ options_ }
219 std::vector< ComponentInterfaceSymbol > items_,
225, finder{ finder_ }, callback{ callback_ }
226, flags{ flags_ }, isEffect{ isEffect_ }
293 if (
const auto pMenu =
295 manager.BeginMenu( pMenu->title );
298 if (
const auto pConditionalGroup =
300 const auto flag = pConditionalGroup->condition();
304 flags.push_back(
flag);
307 if (
const auto pGroup =
dynamic_cast<MenuSection*
>( pItem ) ) {
316 if (
const auto pMenu =
321 if (
const auto pConditionalGroup =
323 const bool flag = flags.back();
329 if (
const auto pGroup =
dynamic_cast<MenuSection*
>( pItem ) ) {
337 const auto pCurrentMenu =
manager.CurrentMenu();
338 if ( !pCurrentMenu ) {
345 if (
const auto pCommand =
348 pCommand->name, pCommand->label_in,
349 pCommand->finder, pCommand->callback,
350 pCommand->flags, pCommand->options
354 if (
const auto pCommandList =
356 manager.AddItemList(pCommandList->name,
357 pCommandList->items.data(), pCommandList->items.size(),
358 pCommandList->finder, pCommandList->callback,
359 pCommandList->flags, pCommandList->isEffect);
362 if (
const auto pSpecial =
364 wxASSERT( pCurrentMenu );
365 pSpecial->fn( project, *pCurrentMenu );
395"File,Edit,Select,View,Transport,Tracks,Generate,Effect,Analyze,Tools,Window,Optional,Help"
397 {
wxT(
"/Optional/Extra/Part1"),
wxT(
398"Transport,Tools,Mixer,Edit,PlayAtSpeed,Seek,Device,Select"
400 {
wxT(
"/Optional/Extra/Part2"),
wxT(
401"Navigation,Focus,Cursor,Track,Scriptables1,Scriptables2"
403 {
wxT(
"/View/Windows"),
wxT(
"UndoHistory,Karaoke,MixerBoard")},
404 {
wxT(
"/Analyze/Analyzers/Windows"),
wxT(
"ContrastAnalyser,PlotSpectrum")},
405 {
wxT(
"/Transport/Basic"),
wxT(
"Play,Record,Scrubbing,Cursor")},
406 {
wxT(
"/View/Other/Toolbars/Toolbars/Other"),
wxT(
407"ShowTransportTB,ShowToolsTB,ShowRecordMeterTB,ShowPlayMeterTB,"
410"ShowEditTB,ShowTranscriptionTB,ShowScrubbingTB,ShowDeviceTB,ShowSelectionTB,"
411"ShowSpectralSelectionTB") },
412 {
wxT(
"/Tracks/Add/Add"),
wxT(
413"NewMonoTrack,NewStereoTrack,NewLabelTrack,NewTimeTrack")},
414 {
wxT(
"/Optional/Extra/Part2/Scriptables1"),
wxT(
415"SelectTime,SelectFrequencies,SelectTracks,SetTrackStatus,SetTrackAudio,"
416"SetTrackVisuals,GetPreference,SetPreference,SetClip,SetEnvelope,SetLabel"
418 {
wxT(
"/Optional/Extra/Part2/Scriptables2"),
wxT(
419"Select,SetTrack,GetInfo,Message,Help,Import2,Export2,OpenProject2,"
420"SaveProject2,Drag,CompareAudio,Screenshot") },
428 commandManager.SetMaxList();
430 auto menubar = commandManager.AddMenuBar(
wxT(
"appmenu"));
433 MenuItemVisitor visitor{ project, commandManager };
460 int cur = undoManager.GetCurrentState();
462 if (undoManager.UndoAvailable()) {
463 undoManager.GetShortDescription(cur, &
desc);
464 commandManager.Modify(
wxT(
"Undo"),
467 commandManager.Enable(
wxT(
"Undo"),
471 commandManager.Modify(
wxT(
"Undo"),
475 if (undoManager.RedoAvailable()) {
476 undoManager.GetShortDescription(cur+1, &
desc);
477 commandManager.Modify(
wxT(
"Redo"),
480 commandManager.Enable(
wxT(
"Redo"),
484 commandManager.Modify(
wxT(
"Redo"),
486 commandManager.Enable(
wxT(
"Redo"),
false);
494 using wxFrame::DetachMenuBar;
502#if defined(__WXMAC__) && defined(_DEBUG)
506 wxASSERT((!dlg || !dlg->IsModal()));
514 wxWindowPtr<wxMenuBar> menuBar{ window.GetMenuBar() };
515 window.DetachMenuBar();
521 CreateMenusAndCommands(project);
526 switch (message.
type) {
535 ModifyUndoMenuItems( mProject );
554 if ( options[ii].quickTest ) {
555 quickFlags[ii] =
true;
556 if( predicate( mProject ) )
564 flags = (lastFlags & ~quickFlags) | flags;
567 for (
const auto &predicate
569 if ( !options[ii].quickTest && predicate( mProject ) )
583 auto &project = mProject;
585 auto flags = GetUpdateFlags(checkActive);
588 if (flags == mLastFlags)
601 auto actual = enabler.actualFlags();
603 enabler.applicable( project ) && (flags & actual) == actual
605 flags2 |= enabler.possibleFlags();
613 commandManager.EnableUsingFlags(
615 (mWhatIfNoSelection == 0 ? flags2 : flags)
629#if defined(__WXGTK__)
636 wxRect r = window.GetRect();
637 window.SetSize(wxSize(1,1));
638 window.SetSize(r.GetSize());
646 auto &project = mProject;
647 bool bAllowed = TryToMakeActionAllowed( flags, flagsRqd );
651 TellUserWhyDisallowed( Name, flags & flagsRqd, flagsRqd);
661 auto &project = mProject;
664 flags = GetUpdateFlags();
668 auto iter = enablers.begin(),
end = enablers.end();
669 while ((flags & flagsRqd) != flagsRqd && iter !=
end) {
670 const auto &enabler = *iter;
671 auto actual = enabler.actualFlags();
672 auto MissingFlags = (~flags & flagsRqd);
675 (flags & actual) == actual
678 (MissingFlags & enabler.possibleFlags()).any()
681 enabler.tryEnable( project, flagsRqd );
682 flags = GetUpdateFlags();
686 return (flags & flagsRqd) == flagsRqd;
694 auto reason =
XO(
"There was a problem with your last action. If you think\nthis is a bug, please tell us exactly where it occurred.");
696 auto untranslatedTitle =
XO(
"Disallowed");
699 bool enableDefaultMessage =
true;
700 bool defaultMessage =
true;
703 if ( options.message ) {
704 reason = options.message( Name );
705 defaultMessage =
false;
706 if ( !options.title.empty() )
707 untranslatedTitle = options.title;
708 helpPage = options.helpPage;
712 enableDefaultMessage =
713 enableDefaultMessage && options.enableDefaultMessage;
719 auto missingFlags = flagsRequired & ~flagsGot;
722 unsigned priority = 0;
723 for (
const auto &options : alloptions )
724 priority = std::max( priority, options.priority );
729 while( priority-- ) {
731 for (
const auto &options : alloptions ) {
733 priority == options.priority
737 doOption( options ) )
750 !enableDefaultMessage
Toolkit-neutral facade for basic user interface services.
constexpr CommandFlag AlwaysEnabledFlag
std::bitset< NCommandFlags > CommandFlag
std::function< CommandHandlerObject &(AudacityProject &) > CommandHandlerFinder
wxEvtHandler CommandHandlerObject
const TranslatableString desc
XXO("&Cut/Copy/Paste Toolbar")
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
static const auto MenuPathStart
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
CommandManager implements a system for organizing all user-callable commands.
static CommandManager & Get(AudacityProject &project)
An explicitly nonlocalized string, not meant for the user to see.
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
static ProjectHistory & Get(AudacityProject &project)
Generates classes whose instances register items at construction.
std::vector< Identifier > Path
static const Predicates & RegisteredPredicates()
static const std::vector< CommandFlagOptions > & Options()
Holds a msgid for the translation catalog; may also bind format arguments.
static UndoManager & Get(AudacityProject &project)
void ShowErrorDialog(const WindowPlacement &placement, const TranslatableString &dlogTitle, const TranslatableString &message, const ManualPageID &helpPage, const ErrorDialogOptions &options={})
Show an error dialog with a link to the manual for further help.
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
std::unique_ptr< BaseItem > BaseItemPtr
std::vector< BaseItemPtr > BaseItemPtrs
void Visit(Visitor &visitor, BaseItem *pTopItem, const GroupItemBase *pRegistry)
~CommandGroupItem() override
CommandGroupItem(const Identifier &name_, std::vector< ComponentInterfaceSymbol > items_, CommandFunctorPointer callback_, CommandFlag flags_, bool isEffect_, CommandHandlerFinder finder_)
CommandItem(const CommandID &name_, const TranslatableString &label_in_, CommandFunctorPointer callback_, CommandFlag flags_, const CommandManager::Options &options_, CommandHandlerFinder finder_)
Common abstract base class for items that group other items.
Ordering
Choose treatment of the children of the group when merging trees.
Type of message published by UndoManager.
enum UndoRedoMessage::Type type