1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-20 14:20:06 +02:00

CommandManager.cpp does not depend on EffectManager...

... some code lifted into BatchCommands.cpp to realize this.

It also doesn't depend on PluginManager, but that is not important for breaking
cycles.
This commit is contained in:
Paul Licameli 2019-06-14 00:50:21 -04:00
parent c506536912
commit b84f5b66f0
6 changed files with 69 additions and 35 deletions

View File

@ -749,6 +749,41 @@ bool MacroCommands::ApplyEffectCommand(
return res; return res;
} }
bool MacroCommands::HandleTextualCommand( CommandManager &commandManager,
const CommandID & Str,
const CommandContext & context, CommandFlag flags, bool alwaysEnabled)
{
switch ( commandManager.HandleTextualCommand(
Str, context, flags, alwaysEnabled) ) {
case CommandManager::CommandSuccess:
return true;
case CommandManager::CommandFailure:
return false;
case CommandManager::CommandNotFound:
default:
break;
}
// Not one of the singleton commands.
// We could/should try all the list-style commands.
// instead we only try the effects.
PluginManager & pm = PluginManager::Get();
EffectManager & em = EffectManager::Get();
const PluginDescriptor *plug = pm.GetFirstPlugin(PluginTypeEffect);
while (plug)
{
if (em.GetCommandIdentifier(plug->GetID()) == Str)
{
return PluginActions::DoEffect(
plug->GetID(), context,
PluginActions::kConfigured);
}
plug = pm.GetNextPlugin(PluginTypeEffect);
}
return false;
}
bool MacroCommands::ApplyCommand( const wxString &friendlyCommand, bool MacroCommands::ApplyCommand( const wxString &friendlyCommand,
const CommandID & command, const wxString & params, const CommandID & command, const wxString & params,
CommandContext const * pContext) CommandContext const * pContext)
@ -778,7 +813,8 @@ bool MacroCommands::ApplyCommand( const wxString &friendlyCommand,
AudacityProject *project = GetActiveProject(); AudacityProject *project = GetActiveProject();
auto &manager = CommandManager::Get( *project ); auto &manager = CommandManager::Get( *project );
if( pContext ){ if( pContext ){
if( manager.HandleTextualCommand( command, *pContext, AlwaysEnabledFlag, true ) ) if( HandleTextualCommand(
manager, command, *pContext, AlwaysEnabledFlag, true ) )
return true; return true;
pContext->Status( wxString::Format( pContext->Status( wxString::Format(
_("Your batch command of %s was not recognized."), friendlyCommand )); _("Your batch command of %s was not recognized."), friendlyCommand ));
@ -787,7 +823,8 @@ bool MacroCommands::ApplyCommand( const wxString &friendlyCommand,
else else
{ {
const CommandContext context( *GetActiveProject() ); const CommandContext context( *GetActiveProject() );
if( manager.HandleTextualCommand( command, context, AlwaysEnabledFlag, true ) ) if( HandleTextualCommand(
manager, command, context, AlwaysEnabledFlag, true ) )
return true; return true;
} }

View File

@ -15,10 +15,12 @@
#include <wx/defs.h> #include <wx/defs.h>
#include "export/Export.h" #include "export/Export.h"
#include "commands/CommandFlag.h"
class wxArrayString; class wxArrayString;
class Effect; class Effect;
class CommandContext; class CommandContext;
class CommandManager;
class AudacityProject; class AudacityProject;
class wxArrayStringEx; class wxArrayStringEx;
@ -57,6 +59,9 @@ class MacroCommands final {
public: public:
bool ApplyMacro( const MacroCommandsCatalog &catalog, bool ApplyMacro( const MacroCommandsCatalog &catalog,
const wxString & filename = {}); const wxString & filename = {});
static bool HandleTextualCommand( CommandManager &commandManager,
const CommandID & Str,
const CommandContext & context, CommandFlag flags, bool alwaysEnabled);
bool ApplyCommand( const wxString &friendlyCommand, bool ApplyCommand( const wxString &friendlyCommand,
const CommandID & command, const wxString & params, const CommandID & command, const wxString & params,
CommandContext const * pContext=NULL ); CommandContext const * pContext=NULL );

View File

@ -96,9 +96,7 @@ CommandManager. It holds the callback for one command.
#include "../Menus.h" #include "../Menus.h"
#include "../PluginManager.h"
#include "../Project.h" #include "../Project.h"
#include "../effects/EffectManager.h"
#include "../widgets/LinkingHtmlWindow.h" #include "../widgets/LinkingHtmlWindow.h"
#include "../widgets/AudacityMessageBox.h" #include "../widgets/AudacityMessageBox.h"
#include "../widgets/HelpSystem.h" #include "../widgets/HelpSystem.h"
@ -1238,10 +1236,12 @@ bool CommandManager::HandleMenuID(int id, CommandFlag flags, bool alwaysEnabled)
/// HandleTextualCommand() allows us a limitted version of script/batch /// HandleTextualCommand() allows us a limitted version of script/batch
/// behavior, since we can get from a string command name to the actual /// behavior, since we can get from a string command name to the actual
/// code to run. /// code to run.
bool CommandManager::HandleTextualCommand(const CommandID & Str, const CommandContext & context, CommandFlag flags, bool alwaysEnabled) CommandManager::TextualCommandResult
CommandManager::HandleTextualCommand(const CommandID & Str,
const CommandContext & context, CommandFlag flags, bool alwaysEnabled)
{ {
if( Str.empty() ) if( Str.empty() )
return false; return CommandFailure;
// Linear search for now... // Linear search for now...
for (const auto &entry : mCommandList) for (const auto &entry : mCommandList)
{ {
@ -1254,7 +1254,8 @@ bool CommandManager::HandleTextualCommand(const CommandID & Str, const CommandCo
// sub-menu name) // sub-menu name)
Str == entry->labelPrefix ) Str == entry->labelPrefix )
{ {
return HandleCommandEntry( entry.get(), flags, alwaysEnabled); return HandleCommandEntry( entry.get(), flags, alwaysEnabled)
? CommandSuccess : CommandFailure;
} }
} }
else else
@ -1262,34 +1263,12 @@ bool CommandManager::HandleTextualCommand(const CommandID & Str, const CommandCo
// Handle multis too... // Handle multis too...
if( Str == entry->name ) if( Str == entry->name )
{ {
return HandleCommandEntry( entry.get(), flags, alwaysEnabled); return HandleCommandEntry( entry.get(), flags, alwaysEnabled)
? CommandSuccess : CommandFailure;
} }
} }
} }
// Not one of the singleton commands. return CommandNotFound;
// We could/should try all the list-style commands.
// instead we only try the effects.
AudacityProject * proj = GetActiveProject();
if( !proj )
{
return false;
}
PluginManager & pm = PluginManager::Get();
EffectManager & em = EffectManager::Get();
const PluginDescriptor *plug = pm.GetFirstPlugin(PluginTypeEffect);
while (plug)
{
if (em.GetCommandIdentifier(plug->GetID()) == Str)
{
return PluginActions::DoEffect(
plug->GetID(), context,
PluginActions::kConfigured);
}
plug = pm.GetNextPlugin(PluginTypeEffect);
}
return false;
} }
void CommandManager::GetCategories(wxArrayString &cats) void CommandManager::GetCategories(wxArrayString &cats)

View File

@ -244,7 +244,16 @@ class AUDACITY_DLL_API CommandManager final
// Lyrics and MixerTrackCluster classes use it. // Lyrics and MixerTrackCluster classes use it.
bool FilterKeyEvent(AudacityProject *project, const wxKeyEvent & evt, bool permit = false); bool FilterKeyEvent(AudacityProject *project, const wxKeyEvent & evt, bool permit = false);
bool HandleMenuID(int id, CommandFlag flags, bool alwaysEnabled); bool HandleMenuID(int id, CommandFlag flags, bool alwaysEnabled);
bool HandleTextualCommand(const CommandID & Str, const CommandContext & context, CommandFlag flags, bool alwaysEnabled);
enum TextualCommandResult {
CommandFailure,
CommandSuccess,
CommandNotFound
};
TextualCommandResult
HandleTextualCommand(const CommandID & Str,
const CommandContext & context, CommandFlag flags, bool alwaysEnabled);
// //
// Accessing // Accessing

View File

@ -32,6 +32,7 @@ small calculations of rectangles.
#include <wx/valgen.h> #include <wx/valgen.h>
#include "../AdornedRulerPanel.h" #include "../AdornedRulerPanel.h"
#include "../BatchCommands.h"
#include "../TrackPanel.h" #include "../TrackPanel.h"
#include "../effects/Effect.h" #include "../effects/Effect.h"
#include "../toolbars/ToolManager.h" #include "../toolbars/ToolManager.h"
@ -454,7 +455,8 @@ void ScreenshotCommand::CapturePreferences(
gPrefs->Flush(); gPrefs->Flush();
CommandID Command{ wxT("Preferences") }; CommandID Command{ wxT("Preferences") };
const CommandContext projectContext( *pProject ); const CommandContext projectContext( *pProject );
if( !commandManager.HandleTextualCommand( Command, projectContext, AlwaysEnabledFlag, true ) ) if( !MacroCommands::HandleTextualCommand( commandManager,
Command, projectContext, AlwaysEnabledFlag, true ) )
{ {
// using GET in a log message for devs' eyes only // using GET in a log message for devs' eyes only
wxLogDebug("Command %s not found", Command.GET() ); wxLogDebug("Command %s not found", Command.GET() );

View File

@ -49,6 +49,7 @@
#endif #endif
#include "../AllThemeResources.h" #include "../AllThemeResources.h"
#include "../BatchCommands.h"
#include "../ImageManipulation.h" #include "../ImageManipulation.h"
#include "../Menus.h" #include "../Menus.h"
#include "../Prefs.h" #include "../Prefs.h"
@ -299,7 +300,8 @@ void EditToolBar::OnButton(wxCommandEvent &event)
auto flags = MenuManager::Get(*p).GetUpdateFlags(); auto flags = MenuManager::Get(*p).GetUpdateFlags();
const CommandContext context( *p ); const CommandContext context( *p );
cm.HandleTextualCommand(EditToolbarButtonList[id].commandName, context, flags, false); MacroCommands::HandleTextualCommand( cm,
EditToolbarButtonList[id].commandName, context, flags, false);
} }
static RegisteredToolbarFactory factory{ EditBarID, static RegisteredToolbarFactory factory{ EditBarID,