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 const auto properties =
112 bool inlined =
false;
113 bool shouldDoSeparator =
false;
115 switch (properties) {
134 return { !inlined, shouldDoSeparator };
140 const auto properties =
144 bool isExtension =
false;
146 switch (properties) {
158 needSeparator.push_back(
false);
159 firstItem.push_back(!isExtension);
166 const auto properties =
169 bool inlined =
false;
171 switch (properties) {
177 if ( !needSeparator.empty() )
178 needSeparator.back() =
true;
183 firstItem.pop_back();
184 needSeparator.pop_back();
196 bool separate =
false;
197 if (!needSeparator.empty()) {
198 separate = needSeparator.back() && !firstItem.back();
199 needSeparator.back() =
false;
200 firstItem.back() =
false;
219, finder{ finder_ }, callback{ callback_ }
220, flags{ flags_ }, options{ options_ }
225 std::vector< ComponentInterfaceSymbol > items_,
231, finder{ finder_ }, callback{ callback_ }
232, flags{ flags_ }, isEffect{ isEffect_ }
286 [
this](
const MenuItem &menu,
auto&) {
290 const auto flag = conditionalGroup();
294 flags.push_back(
flag);
296 [
this](
auto &item,
auto&) {
302 [
this](
const auto &item,
const auto&) {
303 const auto pCurrentMenu =
manager.CurrentMenu();
309 else TypeSwitch::VDispatch<void, LeafTypes>(item,
317 manager.AddItemList(commandList.name,
318 commandList.items.data(), commandList.items.size(),
319 commandList.finder, commandList.callback,
320 commandList.flags, commandList.isEffect);
323 special.fn(mProject, *pCurrentMenu);
330 [
this](
const MenuItem &,
const auto&) {
334 const bool flag = flags.back();
339 [
this](
auto &item,
auto&) {
372"File,Edit,Select,View,Transport,Tracks,Generate,Effect,Analyze,Tools,Window,Optional,Help"
374 {
wxT(
"/Optional/Extra/Part1"),
wxT(
375"Transport,Tools,Mixer,Edit,PlayAtSpeed,Seek,Device,Select"
377 {
wxT(
"/Optional/Extra/Part2"),
wxT(
378"Navigation,Focus,Cursor,Track,Scriptables1,Scriptables2"
380 {
wxT(
"/View/Windows"),
wxT(
"UndoHistory,Karaoke,MixerBoard")},
381 {
wxT(
"/Analyze/Analyzers/Windows"),
wxT(
"ContrastAnalyser,PlotSpectrum")},
382 {
wxT(
"/Transport/Basic"),
wxT(
"Play,Record,Scrubbing,Cursor")},
383 {
wxT(
"/View/Other/Toolbars/Toolbars/Other"),
wxT(
384"ShowTransportTB,ShowToolsTB,ShowRecordMeterTB,ShowPlayMeterTB,"
387"ShowEditTB,ShowTranscriptionTB,ShowScrubbingTB,ShowDeviceTB,ShowSelectionTB,"
388"ShowSpectralSelectionTB") },
389 {
wxT(
"/Tracks/Add/Add"),
wxT(
390"NewMonoTrack,NewStereoTrack,NewLabelTrack,NewTimeTrack")},
391 {
wxT(
"/Optional/Extra/Part2/Scriptables1"),
wxT(
392"SelectTime,SelectFrequencies,SelectTracks,SetTrackStatus,SetTrackAudio,"
393"SetTrackVisuals,GetPreference,SetPreference,SetClip,SetEnvelope,SetLabel"
395 {
wxT(
"/Optional/Extra/Part2/Scriptables2"),
wxT(
396"Select,SetTrack,GetInfo,Message,Help,Import2,Export2,OpenProject2,"
397"SaveProject2,Drag,CompareAudio,Screenshot") },
405 commandManager.SetMaxList();
407 auto menubar = commandManager.AddMenuBar(
wxT(
"appmenu"));
410 MenuItemVisitor visitor{
project, commandManager };
438 int cur = undoManager.GetCurrentState();
440 if (undoManager.UndoAvailable()) {
441 undoManager.GetShortDescription(cur, &
desc);
442 commandManager.Modify(
wxT(
"Undo"),
445 commandManager.Enable(
wxT(
"Undo"),
449 commandManager.Modify(
wxT(
"Undo"),
453 if (undoManager.RedoAvailable()) {
454 undoManager.GetShortDescription(cur+1, &
desc);
455 commandManager.Modify(
wxT(
"Redo"),
458 commandManager.Enable(
wxT(
"Redo"),
462 commandManager.Modify(
wxT(
"Redo"),
464 commandManager.Enable(
wxT(
"Redo"),
false);
472 using wxFrame::DetachMenuBar;
480#if defined(__WXMAC__) && defined(_DEBUG)
484 wxASSERT((!dlg || !dlg->IsModal()));
492 wxWindowPtr<wxMenuBar> menuBar{ window.GetMenuBar() };
493 window.DetachMenuBar();
504 switch (message.
type) {
532 if ( options[ii].quickTest ) {
533 quickFlags[ii] =
true;
542 flags = (lastFlags & ~quickFlags) | flags;
545 for (
const auto &predicate
547 if ( !options[ii].quickTest && predicate(
mProject ) )
579 auto actual = enabler.actualFlags();
581 enabler.applicable(
project ) && (flags & actual) == actual
583 flags2 |= enabler.possibleFlags();
591 commandManager.EnableUsingFlags(
607#if defined(__WXGTK__)
614 wxRect r = window.GetRect();
615 window.SetSize(wxSize(1,1));
616 window.SetSize(r.GetSize());
646 auto iter = enablers.begin(),
end = enablers.end();
647 while ((flags & flagsRqd) != flagsRqd && iter !=
end) {
648 const auto &enabler = *iter;
649 auto actual = enabler.actualFlags();
650 auto MissingFlags = (~flags & flagsRqd);
653 (flags & actual) == actual
656 (MissingFlags & enabler.possibleFlags()).any()
659 enabler.tryEnable(
project, flagsRqd );
664 return (flags & flagsRqd) == flagsRqd;
672 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.");
674 auto untranslatedTitle =
XO(
"Disallowed");
677 bool enableDefaultMessage =
true;
678 bool defaultMessage =
true;
681 if ( options.message ) {
682 reason = options.message( Name );
683 defaultMessage =
false;
684 if ( !options.title.empty() )
685 untranslatedTitle = options.title;
686 helpPage = options.helpPage;
690 enableDefaultMessage =
691 enableDefaultMessage && options.enableDefaultMessage;
697 auto missingFlags = flagsRequired & ~flagsGot;
700 unsigned priority = 0;
701 for (
const auto &options : alloptions )
702 priority = std::max( priority, options.priority );
707 while( priority-- ) {
709 for (
const auto &options : alloptions ) {
711 priority == options.priority
715 doOption( options ) )
728 !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 name
XXO("&Cut/Copy/Paste Toolbar")
audacity::BasicSettings * gPrefs
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.
CallbackReturn Publish(const MenuUpdateMessage &message)
Send a message to connected callbacks.
static ProjectHistory & Get(AudacityProject &project)
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)
virtual bool Read(const wxString &key, bool *value) const =0
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.
void VisitWithFunctions(const VisitorFunctions< RegistryTraits > &visitors, const GroupItem< RegistryTraits > *pTopItem, const GroupItem< RegistryTraits > *pRegistry={}, typename RegistryTraits::ComputedItemContextType &computedItemContext=RegistryTraits::ComputedItemContextType::Instance)
const TranslatableString desc
~CommandGroupItem() override
CommandGroupItem(const Identifier &name_, std::vector< ComponentInterfaceSymbol > items_, CommandFunctorPointer callback_, CommandFlag flags_, bool isEffect_, CommandHandlerFinder finder_)
const TranslatableString label_in
CommandHandlerFinder finder
CommandFunctorPointer callback
CommandManager::Options options
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 are not groups.
Type of message published by UndoManager.
enum UndoRedoMessage::Type type