Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
MenuCreator Class Referencefinal

MenuCreator is responsible for creating the main menu bar. More...

#include <MenuCreator.h>

Inheritance diagram for MenuCreator:
[legend]
Collaboration diagram for MenuCreator:
[legend]

Classes

struct  SpecialItem
 

Public Member Functions

 MenuCreator (AudacityProject &project)
 
 ~MenuCreator () override
 
void CreateMenusAndCommands ()
 
void RebuildMenuBar ()
 
bool ReallyDoQuickCheck () override
 Default implementation returns true. More...
 
void RemoveDuplicateShortcuts ()
 
- Public Member Functions inherited from CommandManager
 CommandManager (AudacityProject &project)
 
 CommandManager (const CommandManager &)=delete
 
CommandManageroperator= (const CommandManager &)=delete
 
 ~CommandManager () override
 
CommandFlag GetUpdateFlags (bool quick=false) const
 
void UpdatePrefs () override
 
bool ReportIfActionNotAllowed (const TranslatableString &Name, CommandFlag &flags, CommandFlag flagsRqd)
 
bool TryToMakeActionAllowed (CommandFlag &flags, CommandFlag flagsRqd)
 
AudacityProjectGetProject ()
 
size_t NCommands () const
 
void PurgeData ()
 
void SetCommandFlags (const CommandID &name, CommandFlag flags)
 
void EnableUsingFlags (CommandFlag flags, CommandFlag strictFlags)
 
void Enable (const wxString &name, bool enabled)
 
void Check (const CommandID &name, bool checked)
 
void Modify (const wxString &name, const TranslatableString &newLabel)
 Changes the label text of a menu item. More...
 
void SetKeyFromName (const CommandID &name, const NormalizedKeyString &key)
 
void SetKeyFromIndex (int i, const NormalizedKeyString &key)
 
bool HandleMenuID (int id, CommandFlag flags, bool alwaysEnabled)
 
void RegisterLastAnalyzer (const CommandContext &context)
 
void RegisterLastTool (const CommandContext &context)
 
void DoRepeatProcess (const CommandContext &context, int)
 
TextualCommandResult HandleTextualCommand (const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)
 
TranslatableStrings GetCategories ()
 
void GetAllCommandNames (CommandIDs &names, bool includeMultis) const
 
void GetAllCommandLabels (TranslatableStrings &labels, std::vector< bool > &vExcludeFromMacros, bool includeMultis) const
 
void GetAllCommandData (CommandIDs &names, std::vector< NormalizedKeyString > &keys, std::vector< NormalizedKeyString > &default_keys, TranslatableStrings &labels, TranslatableStrings &categories, TranslatableStrings &prefixes, bool includeMultis)
 
CommandID GetNameFromNumericID (int id) const
 
TranslatableString GetLabelFromName (const CommandID &name) const
 
TranslatableString GetPrefixedLabelFromName (const CommandID &name) const
 
TranslatableString GetCategoryFromName (const CommandID &name) const
 
NormalizedKeyString GetKeyFromName (const CommandID &name) const
 
NormalizedKeyString GetDefaultKeyFromName (const CommandID &name) const
 
bool GetEnabled (const CommandID &name) const
 
int GetNumberOfKeysRead () const
 
TranslatableString ReportDuplicateShortcuts ()
 
void WriteXML (XMLWriter &xmlFile) const
 
TranslatableString DescribeCommandsAndShortcuts (const ComponentInterfaceSymbol commands[], size_t nCommands) const
 
void UpdateCheckmarks ()
 
wxString FormatLabelForMenu (const CommandID &id, const TranslatableString *pLabel) const
 Format a string appropriate for insertion in a menu. More...
 
void ModifyUndoMenuItems ()
 
void UpdateMenus (bool checkActive=true)
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs)=0
 
virtual void HandleXMLEndTag (const std::string_view &WXUNUSED(tag))
 
virtual void HandleXMLContent (const std::string_view &WXUNUSED(content))
 
virtual XMLTagHandlerHandleXMLChild (const std::string_view &tag)=0
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 
- Public Member Functions inherited from ClientData::Base
virtual ~Base ()
 
