Friendlier command names in the Edit Chains dialogs...

... Both the pane that lists the steps of the chain, and the selection dialog
for adding a new step.

NOT translating command names yet, though.
This commit is contained in:
Paul Licameli 2018-01-09 21:49:49 -05:00
parent fa53d521a2
commit 0319d6ea68
6 changed files with 102 additions and 52 deletions

View File

@ -118,16 +118,15 @@ void BatchCommandDialog::PopulateOrExchange(ShuttleGui &S)
void BatchCommandDialog::PopulateCommandList()
{
wxArrayString commandList = BatchCommands::GetAllCommands();
mCommandNames = BatchCommands::GetAllCommands();
unsigned int i;
mChoices->DeleteAllItems();
for( i=0;i<commandList.GetCount();i++)
{
mChoices->InsertItem( i, commandList[i]);
}
for (size_t ii = 0, size = mCommandNames.size(); ii < size; ++ii)
// insert the user-facing string
mChoices->InsertItem( ii, mCommandNames[ii].first );
}
#if 0
int BatchCommandDialog::GetSelectedItem()
{
int i;
@ -142,6 +141,7 @@ int BatchCommandDialog::GetSelectedItem()
}
return -1;
}
#endif
void BatchCommandDialog::ValidateChoices()
{
@ -153,7 +153,7 @@ void BatchCommandDialog::OnChoice(wxCommandEvent & WXUNUSED(event))
void BatchCommandDialog::OnOk(wxCommandEvent & WXUNUSED(event))
{
mSelectedCommand = mCommand->GetValue().Strip(wxString::both);
mSelectedCommand = mInternalCommandName.Strip(wxString::both);
mSelectedParameters = mParameters->GetValue().Strip(wxString::trailing);
EndModal(true);
}
@ -165,24 +165,23 @@ void BatchCommandDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
void BatchCommandDialog::OnItemSelected(wxListEvent &event)
{
wxString command = mChoices->GetItemText(event.GetIndex());
const auto &command = mCommandNames[ event.GetIndex() ];
EffectManager & em = EffectManager::Get();
PluginID ID = em.GetEffectByIdentifier(command);
PluginID ID = em.GetEffectByIdentifier(command.second);
// 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 (command == mCommand->GetValue())
{
if (command.first == mCommand->GetValue())
return;
}
mCommand->SetValue(command);
mCommand->SetValue(command.first);
mInternalCommandName = command.second;
wxString params = BatchCommands::GetCurrentParamsFor(command);
wxString params = BatchCommands::GetCurrentParamsFor(command.second);
if (params.IsEmpty())
{
params = em.GetDefaultPreset(ID);
@ -193,7 +192,7 @@ void BatchCommandDialog::OnItemSelected(wxListEvent &event)
void BatchCommandDialog::OnEditParams(wxCommandEvent & WXUNUSED(event))
{
wxString command = mCommand->GetValue();
wxString command = mInternalCommandName;
wxString params = mParameters->GetValue();
params = BatchCommands::PromptForParamsFor(command, params, this).Trim();
@ -204,7 +203,7 @@ void BatchCommandDialog::OnEditParams(wxCommandEvent & WXUNUSED(event))
void BatchCommandDialog::OnUsePreset(wxCommandEvent & WXUNUSED(event))
{
wxString command = mCommand->GetValue();
wxString command = mInternalCommandName;
wxString params = mParameters->GetValue();
wxString preset = BatchCommands::PromptForPresetFor(command, params, this).Trim();
@ -215,12 +214,17 @@ void BatchCommandDialog::OnUsePreset(wxCommandEvent & WXUNUSED(event))
void BatchCommandDialog::SetCommandAndParams(const wxString &Command, const wxString &Params)
{
mCommand->SetValue( Command );
auto item = make_iterator_range(mCommandNames).index_if(
[&](const CommandName &name){ return Command == name.second; }
);
mParameters->SetValue( Params );
int item = mChoices->FindItem(-1, Command);
if (item != wxNOT_FOUND)
{
mInternalCommandName = Command;
if (item < 0)
mCommand->SetValue( Command );
else {
mCommand->SetValue( mCommandNames[item].first );
mChoices->SetItemState(item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
EffectManager & em = EffectManager::Get();

View File

@ -56,13 +56,20 @@ class BatchCommandDialog final : public wxDialogWrapper {
void ValidateChoices();
void PopulateCommandList();
int GetSelectedItem();
//int GetSelectedItem();
wxButton *mEditParams;
wxButton *mUsePreset;
wxListCtrl *mChoices;
wxTextCtrl * mCommand;
wxTextCtrl * mParameters;
wxString mInternalCommandName;
using CommandName = std::pair<wxString, wxString>;
using CommandNameVector = std::vector<CommandName>;
CommandNameVector mCommandNames;
DECLARE_EVENT_TABLE()
};

View File

@ -54,15 +54,30 @@ enum eCommandType { CtEffect, CtMenu, CtSpecial };
// TIDY-ME: Not currently translated,
// but there are issues to address if we do.
// CLEANSPEECH remnant
static wxString SpecialCommands[] = {
wxT("NoAction"),
// wxT("Import"), // non-functioning
wxT("ExportMP3_56k_before"),
wxT("ExportMP3_56k_after"),
wxT("ExportFLAC"),
wxT("ExportMP3"),
wxT("ExportOgg"),
wxT("ExportWAV")
static const std::pair<const wxChar*, const wxChar*> SpecialCommands[] = {
// Use translations of the first members, some other day.
// For 2.2.2 we'll get them into the catalog at least.
{ XO("No Action"), wxT("NoAction") },
// { wxT("Import"), wxT("Import") }, // non-functioning
/* i18n-hint: before is adverb; MP3 names an audio file format */
{ XO("Export as MP3 56k before"), wxT("ExportMP3_56k_before") },
/* i18n-hint: after is adverb; MP3 names an audio file format */
{ XO("Export as MP3 56k after"), wxT("ExportMP3_56k_after") },
/* i18n-hint: FLAC names an audio file format */
{ XO("Export as FLAC"), wxT("ExportFLAC") },
/* i18n-hint: MP3 names an audio file format */
{ XO("Export as MP3"), wxT("ExportMP3") },
/* i18n-hint: Ogg names an audio file format */
{ XO("Export as Ogg"), wxT("ExportOgg") },
/* i18n-hint: WAV names an audio file format */
{ XO("Export as WAV"), wxT("ExportWAV") },
};
// end CLEANSPEECH remnant
@ -259,25 +274,22 @@ void BatchCommands::SetWavToMp3Chain() // a function per default chain? This is
}
// Gets all commands that are valid for this mode.
wxArrayString BatchCommands::GetAllCommands()
auto BatchCommands::GetAllCommands() -> CommandNameVector
{
wxArrayString commands;
wxString command;
commands.Clear();
CommandNameVector commands;
AudacityProject *project = GetActiveProject();
if (!project)
{
return commands;
}
unsigned int i;
// CLEANSPEECH remnant
for(i=0;i<sizeof(SpecialCommands)/sizeof(SpecialCommands[0]);i++)
{
commands.Add( SpecialCommands[i] );
}
for( const auto &command : SpecialCommands )
commands.push_back( {
//wxGetTranslation
(command.first),
command.second
} );
// end CLEANSPEECH remnant
PluginManager & pm = PluginManager::Get();
@ -285,15 +297,23 @@ wxArrayString BatchCommands::GetAllCommands()
const PluginDescriptor *plug = pm.GetFirstPlugin(PluginTypeEffect);
while (plug)
{
command = em.GetEffectIdentifier(plug->GetID());
auto command = em.GetEffectIdentifier(plug->GetID());
if (!command.IsEmpty())
{
commands.Add(command);
}
commands.push_back( {
plug->GetUntranslatedName(), // plug->GetTranslatedName(),
command
} );
plug = pm.GetNextPlugin(PluginTypeEffect);
}
commands.Sort();
// 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 a.first < b.first; }
);
/* This is for later in development: include the menu commands.
CommandManager * mManager = project->GetCommandManager();
@ -626,9 +646,8 @@ bool BatchCommands::ApplyCommand(const wxString & command, const wxString & para
unsigned int i;
// Test for a special command.
// CLEANSPEECH remnant
for(i=0;i<sizeof(SpecialCommands)/sizeof(SpecialCommands[0]);i++)
{
if( command == SpecialCommands[i] )
for( i = 0; i < sizeof(SpecialCommands)/sizeof(*SpecialCommands); ++i ) {
if( command == SpecialCommands[i].second )
return ApplySpecialCommand( i, command, params );
}
// end CLEANSPEECH remnant

View File

@ -40,7 +40,12 @@ class BatchCommands final {
// These commands do not depend on the command list.
static wxArrayString GetNames();
static wxArrayString GetAllCommands();
// A pair of user-visible name, and internal string identifier
using CommandName = std::pair<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);

View File

@ -486,6 +486,8 @@ EditChainsDialog::~EditChainsDialog()
/// Creates the dialog and its contents.
void EditChainsDialog::Populate()
{
mCommandNames = BatchCommands::GetAllCommands();
//------------------------- Main section --------------------
ShuttleGui S(this, eIsCreating);
PopulateOrExchange(S);
@ -627,11 +629,20 @@ void EditChainsDialog::PopulateList()
/// Add one item into mList
void EditChainsDialog::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 == name.second; }
);
auto friendlyName = item >= 0
? // wxGetTranslation
( mCommandNames[item].first )
: Action;
int i = mList->GetItemCount();
mList->InsertItem(i, wxT(""));
mList->SetItem(i, ItemNumberColumn, wxString::Format(wxT(" %02i"), i + 1));
mList->SetItem(i, ActionColumn, Action );
mList->SetItem(i, ActionColumn, friendlyName );
mList->SetItem(i, ParamsColumn, Params );
}

View File

@ -110,6 +110,10 @@ private:
int mSelectedCommand;
bool mChanged;
using CommandName = std::pair<wxString, wxString>;
using CommandNameVector = std::vector<CommandName>;
CommandNameVector mCommandNames;
DECLARE_EVENT_TABLE()
};