From 03f8efc0ab18970b7f13a97eb54e65156184e6d3 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 29 Jan 2019 16:02:34 -0500 Subject: [PATCH] CommandManager interacts with journal; simple journals can play... ... such as one whose only line is "CM,Exit", which can also be recorded. But no commands that pop up modal dialogs, or mouse interactions, can yet play back. --- src/commands/CommandManager.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/commands/CommandManager.cpp b/src/commands/CommandManager.cpp index ea6bf6cfd..341bbf378 100644 --- a/src/commands/CommandManager.cpp +++ b/src/commands/CommandManager.cpp @@ -92,6 +92,7 @@ CommandManager. It holds the callback for one command. #include #include +#include "../Journal.h" #include "../Menus.h" #include "../Project.h" @@ -1183,6 +1184,33 @@ bool CommandManager::FilterKeyEvent(AudacityProject *project, const wxKeyEvent & return false; } +namespace { + +constexpr auto JournalCode = wxT("CM"); // for CommandManager + +// Register a callback for the journal +Journal::RegisteredCommand sCommand{ JournalCode, +[]( const wxArrayString &fields ) +{ + // Expect JournalCode and the command name. + // To do, perhaps, is to include some parameters. + bool handled = false; + if ( fields.size() == 2 ) { + auto project = GetActiveProject(); + if (project) { + auto pManager = &CommandManager::Get( *project ); + auto flags = MenuManager::Get( *project ).GetUpdateFlags(); + const CommandContext context( *project ); + auto &command = fields[1]; + handled = + pManager->HandleTextualCommand( command, context, flags, false ); + } + } + return handled; +} +}; + +} /// HandleCommandEntry() takes a CommandListEntry and executes it /// returning true iff successful. If you pass any flags, @@ -1217,6 +1245,8 @@ bool CommandManager::HandleCommandEntry(AudacityProject &project, mNiceName = {}; } + Journal::Output({ JournalCode, entry->name.GET() }); + const CommandContext context{ project, evt, entry->index, entry->parameter }; auto &handler = entry->finder(project); (handler.*(entry->callback))(context);