- Public Member Functions inherited from Observer::Publisher< MenuUpdateMessage >
 Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={})
 Constructor supporting type-erased custom allocation/deletion. More...
 
 Publisher (Publisher &&)=default
 
Publisheroperator= (Publisher &&)=default
 
Subscription Subscribe (Callback callback)
 Connect a callback to the Publisher; later-connected are called earlier. More...
 
Subscription Subscribe (Object &obj, Return(Object::*callback)(Args...))
 Overload of Subscribe takes an object and pointer-to-member-function. More...
 

Static Public Member Functions

static bool FilterKeyEvent (AudacityProject &project, const wxKeyEvent &evt, bool permit=false)
 
static MenuCreatorGet (AudacityProject &project)
 
static const MenuCreatorGet (const AudacityProject &project)
 
static void RebuildAllMenuBars ()
 
- Static Public Member Functions inherited from CommandManager
static CommandManagerGet (AudacityProject &project)
 
static const CommandManagerGet (const AudacityProject &project)
 
static const std::vector< NormalizedKeyString > & ExcludedList ()
 

Static Public Attributes

static constexpr auto Special = Callable::UniqueMaker<SpecialItem>()
 
- Static Public Attributes inherited from Observer::Publisher< MenuUpdateMessage >
static constexpr bool notifies_all
 

Private Member Functions

void ExecuteCommand (const CommandContext &context, const wxEvent *evt, const CommandListEntry &entry) override
 

Additional Inherited Members

- Public Types inherited from CommandManager
enum  { repeattypenone = 0 , repeattypeplugin = 1 , repeattypeunique = 2 , repeattypeapplymacro = 3 }
 
enum  TextualCommandResult { CommandFailure , CommandSuccess , CommandNotFound }
 
- Public Types inherited from Observer::Publisher< MenuUpdateMessage >
using message_type = MenuUpdateMessage
 
using CallbackReturn = std::conditional_t< true, void, bool >
 
using Callback = std::function< CallbackReturn(const MenuUpdateMessage &) >
 Type of functions that can be connected to the Publisher. More...
 
- Public Attributes inherited from CommandManager
CommandFlag mLastFlags = AlwaysEnabledFlag
 
PluginID mLastGenerator {}
 
PluginID mLastEffect {}
 
PluginID mLastAnalyzer {}
 
int mLastAnalyzerRegistration = repeattypenone
 
int mLastAnalyzerRegisteredId = -1
 
PluginID mLastTool {}
 
int mLastToolRegistration = repeattypenone
 
int mLastToolRegisteredId = -1
 
unsigned mRepeatGeneratorFlags = 0
 
unsigned mRepeatEffectFlags = 0
 
unsigned mRepeatAnalyzerFlags = 0
 
unsigned mRepeatToolFlags = 0
 
int mWhatIfNoSelection
 
bool mStopIfWasPaused { true }
 
- Protected Types inherited from CommandManager
using CommandKeyHash = std::unordered_map< NormalizedKeyString, CommandListEntry * >
 
- Protected Member Functions inherited from CommandManager
bool HandleCommandEntry (const CommandListEntry *entry, CommandFlag flags, bool alwaysEnabled, const wxEvent *evt=nullptr, const CommandContext *pGivenContext=nullptr)
 
virtual void ExecuteCommand (const CommandContext &context, const wxEvent *evt, const CommandListEntry &entry)
 
virtual bool ReallyDoQuickCheck ()
 Default implementation returns true. More...
 
- Protected Member Functions inherited from Observer::Publisher< MenuUpdateMessage >
CallbackReturn Publish (const MenuUpdateMessage &message)
 Send a message to connected callbacks. More...
 
- Protected Attributes inherited from CommandManager
AudacityProjectmProject
 
CommandKeyHash mCommandKeyHash
 
- Static Protected Attributes inherited from CommandManager
static const TranslatableString COMMAND = XO("Command")
 

Detailed Description

MenuCreator is responsible for creating the main menu bar.

Definition at line 18 of file MenuCreator.h.

Constructor & Destructor Documentation

◆ MenuCreator()

