From 371afa3ffaf9b238c490762514b65cd44ac62841 Mon Sep 17 00:00:00 2001 From: James Crook Date: Mon, 10 Feb 2020 15:55:39 +0000 Subject: [PATCH] Scripting Help Command now supports JSON, LISP, Brief. --- src/commands/GetInfoCommand.cpp | 1 - src/commands/HelpCommand.cpp | 51 ++++++++++++++++++++++++++++++++- src/commands/HelpCommand.h | 2 ++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/commands/GetInfoCommand.cpp b/src/commands/GetInfoCommand.cpp index 022e8d36c..41ff9e40a 100644 --- a/src/commands/GetInfoCommand.cpp +++ b/src/commands/GetInfoCommand.cpp @@ -36,7 +36,6 @@ This class now lists #include "../WaveTrack.h" #include "../LabelTrack.h" #include "../Envelope.h" -#include "CommandContext.h" #include "SelectCommand.h" #include "../ShuttleGui.h" diff --git a/src/commands/HelpCommand.cpp b/src/commands/HelpCommand.cpp index 61b2faf79..0616c2b63 100644 --- a/src/commands/HelpCommand.cpp +++ b/src/commands/HelpCommand.cpp @@ -20,6 +20,7 @@ #include "../Shuttle.h" #include "LoadCommands.h" #include "../ShuttleGui.h" +#include "CommandTargets.h" #include "CommandContext.h" #include "../effects/EffectManager.h" @@ -28,8 +29,28 @@ const ComponentInterfaceSymbol HelpCommand::Symbol namespace{ BuiltinCommandsModule::Registration< HelpCommand > reg; } +enum { + kJson, + kLisp, + kBrief, + nFormats +}; + +static const EnumValueSymbol kFormats[nFormats] = +{ + // These are acceptable dual purpose internal/visible names + + /* i18n-hint JavaScript Object Notation */ + { XO("JSON") }, + /* i18n-hint name of a computer programming language */ + { XO("LISP") }, + { XO("Brief") } +}; + + bool HelpCommand::DefineParams( ShuttleParams & S ){ S.Define( mCommandName, wxT("Command"), "Help" ); + S.DefineEnum( mFormat, wxT("Format"), 0, kFormats, nFormats ); return true; } @@ -40,11 +61,39 @@ void HelpCommand::PopulateOrExchange(ShuttleGui & S) S.StartMultiColumn(2, wxALIGN_CENTER); { S.TieTextBox(XO("Command:"),mCommandName); + S.TieChoice( XO("Format:"), + mFormat, Msgids( kFormats, nFormats )); } S.EndMultiColumn(); } -bool HelpCommand::Apply(const CommandContext & context){ +bool HelpCommand::Apply(const CommandContext &context) +{ + if( mFormat == kJson ) + return ApplyInner( context ); + + if( mFormat == kLisp ) + { + CommandContext LispyContext( + context.project, + std::make_unique( *context.pOutput.get() ) + ); + return ApplyInner( LispyContext ); + } + + if( mFormat == kBrief ) + { + CommandContext BriefContext( + context.project, + std::make_unique( *context.pOutput.get() ) + ); + return ApplyInner( BriefContext ); + } + + return false; +} + +bool HelpCommand::ApplyInner(const CommandContext & context){ EffectManager & em = EffectManager::Get(); PluginID ID = em.GetEffectByIdentifier( mCommandName ); if( ID.empty() ) diff --git a/src/commands/HelpCommand.h b/src/commands/HelpCommand.h index 376c20121..41d9020d6 100644 --- a/src/commands/HelpCommand.h +++ b/src/commands/HelpCommand.h @@ -27,6 +27,7 @@ class HelpCommand : public AudacityCommand { public: static const ComponentInterfaceSymbol Symbol; + int mFormat; // ComponentInterface overrides ComponentInterfaceSymbol GetSymbol() override {return Symbol;}; @@ -34,6 +35,7 @@ public: bool DefineParams( ShuttleParams & S ) override; void PopulateOrExchange(ShuttleGui & S) override; bool Apply(const CommandContext & context) override; + bool ApplyInner(const CommandContext & context); // AudacityCommand overrides wxString ManualPage() override {return wxT("Extra_Menu:_Scriptables_II#help");};