mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-15 23:59:37 +02:00
Fix displays of strings for macro dialogs...
... Internationalize some prompts; command names are not yet internationalized everywhere, but will display the "friendly" form with spaces when mentioned in message boxes
This commit is contained in:
commit
bf0c079f28
@ -62,6 +62,7 @@ MacroCommandDialog::MacroCommandDialog(wxWindow * parent, wxWindowID id):
|
||||
wxDialogWrapper(parent, id, _("Select Command"),
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxCAPTION | wxRESIZE_BORDER)
|
||||
, mCatalog( GetActiveProject() )
|
||||
{
|
||||
SetLabel(_("Select Command")); // Provide visual label
|
||||
SetName(_("Select Command")); // Provide audible label
|
||||
@ -123,12 +124,11 @@ void MacroCommandDialog::PopulateOrExchange(ShuttleGui &S)
|
||||
|
||||
void MacroCommandDialog::PopulateCommandList()
|
||||
{
|
||||
mCommandNames = MacroCommands::GetAllCommands();
|
||||
|
||||
mChoices->DeleteAllItems();
|
||||
for (size_t ii = 0, size = mCommandNames.size(); ii < size; ++ii)
|
||||
long ii = 0;
|
||||
for ( const auto &entry : mCatalog )
|
||||
// insert the user-facing string
|
||||
mChoices->InsertItem( ii, std::get<0>( mCommandNames[ii] ) );
|
||||
mChoices->InsertItem( ii++, entry.friendly /* .Translation() */ );
|
||||
}
|
||||
|
||||
void MacroCommandDialog::ValidateChoices()
|
||||
@ -159,21 +159,21 @@ void MacroCommandDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
|
||||
|
||||
void MacroCommandDialog::OnItemSelected(wxListEvent &event)
|
||||
{
|
||||
const auto &command = mCommandNames[ event.GetIndex() ];
|
||||
const auto &command = mCatalog[ event.GetIndex() ];
|
||||
|
||||
EffectManager & em = EffectManager::Get();
|
||||
PluginID ID = em.GetEffectByIdentifier( std::get<1>( command ));
|
||||
PluginID ID = em.GetEffectByIdentifier( command.internal );
|
||||
|
||||
// If ID is empty, then the effect wasn't found, in which case, the user must have
|
||||
// selected one of the "special" commands.
|
||||
mEditParams->Enable(!ID.IsEmpty());
|
||||
mUsePreset->Enable(em.HasPresets(ID));
|
||||
|
||||
if (std::get<0>( command ) == mCommand->GetValue())
|
||||
if ( command.friendly == mCommand->GetValue() )
|
||||
return;
|
||||
|
||||
mCommand->SetValue(std::get<0> (command));
|
||||
mInternalCommandName = std::get<1>( command );
|
||||
mCommand->SetValue(command.friendly);
|
||||
mInternalCommandName = command.internal;
|
||||
|
||||
wxString params = MacroCommands::GetCurrentParamsFor(mInternalCommandName);
|
||||
if (params.IsEmpty())
|
||||
@ -183,7 +183,7 @@ void MacroCommandDialog::OnItemSelected(wxListEvent &event)
|
||||
|
||||
// Cryptic command and category.
|
||||
// Later we can put help information there, perhaps.
|
||||
mDetails->SetValue( mInternalCommandName + "\r\n" + std::get<2>(command) );
|
||||
mDetails->SetValue( mInternalCommandName + "\r\n" + command.category );
|
||||
mParameters->SetValue(params);
|
||||
}
|
||||
|
||||
@ -211,19 +211,20 @@ void MacroCommandDialog::OnUsePreset(wxCommandEvent & WXUNUSED(event))
|
||||
|
||||
void MacroCommandDialog::SetCommandAndParams(const wxString &Command, const wxString &Params)
|
||||
{
|
||||
auto item = make_iterator_range(mCommandNames).index_if(
|
||||
[&](const CommandName &name){ return Command == std::get<1>( name); }
|
||||
);
|
||||
auto iter = mCatalog.ByCommandId( Command );
|
||||
|
||||
mParameters->SetValue( Params );
|
||||
|
||||
mInternalCommandName = Command;
|
||||
if (item < 0)
|
||||
if (iter == mCatalog.end())
|
||||
// Expose an internal name to the user in default of any friendly name
|
||||
// -- AVOID THIS!
|
||||
mCommand->SetValue( Command );
|
||||
else {
|
||||
mCommand->SetValue( std::get<0>( mCommandNames[item]) );
|
||||
mDetails->SetValue( std::get<1>(mCommandNames[item]) + "\r\n" + std::get<2>(mCommandNames[item]) );
|
||||
mChoices->SetItemState(item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
|
||||
mCommand->SetValue( iter->friendly /* .Translation() */ );
|
||||
mDetails->SetValue( iter->internal + "\r\n" + iter->category );
|
||||
mChoices->SetItemState(iter - mCatalog.begin(),
|
||||
wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
|
||||
|
||||
EffectManager & em = EffectManager::Get();
|
||||
PluginID ID = em.GetEffectByIdentifier(Command);
|
||||
|
@ -12,7 +12,6 @@
|
||||
#ifndef __AUDACITY_MACRO_COMMAND_DIALOG__
|
||||
#define __AUDACITY_MACRO_COMMAND_DIALOG__
|
||||
|
||||
#include "MemoryX.h"
|
||||
#include <wx/defs.h>
|
||||
#include <wx/string.h>
|
||||
|
||||
@ -26,6 +25,8 @@
|
||||
#include <wx/menuitem.h>
|
||||
#include <wx/checklst.h>
|
||||
|
||||
#include "BatchCommands.h"
|
||||
|
||||
class wxWindow;
|
||||
class wxCheckBox;
|
||||
class wxChoice;
|
||||
@ -70,9 +71,7 @@ class MacroCommandDialog final : public wxDialogWrapper {
|
||||
|
||||
wxString mInternalCommandName;
|
||||
|
||||
using CommandName = std::tuple<wxString, wxString,wxString>;
|
||||
using CommandNameVector = std::vector<CommandName>;
|
||||
CommandNameVector mCommandNames;
|
||||
const MacroCommandsCatalog mCatalog;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
@ -274,19 +274,19 @@ bool MacroCommands::RenameMacro(const wxString & oldchain, const wxString & newc
|
||||
}
|
||||
|
||||
// Gets all commands that are valid for this mode.
|
||||
auto MacroCommands::GetAllCommands() -> CommandNameVector
|
||||
MacroCommandsCatalog::MacroCommandsCatalog( const AudacityProject *project )
|
||||
{
|
||||
CommandNameVector commands;
|
||||
|
||||
AudacityProject *project = GetActiveProject();
|
||||
if (!project)
|
||||
return commands;
|
||||
return;
|
||||
|
||||
// CLEANSPEECH remnant
|
||||
Entries commands;
|
||||
for( const auto &command : SpecialCommands )
|
||||
commands.push_back(
|
||||
CommandName( command.first, command.second, _("Special Command") )
|
||||
);
|
||||
commands.push_back( {
|
||||
command.first /* .Translation() */,
|
||||
command.second,
|
||||
_("Special Command")
|
||||
} );
|
||||
|
||||
// end CLEANSPEECH remnant
|
||||
|
||||
@ -298,72 +298,103 @@ auto MacroCommands::GetAllCommands() -> CommandNameVector
|
||||
{
|
||||
auto command = em.GetCommandIdentifier(plug->GetID());
|
||||
if (!command.IsEmpty())
|
||||
commands.push_back(
|
||||
CommandName(
|
||||
plug->GetUntranslatedName(), // plug->GetTranslatedName(),
|
||||
command,
|
||||
plug->GetPluginType() == PluginTypeEffect ?
|
||||
_("Effect") : _("Menu Command (With Parameters)")
|
||||
)
|
||||
);
|
||||
commands.push_back( {
|
||||
plug->GetUntranslatedName(), // plug->GetTranslatedName(),
|
||||
command,
|
||||
plug->GetPluginType() == PluginTypeEffect ?
|
||||
_("Effect") : _("Menu Command (With Parameters)")
|
||||
} );
|
||||
plug = pm.GetNextPlugin(PluginTypeEffect|PluginTypeAudacityCommand);
|
||||
}
|
||||
}
|
||||
|
||||
CommandManager * mManager = project->GetCommandManager();
|
||||
auto mManager = project->GetCommandManager();
|
||||
wxArrayString mLabels;
|
||||
wxArrayString mNames;
|
||||
mLabels.Clear();
|
||||
mNames.Clear();
|
||||
mManager->GetAllCommandLabels(mLabels, false);
|
||||
mManager->GetAllCommandNames(mNames, false);
|
||||
|
||||
const bool english = wxGetLocale()->GetCanonicalName().StartsWith(wxT("en"));
|
||||
|
||||
for(size_t i=0; i<mNames.GetCount(); i++) {
|
||||
wxString label = mLabels[i];
|
||||
if( !label.Contains( "..." ) ){
|
||||
label.Replace( "&", "" );
|
||||
wxString squashed = label;
|
||||
squashed.Replace( " ", "" );
|
||||
bool suffix;
|
||||
if (!english)
|
||||
suffix = true;
|
||||
else {
|
||||
// We'll disambiguate if the squashed name is short and shorter than the internal name.
|
||||
// Otherwise not.
|
||||
// This means we won't have repetitive items like "Cut (Cut)"
|
||||
// But we will show important disambiguation like "All (SelectAll)" and "By Date (SortByDate)"
|
||||
// Disambiguation is no longer essential as the details box will show it.
|
||||
// PRL: I think this reasoning applies only when locale is English.
|
||||
// For other locales, show the (CamelCaseCodeName) always. Or, never?
|
||||
wxString squashed = label;
|
||||
squashed.Replace( " ", "" );
|
||||
|
||||
// We'll disambiguate if the squashed name is short and shorter than the internal name.
|
||||
// Otherwise not.
|
||||
// This means we won't have repetitive items like "Cut (Cut)"
|
||||
// But we will show important disambiguation like "All (SelectAll)" and "By Date (SortByDate)"
|
||||
// Disambiguation is no longer essential as the details box will show it.
|
||||
if( squashed.Length() < wxMin( 18, mNames[i].Length()) )
|
||||
suffix = squashed.Length() < wxMin( 18, mNames[i].Length());
|
||||
}
|
||||
|
||||
if( suffix )
|
||||
label = label + " (" + mNames[i] + ")";
|
||||
|
||||
commands.push_back(
|
||||
CommandName(
|
||||
label, // User readable name
|
||||
commands.push_back(
|
||||
{
|
||||
label, // User readable name
|
||||
mNames[i], // Internal name.
|
||||
_("Menu Command (No Parameters)")
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort commands by their user-visible names.
|
||||
// PRL: What should happen if first members of pairs are not unique?
|
||||
// Sort stably?
|
||||
std::sort(
|
||||
commands.begin(), commands.end(),
|
||||
[](const CommandName &a, const CommandName &b)
|
||||
{ return std::get<0>(a) < std::get<0>(b); }
|
||||
);
|
||||
// PRL: What exactly should happen if first members of pairs are not unique?
|
||||
// I'm not sure, but at least I can sort stably for a better defined result,
|
||||
// keeping specials before effects and menu items, and lastly commands.
|
||||
auto less =
|
||||
[](const Entry &a, const Entry &b) { return a.friendly < b.friendly; };
|
||||
std::stable_sort(commands.begin(), commands.end(), less);
|
||||
|
||||
// JKC: Gave up on trying to use std::unique on this.
|
||||
CommandNameVector uniqueCommands;
|
||||
unsigned size = commands.size();
|
||||
wxString oldName = "";
|
||||
for( unsigned i = 0; i < size; ++i )
|
||||
{
|
||||
if( std::get<0>( commands[i] ) != oldName )
|
||||
uniqueCommands.push_back( commands[i] );
|
||||
oldName = std::get<0>( commands[i] );
|
||||
}
|
||||
return uniqueCommands;
|
||||
// Now uniquify by friendly name
|
||||
auto equal =
|
||||
[](const Entry &a, const Entry &b) { return a.friendly == b.friendly; };
|
||||
std::unique_copy(
|
||||
commands.begin(), commands.end(), std::back_inserter(mCommands), equal);
|
||||
}
|
||||
|
||||
// binary search
|
||||
auto MacroCommandsCatalog::ByFriendlyName( const wxString &friendlyName ) const
|
||||
-> Entries::const_iterator
|
||||
{
|
||||
const auto less = [&](const Entry &entryA, const Entry &entryB)
|
||||
{ return entryA.friendly < entryB.friendly; };
|
||||
auto range = std::equal_range(
|
||||
begin(), end(), Entry{ friendlyName }, less);
|
||||
if (range.first != range.second) {
|
||||
wxASSERT_MSG( range.first + 1 == range.second,
|
||||
"Non-unique user-visible command name" );
|
||||
return range.first;
|
||||
}
|
||||
else
|
||||
return end();
|
||||
}
|
||||
|
||||
// linear search
|
||||
auto MacroCommandsCatalog::ByCommandId( const wxString &commandId ) const
|
||||
-> Entries::const_iterator
|
||||
{
|
||||
// Maybe this too should have a uniqueness check?
|
||||
return std::find_if( begin(), end(),
|
||||
[&](const Entry &entry){ return entry.internal == commandId; });
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString MacroCommands::GetCurrentParamsFor(const wxString & command)
|
||||
{
|
||||
const PluginID & ID = EffectManager::Get().GetEffectByIdentifier(command);
|
||||
@ -564,9 +595,11 @@ bool MacroCommands::WriteMp3File( const wxString & Name, int bitrate )
|
||||
// and think again.
|
||||
// ======= IMPORTANT ========
|
||||
// CLEANSPEECH remnant
|
||||
bool MacroCommands::ApplySpecialCommand(int WXUNUSED(iCommand), const wxString & command,const wxString & params)
|
||||
bool MacroCommands::ApplySpecialCommand(
|
||||
int WXUNUSED(iCommand), const wxString &friendlyCommand,
|
||||
const wxString & command, const wxString & params)
|
||||
{
|
||||
if (ReportAndSkip(command, params))
|
||||
if (ReportAndSkip(friendlyCommand, params))
|
||||
return true;
|
||||
|
||||
AudacityProject *project = GetActiveProject();
|
||||
@ -643,15 +676,19 @@ bool MacroCommands::ApplySpecialCommand(int WXUNUSED(iCommand), const wxString &
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
AudacityMessageBox(wxString::Format(_("Command %s not implemented yet"),command));
|
||||
AudacityMessageBox(
|
||||
wxString::Format(_("Command %s not implemented yet"), friendlyCommand));
|
||||
return false;
|
||||
}
|
||||
// end CLEANSPEECH remnant
|
||||
|
||||
bool MacroCommands::ApplyEffectCommand(const PluginID & ID, const wxString & command, const wxString & params, const CommandContext & Context)
|
||||
bool MacroCommands::ApplyEffectCommand(
|
||||
const PluginID & ID, const wxString &friendlyCommand,
|
||||
const wxString & command, const wxString & params,
|
||||
const CommandContext & Context)
|
||||
{
|
||||
//Possibly end processing here, if in batch-debug
|
||||
if( ReportAndSkip(command, params))
|
||||
if( ReportAndSkip(friendlyCommand, params))
|
||||
return true;
|
||||
|
||||
const PluginDescriptor *plug = PluginManager::Get().GetPlugin(ID);
|
||||
@ -692,7 +729,9 @@ bool MacroCommands::ApplyEffectCommand(const PluginID & ID, const wxString & com
|
||||
return res;
|
||||
}
|
||||
|
||||
bool MacroCommands::ApplyCommand(const wxString & command, const wxString & params, CommandContext const * pContext)
|
||||
bool MacroCommands::ApplyCommand( const wxString &friendlyCommand,
|
||||
const wxString & command, const wxString & params,
|
||||
CommandContext const * pContext)
|
||||
{
|
||||
|
||||
unsigned int i;
|
||||
@ -700,7 +739,7 @@ bool MacroCommands::ApplyCommand(const wxString & command, const wxString & para
|
||||
// CLEANSPEECH remnant
|
||||
for( i = 0; i < sizeof(SpecialCommands)/sizeof(*SpecialCommands); ++i ) {
|
||||
if( command.IsSameAs( SpecialCommands[i].second, false) )
|
||||
return ApplySpecialCommand( i, command, params );
|
||||
return ApplySpecialCommand( i, friendlyCommand, command, params );
|
||||
}
|
||||
// end CLEANSPEECH remnant
|
||||
|
||||
@ -709,9 +748,11 @@ bool MacroCommands::ApplyCommand(const wxString & command, const wxString & para
|
||||
if (!ID.empty())
|
||||
{
|
||||
if( pContext )
|
||||
return ApplyEffectCommand(ID, command, params, *pContext);
|
||||
return ApplyEffectCommand(
|
||||
ID, friendlyCommand, command, params, *pContext);
|
||||
const CommandContext context( *GetActiveProject() );
|
||||
return ApplyEffectCommand(ID, command, params, context);
|
||||
return ApplyEffectCommand(
|
||||
ID, friendlyCommand, command, params, context);
|
||||
}
|
||||
|
||||
AudacityProject *project = GetActiveProject();
|
||||
@ -720,7 +761,7 @@ bool MacroCommands::ApplyCommand(const wxString & command, const wxString & para
|
||||
if( pManager->HandleTextualCommand( command, *pContext, AlwaysEnabledFlag, AlwaysEnabledFlag ) )
|
||||
return true;
|
||||
pContext->Status( wxString::Format(
|
||||
_("Your batch command of %s was not recognized."), command ));
|
||||
_("Your batch command of %s was not recognized."), friendlyCommand ));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@ -732,12 +773,13 @@ bool MacroCommands::ApplyCommand(const wxString & command, const wxString & para
|
||||
|
||||
AudacityMessageBox(
|
||||
wxString::Format(
|
||||
_("Your batch command of %s was not recognized."), command ));
|
||||
_("Your batch command of %s was not recognized."), friendlyCommand ));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MacroCommands::ApplyCommandInBatchMode(const wxString & command, const wxString ¶ms)
|
||||
bool MacroCommands::ApplyCommandInBatchMode( const wxString &friendlyCommand,
|
||||
const wxString & command, const wxString ¶ms)
|
||||
{
|
||||
AudacityProject *project = GetActiveProject();
|
||||
|
||||
@ -748,14 +790,15 @@ bool MacroCommands::ApplyCommandInBatchMode(const wxString & command, const wxSt
|
||||
project->SetShowId3Dialog(prevShowMode);
|
||||
} );
|
||||
|
||||
return ApplyCommand( command, params );
|
||||
return ApplyCommand( friendlyCommand, command, params );
|
||||
}
|
||||
|
||||
static int MacroReentryCount = 0;
|
||||
// ApplyMacro returns true on success, false otherwise.
|
||||
// Any error reporting to the user in setting up the chain
|
||||
// has already been done.
|
||||
bool MacroCommands::ApplyMacro(const wxString & filename)
|
||||
bool MacroCommands::ApplyMacro(
|
||||
const MacroCommandsCatalog &catalog, const wxString & filename)
|
||||
{
|
||||
// Check for reentrant ApplyMacro commands.
|
||||
// We'll allow 1 level of reentry, but not more.
|
||||
@ -783,12 +826,17 @@ bool MacroCommands::ApplyMacro(const wxString & filename)
|
||||
mAbort = false;
|
||||
|
||||
size_t i = 0;
|
||||
for (; i < mCommandMacro.GetCount(); i++) {
|
||||
if (!ApplyCommandInBatchMode(mCommandMacro[i], mParamsMacro[i]) || mAbort)
|
||||
for (; i < mCommandMacro.size(); i++) {
|
||||
const auto &command = mCommandMacro[i];
|
||||
auto iter = catalog.ByCommandId(command);
|
||||
auto friendly = (iter == catalog.end())
|
||||
? command // Expose internal name to user, in default of a better one!
|
||||
: iter->friendly;
|
||||
if (!ApplyCommandInBatchMode(friendly, command, mParamsMacro[i]) || mAbort)
|
||||
break;
|
||||
}
|
||||
|
||||
res = (i == mCommandMacro.GetCount());
|
||||
res = (i == mCommandMacro.size());
|
||||
if (!res)
|
||||
return false;
|
||||
|
||||
@ -856,7 +904,8 @@ void MacroCommands::ResetMacro()
|
||||
|
||||
// ReportAndSkip() is a diagnostic function that avoids actually
|
||||
// applying the requested effect if in batch-debug mode.
|
||||
bool MacroCommands::ReportAndSkip(const wxString & command, const wxString & params)
|
||||
bool MacroCommands::ReportAndSkip(
|
||||
const wxString & friendlyCommand, const wxString & params)
|
||||
{
|
||||
int bDebug;
|
||||
gPrefs->Read(wxT("/Batch/Debug"), &bDebug, false);
|
||||
@ -866,12 +915,12 @@ bool MacroCommands::ReportAndSkip(const wxString & command, const wxString & par
|
||||
//TODO: Add a cancel button to these, and add the logic so that we can abort.
|
||||
if( params != wxT("") )
|
||||
{
|
||||
AudacityMessageBox( wxString::Format(_("Apply %s with parameter(s)\n\n%s"),command, params),
|
||||
AudacityMessageBox( wxString::Format(_("Apply %s with parameter(s)\n\n%s"),friendlyCommand, params),
|
||||
_("Test Mode"));
|
||||
}
|
||||
else
|
||||
{
|
||||
AudacityMessageBox( wxString::Format(_("Apply %s"),command),
|
||||
AudacityMessageBox( wxString::Format(_("Apply %s"), friendlyCommand),
|
||||
_("Test Mode"));
|
||||
}
|
||||
return true;
|
||||
|
@ -12,7 +12,6 @@
|
||||
#ifndef __AUDACITY_BATCH_COMMANDS_DIALOG__
|
||||
#define __AUDACITY_BATCH_COMMANDS_DIALOG__
|
||||
|
||||
#include "MemoryX.h"
|
||||
#include <wx/defs.h>
|
||||
#include <wx/string.h>
|
||||
|
||||
@ -20,18 +19,57 @@
|
||||
|
||||
class Effect;
|
||||
class CommandContext;
|
||||
class AudacityProject;
|
||||
|
||||
class MacroCommandsCatalog {
|
||||
public:
|
||||
// A triple of user-visible name, internal string identifier and type/help string.
|
||||
struct Entry {
|
||||
wxString friendly;
|
||||
wxString internal;
|
||||
wxString category;
|
||||
};
|
||||
using Entries = std::vector<Entry>;
|
||||
|
||||
MacroCommandsCatalog( const AudacityProject *project );
|
||||
|
||||
// binary search
|
||||
Entries::const_iterator ByFriendlyName( const wxString &friendlyName ) const;
|
||||
// linear search
|
||||
Entries::const_iterator ByCommandId( const wxString &commandId ) const;
|
||||
|
||||
// Lookup by position as sorted by friendly name
|
||||
const Entry &operator[] ( size_t index ) const { return mCommands[index]; }
|
||||
|
||||
Entries::const_iterator begin() const { return mCommands.begin(); }
|
||||
Entries::const_iterator end() const { return mCommands.end(); }
|
||||
|
||||
private:
|
||||
// Sorted by friendly name
|
||||
Entries mCommands;
|
||||
};
|
||||
|
||||
// Stores information for one chain
|
||||
class MacroCommands final {
|
||||
public:
|
||||
// constructors and destructors
|
||||
MacroCommands();
|
||||
public:
|
||||
bool ApplyMacro(const wxString & filename = wxT(""));
|
||||
bool ApplyCommand( const wxString & command, const wxString & params, CommandContext const * pContext=NULL );
|
||||
bool ApplyCommandInBatchMode(const wxString & command, const wxString ¶ms);
|
||||
bool ApplySpecialCommand(int iCommand, const wxString & command,const wxString & params);
|
||||
bool ApplyEffectCommand(const PluginID & ID, const wxString & command, const wxString & params, const CommandContext & Context);
|
||||
bool ReportAndSkip( const wxString & command, const wxString & params );
|
||||
bool ApplyMacro( const MacroCommandsCatalog &catalog,
|
||||
const wxString & filename = wxT(""));
|
||||
bool ApplyCommand( const wxString &friendlyCommand,
|
||||
const wxString & command, const wxString & params,
|
||||
CommandContext const * pContext=NULL );
|
||||
bool ApplyCommandInBatchMode( const wxString &friendlyCommand,
|
||||
const wxString & command, const wxString ¶ms);
|
||||
bool ApplySpecialCommand(
|
||||
int iCommand, const wxString &friendlyCommand,
|
||||
const wxString & command, const wxString & params);
|
||||
bool ApplyEffectCommand(
|
||||
const PluginID & ID, const wxString &friendlyCommand,
|
||||
const wxString & command,
|
||||
const wxString & params, const CommandContext & Context);
|
||||
bool ReportAndSkip( const wxString & friendlyCommand, const wxString & params );
|
||||
void AbortBatch();
|
||||
|
||||
// Utility functions for the special commands.
|
||||
@ -44,12 +82,6 @@ class MacroCommands final {
|
||||
static wxArrayString GetNames();
|
||||
static wxArrayString GetNamesOfDefaultMacros();
|
||||
|
||||
// A triple of user-visible name, internal string identifier and type/help string.
|
||||
using CommandName = std::tuple<wxString, wxString, wxString>;
|
||||
using CommandNameVector = std::vector<CommandName>;
|
||||
// Result is sorted by user-visible name
|
||||
static CommandNameVector GetAllCommands();
|
||||
|
||||
static wxString GetCurrentParamsFor(const wxString & command);
|
||||
static wxString PromptForParamsFor(const wxString & command, const wxString & params, wxWindow *parent);
|
||||
static wxString PromptForPresetFor(const wxString & command, const wxString & params, wxWindow *parent);
|
||||
|
@ -73,6 +73,7 @@ ApplyMacroDialog::ApplyMacroDialog(wxWindow * parent, bool bInherited):
|
||||
wxDialogWrapper(parent, wxID_ANY, _("Apply Macro"),
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||
, mCatalog( GetActiveProject() )
|
||||
{
|
||||
//AudacityProject * p = GetActiveProject();
|
||||
mAbort = false;
|
||||
@ -269,7 +270,7 @@ void ApplyMacroDialog::ApplyMacroToProject( int iMacro, bool bHasGui )
|
||||
{
|
||||
wxWindowDisabler wd(&activityWin);
|
||||
success = GuardedCall< bool >(
|
||||
[this]{ return mMacroCommands.ApplyMacro(); } );
|
||||
[this]{ return mMacroCommands.ApplyMacro(mCatalog); } );
|
||||
}
|
||||
|
||||
if( !bHasGui )
|
||||
@ -436,7 +437,7 @@ void ApplyMacroDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event))
|
||||
project->Import(files[i]);
|
||||
project->ZoomAfterImport(nullptr);
|
||||
project->OnSelectAll(*project);
|
||||
if (!mMacroCommands.ApplyMacro())
|
||||
if (!mMacroCommands.ApplyMacro(mCatalog))
|
||||
return false;
|
||||
|
||||
if (!activityWin.IsShown() || mAbort)
|
||||
@ -547,8 +548,6 @@ MacrosWindow::~MacrosWindow()
|
||||
/// Creates the dialog and its contents.
|
||||
void MacrosWindow::Populate()
|
||||
{
|
||||
mCommandNames = MacroCommands::GetAllCommands();
|
||||
|
||||
//------------------------- Main section --------------------
|
||||
ShuttleGui S(this, eIsCreating);
|
||||
PopulateOrExchange(S);
|
||||
@ -634,7 +633,7 @@ void MacrosWindow::PopulateOrExchange(ShuttleGui & S)
|
||||
|
||||
S.StartVerticalLay(wxALIGN_TOP, 0);
|
||||
{
|
||||
S.AddPrompt( "Command" );
|
||||
S.AddPrompt( _("Command") );
|
||||
S.Id(InsertButtonID).AddButton(_("&Insert"), wxALIGN_LEFT);
|
||||
S.Id(EditButtonID).AddButton(_("&Edit..."), wxALIGN_LEFT);
|
||||
S.Id(DeleteButtonID).AddButton(_("De&lete"), wxALIGN_LEFT);
|
||||
@ -643,7 +642,7 @@ void MacrosWindow::PopulateOrExchange(ShuttleGui & S)
|
||||
mDefaults = S.Id(DefaultsButtonID).AddButton(_("De&faults"));
|
||||
|
||||
S.AddSpace( 30 );
|
||||
S.AddPrompt( "Macro" );
|
||||
S.AddPrompt( _("Macro") );
|
||||
S.Id(AddButtonID).AddButton(_("&New"));
|
||||
mRemove = S.Id(RemoveButtonID).AddButton(_("Remo&ve"));
|
||||
mRename = S.Id(RenameButtonID).AddButton(_("&Rename..."));
|
||||
@ -690,14 +689,13 @@ void MacrosWindow::PopulateList()
|
||||
/// Add one item into mList
|
||||
void MacrosWindow::AddItem(const wxString &Action, const wxString &Params)
|
||||
{
|
||||
// Translate internal command name to a friendly form
|
||||
auto item = make_iterator_range(mCommandNames).index_if(
|
||||
[&](const CommandName &name){ return Action == std::get<1>(name); }
|
||||
);
|
||||
auto friendlyName = item >= 0
|
||||
? // wxGetTranslation
|
||||
std::get<0>( mCommandNames[item] )
|
||||
: Action;
|
||||
auto entry = mCatalog.ByCommandId(Action);
|
||||
auto friendlyName = entry != mCatalog.end()
|
||||
? entry->friendly /* .Translation() */
|
||||
:
|
||||
// Expose an internal name to the user in default of any friendly name
|
||||
// -- AVOID THIS!
|
||||
Action;
|
||||
|
||||
int i = mList->GetItemCount();
|
||||
|
||||
|
@ -74,6 +74,9 @@ class ApplyMacroDialog : public wxDialogWrapper {
|
||||
bool mbExpanded;
|
||||
wxString mActiveMacro;
|
||||
|
||||
protected:
|
||||
const MacroCommandsCatalog mCatalog;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
@ -142,10 +145,6 @@ private:
|
||||
int mSelectedCommand;
|
||||
bool mChanged;
|
||||
|
||||
using CommandName = std::tuple<wxString, wxString,wxString>;
|
||||
using CommandNameVector = std::vector<CommandName>;
|
||||
CommandNameVector mCommandNames;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include <wx/string.h>
|
||||
#include <wx/longlong.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#ifndef IN_RC
|
||||
|
||||
class wxString;
|
||||
@ -167,4 +169,19 @@ private:
|
||||
#define UTF8CTOWX(X) wxString((X), wxConvUTF8)
|
||||
#define LAT1CTOWX(X) wxString((X), wxConvISO8859_1)
|
||||
|
||||
inline wxArrayString LocalizedStrings(const wxString strings[], size_t nStrings)
|
||||
{
|
||||
wxArrayString results;
|
||||
std::transform( strings, strings + nStrings, std::back_inserter(results),
|
||||
GetCustomTranslation );
|
||||
return results;
|
||||
}
|
||||
|
||||
inline wxArrayString LocalizedStrings(const wxArrayString &strings)
|
||||
{
|
||||
if (strings.empty())
|
||||
return {};
|
||||
return LocalizedStrings( &strings[0], strings.size() );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -2077,7 +2077,8 @@ ShuttleGui & ShuttleGui::Id(int id )
|
||||
}
|
||||
|
||||
ShuttleGui & ShuttleGui::Optional( bool &bVar ){
|
||||
TieCheckBox( "Set", bVar );
|
||||
/* i18n-hint verb, imperative */
|
||||
TieCheckBox( _("Set"), bVar );
|
||||
return *this;
|
||||
};
|
||||
|
||||
|
@ -39,21 +39,29 @@ OldStyleCommandPointer BatchEvalCommandType::Create(std::unique_ptr<CommandOutpu
|
||||
|
||||
bool BatchEvalCommand::Apply(const CommandContext & context)
|
||||
{
|
||||
// Uh oh, I need to build a catalog, expensively
|
||||
// Maybe it can be built in one long-lived place and shared among command
|
||||
// objects instead?
|
||||
MacroCommandsCatalog catalog(&context.project);
|
||||
|
||||
wxString macroName = GetString(wxT("MacroName"));
|
||||
if (macroName != wxT(""))
|
||||
{
|
||||
MacroCommands batch;
|
||||
batch.ReadMacro(macroName);
|
||||
return batch.ApplyMacro();
|
||||
return batch.ApplyMacro(catalog);
|
||||
}
|
||||
|
||||
wxString cmdName = GetString(wxT("CommandName"));
|
||||
wxString cmdParams = GetString(wxT("ParamString"));
|
||||
auto iter = catalog.ByCommandId(cmdName);
|
||||
const wxString &friendly = (iter == catalog.end())
|
||||
? cmdName // Expose internal name to user, in default of a better one!
|
||||
: iter->friendly;
|
||||
|
||||
// Create a Batch that will have just one command in it...
|
||||
MacroCommands Batch;
|
||||
bool bResult = Batch.ApplyCommand(cmdName, cmdParams, &context);
|
||||
bool bResult = Batch.ApplyCommand(friendly, cmdName, cmdParams, &context);
|
||||
// Relay messages, if any.
|
||||
wxString Message = Batch.GetMessage();
|
||||
if( !Message.IsEmpty() )
|
||||
|
@ -1650,7 +1650,7 @@ void CommandManager::GetCategories(wxArrayString &cats)
|
||||
}
|
||||
|
||||
void CommandManager::GetAllCommandNames(wxArrayString &names,
|
||||
bool includeMultis)
|
||||
bool includeMultis) const
|
||||
{
|
||||
for(const auto &entry : mCommandList) {
|
||||
if ( entry->isEffect )
|
||||
@ -1663,7 +1663,7 @@ void CommandManager::GetAllCommandNames(wxArrayString &names,
|
||||
}
|
||||
|
||||
void CommandManager::GetAllCommandLabels(wxArrayString &names,
|
||||
bool includeMultis)
|
||||
bool includeMultis) const
|
||||
{
|
||||
for(const auto &entry : mCommandList) {
|
||||
// This is fetching commands from the menus, for use as batch commands.
|
||||
|
@ -278,8 +278,8 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
|
||||
//
|
||||
|
||||
void GetCategories(wxArrayString &cats);
|
||||
void GetAllCommandNames(wxArrayString &names, bool includeMultis);
|
||||
void GetAllCommandLabels(wxArrayString &labels, bool includeMultis);
|
||||
void GetAllCommandNames(wxArrayString &names, bool includeMultis) const;
|
||||
void GetAllCommandLabels(wxArrayString &labels, bool includeMultis) const;
|
||||
void GetAllCommandData(
|
||||
wxArrayString &names,
|
||||
std::vector<NormalizedKeyString> &keys,
|
||||
|
@ -61,7 +61,7 @@ bool DragCommand::DefineParams( ShuttleParams & S ){
|
||||
|
||||
void DragCommand::PopulateOrExchange(ShuttleGui & S)
|
||||
{
|
||||
wxArrayString coords( nCoordTypes, kCoordTypeStrings );
|
||||
auto coords = LocalizedStrings( kCoordTypeStrings, nCoordTypes );
|
||||
|
||||
S.AddSpace(0, 5);
|
||||
|
||||
|
@ -94,8 +94,8 @@ bool GetInfoCommand::DefineParams( ShuttleParams & S ){
|
||||
|
||||
void GetInfoCommand::PopulateOrExchange(ShuttleGui & S)
|
||||
{
|
||||
wxArrayString types( nTypes, kTypes );
|
||||
wxArrayString formats( nFormats, kFormats );
|
||||
auto types = LocalizedStrings( kTypes, nTypes );
|
||||
auto formats = LocalizedStrings( kFormats, nFormats );
|
||||
S.AddSpace(0, 5);
|
||||
|
||||
S.StartMultiColumn(2, wxALIGN_CENTER);
|
||||
|
@ -48,7 +48,7 @@ bool GetTrackInfoCommand::DefineParams( ShuttleParams & S ){
|
||||
|
||||
void GetTrackInfoCommand::PopulateOrExchange(ShuttleGui & S)
|
||||
{
|
||||
wxArrayString types( nTypes, kTypes );
|
||||
auto types = LocalizedStrings( kTypes, nTypes );
|
||||
S.AddSpace(0, 5);
|
||||
|
||||
S.StartMultiColumn(2, wxALIGN_CENTER);
|
||||
|
@ -148,8 +148,8 @@ bool ScreenshotCommand::DefineParams( ShuttleParams & S ){
|
||||
|
||||
void ScreenshotCommand::PopulateOrExchange(ShuttleGui & S)
|
||||
{
|
||||
wxArrayString whats(nCaptureWhats, kCaptureWhatStrings);
|
||||
wxArrayString backs(nBackgrounds, kBackgroundStrings);
|
||||
auto whats = LocalizedStrings(kCaptureWhatStrings, nCaptureWhats);
|
||||
auto backs = LocalizedStrings(kBackgroundStrings, nBackgrounds);
|
||||
S.AddSpace(0, 5);
|
||||
|
||||
S.StartMultiColumn(2, wxALIGN_CENTER);
|
||||
|
@ -107,6 +107,7 @@ bool SelectFrequenciesCommand::Apply(const CommandContext & context){
|
||||
const int nModes =3;
|
||||
static const wxString kModes[nModes] =
|
||||
{
|
||||
/* i18n-hint verb, imperative */
|
||||
XO("Set"),
|
||||
XO("Add"),
|
||||
XO("Remove")
|
||||
@ -123,7 +124,7 @@ bool SelectTracksCommand::DefineParams( ShuttleParams & S ){
|
||||
|
||||
void SelectTracksCommand::PopulateOrExchange(ShuttleGui & S)
|
||||
{
|
||||
wxArrayString modes( nModes, kModes );
|
||||
auto modes = LocalizedStrings( kModes, nModes );
|
||||
S.AddSpace(0, 5);
|
||||
|
||||
S.StartMultiColumn(3, wxALIGN_CENTER);
|
||||
|
@ -61,7 +61,7 @@ bool SetClipCommand::DefineParams( ShuttleParams & S ){
|
||||
|
||||
void SetClipCommand::PopulateOrExchange(ShuttleGui & S)
|
||||
{
|
||||
wxArrayString colours( nColours, kColourStrings );
|
||||
auto colours = LocalizedStrings( kColourStrings, nColours );
|
||||
|
||||
S.AddSpace(0, 5);
|
||||
|
||||
|
@ -46,7 +46,7 @@ void SetProjectCommand::PopulateOrExchange(ShuttleGui & S)
|
||||
S.StartMultiColumn(3, wxALIGN_CENTER);
|
||||
{
|
||||
S.Optional( bHasName ).TieTextBox( _("Name:"), mName );
|
||||
S.TieCheckBox( "Resize:", bHasSizing );
|
||||
S.TieCheckBox( _("Resize:"), bHasSizing );
|
||||
}
|
||||
S.EndMultiColumn();
|
||||
S.StartMultiColumn(2, wxALIGN_CENTER);
|
||||
|
@ -123,10 +123,10 @@ bool SetTrackCommand::DefineParams( ShuttleParams & S ){
|
||||
|
||||
void SetTrackCommand::PopulateOrExchange(ShuttleGui & S)
|
||||
{
|
||||
wxArrayString colours( nColours, kColourStrings );
|
||||
wxArrayString displays( nDisplayTypes, kDisplayTypeStrings );
|
||||
wxArrayString scales( nScaleTypes, kScaleTypeStrings );
|
||||
wxArrayString vzooms( nZoomTypes, kZoomTypeStrings );
|
||||
auto colours = LocalizedStrings( kColourStrings, nColours );
|
||||
auto displays = LocalizedStrings( kDisplayTypeStrings, nDisplayTypes );
|
||||
auto scales = LocalizedStrings( kScaleTypeStrings, nScaleTypes );
|
||||
auto vzooms = LocalizedStrings( kZoomTypeStrings, nZoomTypes );
|
||||
|
||||
S.AddSpace(0, 5);
|
||||
|
||||
|
@ -94,15 +94,6 @@ enum
|
||||
static const wxChar *KEY_Version = wxT("Version");
|
||||
static const wxChar *KEY_Command = wxT("Command");
|
||||
|
||||
wxArrayString NyqControl::GetTranslatedChoices() const
|
||||
{
|
||||
wxArrayString results;
|
||||
std::transform(
|
||||
choices.begin(), choices.end(), std::back_inserter(results),
|
||||
GetCustomTranslation);
|
||||
return results;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// NyquistEffect
|
||||
@ -2405,7 +2396,7 @@ void NyquistEffect::BuildEffectWindow(ShuttleGui & S)
|
||||
{
|
||||
S.AddSpace(10, 10);
|
||||
|
||||
const wxArrayString &choices = ctrl.GetTranslatedChoices();
|
||||
auto choices = LocalizedStrings(ctrl.choices);
|
||||
S.Id(ID_Choice + i).AddChoice( {}, wxT(""), &choices);
|
||||
}
|
||||
else
|
||||
|
@ -53,8 +53,6 @@ public:
|
||||
//NyqControl( NyqControl && ) = default;
|
||||
//NyqControl &operator = ( NyqControl && ) = default;
|
||||
|
||||
wxArrayString GetTranslatedChoices() const;
|
||||
|
||||
int type;
|
||||
wxString var;
|
||||
wxString name;
|
||||
|
Loading…
x
Reference in New Issue
Block a user