MenuCreator::MenuCreator ( AudacityProject project)

Definition at line 84 of file MenuCreator.cpp.

86{
87}
const auto project
CommandManager implements a system for organizing all user-callable commands.

◆ ~MenuCreator()

MenuCreator::~MenuCreator ( )
overridedefault

Member Function Documentation

◆ CreateMenusAndCommands()

void MenuCreator::CreateMenusAndCommands ( )

Definition at line 441 of file MenuCreator.cpp.

442{
443 {
444 MenuItemVisitor visitor{ mProject };
445 }
446
448
449#if defined(_DEBUG)
450// c->CheckDups();
451#endif
452}
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:34
AudacityProject & mProject
CommandFlag mLastFlags

References AlwaysEnabledFlag, CommandManager::mLastFlags, and CommandManager::mProject.

Referenced by ProjectManager::New(), and RebuildMenuBar().

Here is the caller graph for this function:

◆ ExecuteCommand()

void MenuCreator::ExecuteCommand ( const CommandContext context,
const wxEvent *  evt,
const CommandListEntry entry 
)
overrideprivatevirtual

Reimplemented from CommandManager.

Definition at line 490 of file MenuCreator.cpp.

492{
493 Journal::Output({ JournalCode, entry.name.GET() });
494 return CommandManager::ExecuteCommand(context, evt, entry);
495}
static ProjectFileIORegistry::AttributeWriterEntry entry
constexpr auto JournalCode
virtual void ExecuteCommand(const CommandContext &context, const wxEvent *evt, const CommandListEntry &entry)
void Output(const wxString &string)

References entry, CommandManager::ExecuteCommand(), JournalCode, and Journal::Output().

Here is the call graph for this function:

◆ FilterKeyEvent()

bool MenuCreator::FilterKeyEvent ( AudacityProject project,
const wxKeyEvent &  evt,
bool  permit = false 
)
static

Definition at line 568 of file MenuCreator.cpp.

