diff --git a/src/BatchCommands.cpp b/src/BatchCommands.cpp index 5725b9d45..a6f0ad835 100644 --- a/src/BatchCommands.cpp +++ b/src/BatchCommands.cpp @@ -778,7 +778,7 @@ bool MacroCommands::ApplyCommand( const wxString &friendlyCommand, AudacityProject *project = GetActiveProject(); auto &manager = CommandManager::Get( *project ); if( pContext ){ - if( manager.HandleTextualCommand( command, *pContext, AlwaysEnabledFlag, AlwaysEnabledFlag ) ) + if( manager.HandleTextualCommand( command, *pContext, AlwaysEnabledFlag, true ) ) return true; pContext->Status( wxString::Format( _("Your batch command of %s was not recognized."), friendlyCommand )); @@ -787,7 +787,7 @@ bool MacroCommands::ApplyCommand( const wxString &friendlyCommand, else { const CommandContext context( *GetActiveProject() ); - if( manager.HandleTextualCommand( command, context, AlwaysEnabledFlag, AlwaysEnabledFlag ) ) + if( manager.HandleTextualCommand( command, context, AlwaysEnabledFlag, true ) ) return true; } diff --git a/src/ProjectWindow.cpp b/src/ProjectWindow.cpp index e22ae3d49..0663da850 100644 --- a/src/ProjectWindow.cpp +++ b/src/ProjectWindow.cpp @@ -1513,7 +1513,7 @@ void ProjectWindow::OnMenu(wxCommandEvent & event) auto &commandManager = CommandManager::Get( project ); bool handled = commandManager.HandleMenuID( event.GetId(), MenuManager::Get( project ).GetUpdateFlags(), - NoFlagsSpecified); + false); if (handled) event.Skip(false); diff --git a/src/commands/CommandManager.cpp b/src/commands/CommandManager.cpp index ee0048d2e..2d1016103 100644 --- a/src/commands/CommandManager.cpp +++ b/src/commands/CommandManager.cpp @@ -1159,7 +1159,7 @@ bool CommandManager::FilterKeyEvent(AudacityProject *project, const wxKeyEvent & // LL: Why do they need to be disabled??? entry->enabled = false; auto cleanup = valueRestorer( entry->enabled, true ); - return HandleCommandEntry(entry, NoFlagsSpecified, NoFlagsSpecified, &evt); + return HandleCommandEntry(entry, NoFlagsSpecified, false, &evt); } wxWindow * pFocus = wxWindow::FindFocus(); @@ -1233,12 +1233,12 @@ bool CommandManager::FilterKeyEvent(AudacityProject *project, const wxKeyEvent & { return true; } - return HandleCommandEntry(entry, flags, NoFlagsSpecified, &temp); + return HandleCommandEntry(entry, flags, false, &temp); } if (type == wxEVT_KEY_UP && entry->wantKeyup) { - return HandleCommandEntry(entry, flags, NoFlagsSpecified, &temp); + return HandleCommandEntry(entry, flags, false, &temp); } return false; @@ -1249,7 +1249,7 @@ bool CommandManager::FilterKeyEvent(AudacityProject *project, const wxKeyEvent & ///the command won't be executed unless the flags are compatible ///with the command's flags. bool CommandManager::HandleCommandEntry(const CommandListEntry * entry, - CommandFlag flags, CommandMask mask, const wxEvent * evt) + CommandFlag flags, bool alwaysEnabled, const wxEvent * evt) { if (!entry ) return false; @@ -1259,8 +1259,7 @@ bool CommandManager::HandleCommandEntry(const CommandListEntry * entry, auto proj = GetActiveProject(); - auto combinedMask = (mask & entry->flags); - if (combinedMask.any()) { + if (!alwaysEnabled && entry->flags.any()) { wxASSERT( proj ); if( !proj ) @@ -1272,7 +1271,7 @@ bool CommandManager::HandleCommandEntry(const CommandListEntry * entry, // NB: The call may have the side effect of changing flags. bool allowed = MenuManager::Get(*proj).ReportIfActionNotAllowed( - NiceName, flags, entry->flags, combinedMask ); + NiceName, flags, entry->flags, entry->flags ); // If the function was disallowed, it STILL should count as having been // handled (by doing nothing or by telling the user of the problem). // Otherwise we may get other handlers having a go at obeying the command. @@ -1292,7 +1291,7 @@ bool CommandManager::HandleCommandEntry(const CommandListEntry * entry, ///CommandManagerListener function. If you pass any flags, ///the command won't be executed unless the flags are compatible ///with the command's flags. -bool CommandManager::HandleMenuID(int id, CommandFlag flags, CommandMask mask) +bool CommandManager::HandleMenuID(int id, CommandFlag flags, bool alwaysEnabled) { CommandListEntry *entry = mCommandNumericIDHash[id]; @@ -1300,13 +1299,13 @@ bool CommandManager::HandleMenuID(int id, CommandFlag flags, CommandMask mask) if (hook && hook(entry->name)) return true; - return HandleCommandEntry( entry, flags, mask ); + return HandleCommandEntry( entry, flags, alwaysEnabled ); } /// HandleTextualCommand() allows us a limitted version of script/batch /// behavior, since we can get from a string command name to the actual /// code to run. -bool CommandManager::HandleTextualCommand(const CommandID & Str, const CommandContext & context, CommandFlag flags, CommandMask mask) +bool CommandManager::HandleTextualCommand(const CommandID & Str, const CommandContext & context, CommandFlag flags, bool alwaysEnabled) { if( Str.empty() ) return false; @@ -1322,7 +1321,7 @@ bool CommandManager::HandleTextualCommand(const CommandID & Str, const CommandCo // sub-menu name) Str == entry->labelPrefix ) { - return HandleCommandEntry( entry.get(), flags, mask); + return HandleCommandEntry( entry.get(), flags, alwaysEnabled); } } else @@ -1330,7 +1329,7 @@ bool CommandManager::HandleTextualCommand(const CommandID & Str, const CommandCo // Handle multis too... if( Str == entry->name ) { - return HandleCommandEntry( entry.get(), flags, mask); + return HandleCommandEntry( entry.get(), flags, alwaysEnabled); } } } diff --git a/src/commands/CommandManager.h b/src/commands/CommandManager.h index 291909971..12707ab14 100644 --- a/src/commands/CommandManager.h +++ b/src/commands/CommandManager.h @@ -243,8 +243,8 @@ class AUDACITY_DLL_API CommandManager final // "permit" allows filtering even if the active window isn't a child of the project. // Lyrics and MixerTrackCluster classes use it. bool FilterKeyEvent(AudacityProject *project, const wxKeyEvent & evt, bool permit = false); - bool HandleMenuID(int id, CommandFlag flags, CommandMask mask); - bool HandleTextualCommand(const CommandID & Str, const CommandContext & context, CommandFlag flags, CommandMask mask); + bool HandleMenuID(int id, CommandFlag flags, bool alwaysEnabled); + bool HandleTextualCommand(const CommandID & Str, const CommandContext & context, CommandFlag flags, bool alwaysEnabled); // // Accessing @@ -343,7 +343,8 @@ private: // Executing commands // - bool HandleCommandEntry(const CommandListEntry * entry, CommandFlag flags, CommandMask mask, const wxEvent * evt = NULL); + bool HandleCommandEntry(const CommandListEntry * entry, CommandFlag flags, + bool alwaysEnabled, const wxEvent * evt = NULL); // // Modifying diff --git a/src/commands/ScreenshotCommand.cpp b/src/commands/ScreenshotCommand.cpp index 04207fff3..51aa901a8 100644 --- a/src/commands/ScreenshotCommand.cpp +++ b/src/commands/ScreenshotCommand.cpp @@ -454,7 +454,7 @@ void ScreenshotCommand::CapturePreferences( gPrefs->Flush(); CommandID Command{ wxT("Preferences") }; const CommandContext projectContext( *pProject ); - if( !commandManager.HandleTextualCommand( Command, projectContext, AlwaysEnabledFlag, AlwaysEnabledFlag ) ) + if( !commandManager.HandleTextualCommand( Command, projectContext, AlwaysEnabledFlag, true ) ) { // using GET in a log message for devs' eyes only wxLogDebug("Command %s not found", Command.GET() ); @@ -614,7 +614,7 @@ void ScreenshotCommand::CaptureCommands( SetIdleHandler( IdleHandler ); Str = Commands[i]; const CommandContext projectContext( *pProject ); - if( !manager.HandleTextualCommand( Str, projectContext, AlwaysEnabledFlag, AlwaysEnabledFlag ) ) + if( !manager.HandleTextualCommand( Str, projectContext, AlwaysEnabledFlag, true ) ) { wxLogDebug("Command %s not found", Str); } diff --git a/src/toolbars/EditToolBar.cpp b/src/toolbars/EditToolBar.cpp index 64d7ec325..098ee19e7 100644 --- a/src/toolbars/EditToolBar.cpp +++ b/src/toolbars/EditToolBar.cpp @@ -299,7 +299,7 @@ void EditToolBar::OnButton(wxCommandEvent &event) auto flags = MenuManager::Get(*p).GetUpdateFlags(); const CommandContext context( *p ); - cm.HandleTextualCommand(EditToolbarButtonList[id].commandName, context, flags, NoFlagsSpecified); + cm.HandleTextualCommand(EditToolbarButtonList[id].commandName, context, flags, false); } static RegisteredToolbarFactory factory{ EditBarID,