570{
571 auto &cm = Get(project);
572
573 auto pWindow = FindProjectFrame(&project);
574 CommandListEntry *entry = cm.mCommandKeyHash[KeyEventToKeyString(evt)];
575 if (entry == NULL)
576 {
577 return false;
578 }
579
580 int type = evt.GetEventType();
581
582 // Global commands aren't tied to any specific project
583 if (entry->isGlobal && type == wxEVT_KEY_DOWN)
584 {
585 // Global commands are always disabled so they do not interfere with the
586 // rest of the command handling. But, to use the common handler, we
587 // enable them temporarily and then disable them again after handling.
588 // LL: Why do they need to be disabled???
589 entry->enabled = false;
590 auto cleanup = valueRestorer( entry->enabled, true );
591 return cm.HandleCommandEntry(entry, NoFlagsSpecified, false, &evt);
592 }
593
594 wxWindow * pFocus = wxWindow::FindFocus();
595 wxWindow * pParent = wxGetTopLevelParent( pFocus );
596 bool validTarget = pParent == pWindow;
597 // Bug 1557. MixerBoard should count as 'destined for project'
598 // MixerBoard IS a TopLevelWindow, and its parent is the project.
599 if( pParent && pParent->GetParent() == pWindow ){
600 if(auto keystrokeHandlingWindow = dynamic_cast< TopLevelKeystrokeHandlingWindow* >( pParent ))
601 validTarget = keystrokeHandlingWindow->HandleCommandKeystrokes();
602 }
603 validTarget = validTarget && wxEventLoop::GetActive()->IsMain();
604
605 // Any other keypresses must be destined for this project window
606 if (!permit && !validTarget )
607 {
608 return false;
609 }
610
611 auto flags = cm.GetUpdateFlags();
612
613 wxKeyEvent temp = evt;
614
615 // Possibly let wxWidgets do its normal key handling IF it is one of
616 // the standard navigation keys.
617 if((type == wxEVT_KEY_DOWN) || (type == wxEVT_KEY_UP ))
618 {
619 wxWindow * pWnd = wxWindow::FindFocus();
620 bool bIntercept =
621 pWnd && !dynamic_cast< NonKeystrokeInterceptingWindow * >( pWnd );
622
623 //wxLogDebug("Focus: %p TrackPanel: %p", pWnd, pTrackPanel );
624 // We allow the keystrokes below to be handled by wxWidgets controls IF we are
625 // in some sub window rather than in the TrackPanel itself.
626 // Otherwise they will go to our command handler and if it handles them
627 // they will NOT be available to wxWidgets.
628 if( bIntercept ){
629 switch( evt.GetKeyCode() ){
630 case WXK_LEFT:
631 case WXK_RIGHT:
632 case WXK_UP:
633 case WXK_DOWN:
634 // Don't trap WXK_SPACE (Bug 1727 - SPACE not starting/stopping playback
635 // when cursor is in a time control)
636 // case WXK_SPACE:
637 case WXK_TAB:
638 case WXK_BACK:
639 case WXK_HOME:
640 case WXK_END:
641 case WXK_RETURN:
642 case WXK_NUMPAD_ENTER:
643 case WXK_DELETE:
644 case '0':
645 case '1':
646 case '2':
647 case '3':
648 case '4':
649 case '5':
650 case '6':
651 case '7':
652 case '8':
653 case '9':
654 return false;
655 case ',':
656 case '.':
657 if (!evt.HasAnyModifiers())
658 return false;
659 }
660 }
661 }
662
663 if (type == wxEVT_KEY_DOWN)
664 {
665 if (entry->skipKeydown)
666 {
667 return true;
668 }
669 return cm.HandleCommandEntry(entry, flags, false, &temp);
670 }
671
672 if (type == wxEVT_KEY_UP && entry->wantKeyup)
673 {
674 return cm.HandleCommandEntry(entry, flags, false, &temp);
675 }
676
677 return false;
678}
constexpr CommandFlag NoFlagsSpecified
Definition: CommandFlag.h:35
ValueRestorer< T > valueRestorer(T &var)
inline functions provide convenient parameter type deduction
Definition: MemoryX.h:253
NormalizedKeyString KeyEventToKeyString(const wxKeyEvent &event)
wxFrame * FindProjectFrame(AudacityProject *project)
Get a pointer to the window associated with a project, or null if the given pointer is null,...
CommandListEntry is a structure used by CommandManager.
static MenuCreator & Get(AudacityProject &project)
Definition: MenuCreator.cpp:91
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:383

References entry, BasicUI::FindFocus(), FindProjectFrame(), Get(), KeyEventToKeyString(), NoFlagsSpecified, project, and valueRestorer().

Referenced by MixerBoardFrame::OnKeyEvent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get() [1/2]

MenuCreator & MenuCreator::Get ( AudacityProject project)
static

Definition at line 91 of file MenuCreator.cpp.

92{
93 return static_cast<MenuCreator&>(CommandManager::Get(project));
94}
static CommandManager & Get(AudacityProject &project)
MenuCreator is responsible for creating the main menu bar.
Definition: MenuCreator.h:19

References CommandManager::Get(), and project.

Referenced by DoReloadPreferences(), FilterKeyEvent(), AudacityApp::InitPart2(), ProjectManager::New(), anonymous_namespace{EditMenus.cpp}::OnPreferences(), RebuildAllMenuBars(), and MacrosWindow::UpdateMenus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get() [2/2]

const MenuCreator & MenuCreator::Get ( const AudacityProject project)
static

Definition at line 96 of file MenuCreator.cpp.

97{
98 return static_cast<const MenuCreator&>(CommandManager::Get(project));
99}

References CommandManager::Get(), and project.

Here is the call graph for this function:

◆ ReallyDoQuickCheck()

bool MenuCreator::ReallyDoQuickCheck ( )
overridevirtual

Default implementation returns true.

Reimplemented from CommandManager.

Definition at line 499 of file MenuCreator.cpp.

500{
501 return !GetProjectFrame(mProject).IsActive();
502}
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 ...

References GetProjectFrame(), and CommandManager::mProject.

Here is the call graph for this function:

◆ RebuildAllMenuBars()

void MenuCreator::RebuildAllMenuBars ( )
static

The following method moves to the previous track selecting and unselecting depending if you are on the start of a block or not.

Definition at line 508 of file MenuCreator.cpp.

509{
510 for( auto p : AllProjects{} ) {
511 Get(*p).RebuildMenuBar();
512#if defined(__WXGTK__)
513 // Workaround for:
514 //
515 // http://bugzilla.audacityteam.org/show_bug.cgi?id=458
516 //
517 // This workaround should be removed when Audacity updates to wxWidgets 3.x which has a fix.
518 auto &window = GetProjectFrame( *p );
519 wxRect r = window.GetRect();
520 window.SetSize(wxSize(1,1));
521 window.SetSize(r.GetSize());
522#endif
523 }
524}
void RebuildMenuBar()

References Get(), GetProjectFrame(), and RebuildMenuBar().

Referenced by anonymous_namespace{PluginMenus.cpp}::DoManagePluginsMenu(), AudacityApp::InitPart2(), IncompatiblePluginsDialog::OnPluginManagerClicked(), anonymous_namespace{ViewMenus.cpp}::OnShowExtraMenus(), anonymous_namespace{SpectrumView.cpp}::SpectrogramSettingsHandler::OnSpectrogramSettings(), ProjectFileManager::OpenFile(), EffectsPrefs::PopulateOrExchange(), and RemoveDuplicateShortcuts().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RebuildMenuBar()

void MenuCreator::RebuildMenuBar ( )

Definition at line 461 of file MenuCreator.cpp.

462{
463 auto &project = mProject;
464 // On OSX, we can't rebuild the menus while a modal dialog is being shown
465 // since the enabled state for menus like Quit and Preference gets out of
466 // sync with wxWidgets idea of what it should be.
467#if defined(__WXMAC__) && defined(_DEBUG)
468 {
469 wxDialog *dlg =
470 wxDynamicCast(wxGetTopLevelParent(wxWindow::FindFocus()), wxDialog);
471 assert((!dlg || !dlg->IsModal()));
472 }
473#endif
474
475 // Delete the menus, since we will soon recreate them.
476 // Rather oddly, the menus don't vanish as a result of doing this.
477 {
478 auto &window = static_cast<wxFrameEx&>( GetProjectFrame( project ) );
479 wxWindowPtr<wxMenuBar> menuBar{ window.GetMenuBar() };
480 window.DetachMenuBar();
481 // menuBar gets deleted here
482 }
483
484 PurgeData();
486}
void CreateMenusAndCommands()

References CreateMenusAndCommands(), BasicUI::FindFocus(), GetProjectFrame(), CommandManager::mProject, project, and CommandManager::PurgeData().

Referenced by DoReloadPreferences(), anonymous_namespace{EditMenus.cpp}::OnPreferences(), RebuildAllMenuBars(), and MacrosWindow::UpdateMenus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveDuplicateShortcuts()

void MenuCreator::RemoveDuplicateShortcuts ( )

Definition at line 526 of file MenuCreator.cpp.

527{
528 const auto disabledShortcuts = ReportDuplicateShortcuts();
529 if (!disabledShortcuts.Translation().empty()) {
530 TranslatableString message = XO("The following commands have had their shortcuts removed,"
531 " because their default shortcut is new or changed, and is the same shortcut"
532 " that you have assigned to another command.")
533 + disabledShortcuts;
534 AudacityMessageBox(message, XO("Shortcuts have been removed"), wxOK | wxCENTRE);
535
536 gPrefs->Flush();
538 }
539}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
XO("Cut/Copy/Paste")
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
TranslatableString ReportDuplicateShortcuts()
static void RebuildAllMenuBars()
Holds a msgid for the translation catalog; may also bind format arguments.
virtual bool Flush() noexcept=0

References AudacityMessageBox(), audacity::BasicSettings::Flush(), gPrefs, RebuildAllMenuBars(), CommandManager::ReportDuplicateShortcuts(), and XO().

Referenced by AudacityApp::InitPart2().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ Special

constexpr auto MenuCreator::Special = Callable::UniqueMaker<SpecialItem>()
staticconstexpr

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