Add details box to BatchCommandDialog

It is now populated with the CommandID and the command type.
Later we can add the command help string.

Std::pair changed to std::tuple to accommodate the extra information.
This commit is contained in:
James Crook 2018-03-01 19:23:46 +00:00
parent f5929381ec
commit bf03fd874b
6 changed files with 56 additions and 48 deletions

View File

@ -95,10 +95,13 @@ void BatchCommandDialog::PopulateOrExchange(ShuttleGui &S)
S.SetStretchyCol(1);
mParameters = S.AddTextBox(_("&Parameters"), wxT(""), 0);
mParameters->SetEditable(false);
S.Prop(0).AddPrompt( _("&Details" ) );
mDetails = S.AddTextWindow( wxT(""));
mDetails->SetEditable(false);
}
S.EndMultiColumn();
S.StartStatic(_("C&hoose command"), true);
S.Prop(10).StartStatic(_("C&hoose command"), true);
{
S.SetStyle(wxSUNKEN_BORDER | wxLC_LIST | wxLC_SINGLE_SEL);
mChoices = S.Id(CommandsListID).AddListControl();
@ -111,7 +114,7 @@ void BatchCommandDialog::PopulateOrExchange(ShuttleGui &S)
PopulateCommandList();
SetMinSize(wxSize(500, 400));
SetMinSize(wxSize(780, 560));
Fit();
Center();
}
@ -123,26 +126,9 @@ void BatchCommandDialog::PopulateCommandList()
mChoices->DeleteAllItems();
for (size_t ii = 0, size = mCommandNames.size(); ii < size; ++ii)
// insert the user-facing string
mChoices->InsertItem( ii, mCommandNames[ii].first );
mChoices->InsertItem( ii, std::get<0>( mCommandNames[ii] ) );
}
#if 0
int BatchCommandDialog::GetSelectedItem()
{
int i;
mSelectedCommand = wxT("");
for(i=0;i<mChoices->GetItemCount();i++)
{
if( mChoices->GetItemState( i, wxLIST_STATE_FOCUSED) != 0)
{
mSelectedCommand = mChoices->GetItemText( i );
return i;
}
}
return -1;
}
#endif
void BatchCommandDialog::ValidateChoices()
{
}
@ -168,25 +154,28 @@ void BatchCommandDialog::OnItemSelected(wxListEvent &event)
const auto &command = mCommandNames[ event.GetIndex() ];
EffectManager & em = EffectManager::Get();
PluginID ID = em.GetEffectByIdentifier(command.second);
PluginID ID = em.GetEffectByIdentifier( std::get<1>( command ));
// 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.first == mCommand->GetValue())
if (std::get<0>( command ) == mCommand->GetValue())
return;
mCommand->SetValue(command.first);
mInternalCommandName = command.second;
mCommand->SetValue(std::get<0> (command));
mInternalCommandName = std::get<1>( command );
wxString params = BatchCommands::GetCurrentParamsFor(command.second);
wxString params = BatchCommands::GetCurrentParamsFor(mInternalCommandName);
if (params.IsEmpty())
{
params = em.GetDefaultPreset(ID);
}
// Cryptic command and category.
// Later we can put help information there, perhaps.
mDetails->SetValue( mInternalCommandName + "\r\n" + std::get<2>(command) );
mParameters->SetValue(params);
}
@ -215,7 +204,7 @@ void BatchCommandDialog::OnUsePreset(wxCommandEvent & WXUNUSED(event))
void BatchCommandDialog::SetCommandAndParams(const wxString &Command, const wxString &Params)
{
auto item = make_iterator_range(mCommandNames).index_if(
[&](const CommandName &name){ return Command == name.second; }
[&](const CommandName &name){ return Command == std::get<1>( name); }
);
mParameters->SetValue( Params );
@ -224,7 +213,8 @@ void BatchCommandDialog::SetCommandAndParams(const wxString &Command, const wxSt
if (item < 0)
mCommand->SetValue( Command );
else {
mCommand->SetValue( mCommandNames[item].first );
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);
EffectManager & em = EffectManager::Get();

View File

@ -12,6 +12,7 @@
#ifndef __AUDACITY_BATCH_COMMAND_DIALOG__
#define __AUDACITY_BATCH_COMMAND_DIALOG__
#include <tuple>
#include <wx/defs.h>
#include <wx/string.h>
@ -63,10 +64,11 @@ class BatchCommandDialog final : public wxDialogWrapper {
wxListCtrl *mChoices;
wxTextCtrl * mCommand;
wxTextCtrl * mParameters;
wxTextCtrl * mDetails;
wxString mInternalCommandName;
using CommandName = std::pair<wxString, wxString>;
using CommandName = std::tuple<wxString, wxString,wxString>;
using CommandNameVector = std::vector<CommandName>;
CommandNameVector mCommandNames;

View File

@ -258,11 +258,9 @@ auto BatchCommands::GetAllCommands() -> CommandNameVector
// CLEANSPEECH remnant
for( const auto &command : SpecialCommands )
commands.push_back( {
//wxGetTranslation
(command.first),
command.second
} );
commands.push_back(
CommandName( command.first, command.second, _("Special Command") )
);
// end CLEANSPEECH remnant
@ -274,10 +272,14 @@ auto BatchCommands::GetAllCommands() -> CommandNameVector
{
auto command = em.GetCommandIdentifier(plug->GetID());
if (!command.IsEmpty())
commands.push_back( {
plug->GetUntranslatedName(), // plug->GetTranslatedName(),
command
} );
commands.push_back(
CommandName(
plug->GetUntranslatedName(), // plug->GetTranslatedName(),
command,
plug->GetPluginType() == PluginTypeEffect ?
_("Effect") : _("Menu Command (With Parameters)")
)
);
plug = pm.GetNextPlugin(PluginTypeEffect|PluginTypeAudacityCommand);
}
}
@ -290,13 +292,26 @@ auto BatchCommands::GetAllCommands() -> CommandNameVector
mManager->GetAllCommandLabels(mLabels, false);
mManager->GetAllCommandNames(mNames, false);
for(size_t i=0; i<mNames.GetCount(); i++) {
if( !mLabels[i].Contains( "..." ) ){
mLabels[i].Replace( "&", "" );
wxString label = mLabels[i];
if( !label.Contains( "..." ) ){
label.Replace( "&", "" );
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()) )
label = label + " (" + mNames[i] + ")";
commands.push_back(
{
mLabels[i] + " (" + mNames[i] + ")", // User readable name
mNames[i] // Internal name.
}
CommandName(
label, // User readable name
mNames[i], // Internal name.
_("Menu Command (No Parameters)")
)
);
}
}
@ -307,7 +322,7 @@ auto BatchCommands::GetAllCommands() -> CommandNameVector
std::sort(
commands.begin(), commands.end(),
[](const CommandName &a, const CommandName &b)
{ return a.first < b.first; }
{ return std::get<0>(a) < std::get<0>(b); }
);

View File

@ -12,6 +12,7 @@
#ifndef __AUDACITY_BATCH_COMMANDS_DIALOG__
#define __AUDACITY_BATCH_COMMANDS_DIALOG__
#include <tuple>
#include <wx/defs.h>
#include <wx/string.h>
@ -43,7 +44,7 @@ class BatchCommands final {
static wxArrayString GetNames();
// A pair of user-visible name, and internal string identifier
using CommandName = std::pair<wxString, wxString>;
using CommandName = std::tuple<wxString, wxString, wxString>;
using CommandNameVector = std::vector<CommandName>;
// Result is sorted by user-visible name
static CommandNameVector GetAllCommands();

View File

@ -655,11 +655,11 @@ 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; }
[&](const CommandName &name){ return Action == std::get<1>(name); }
);
auto friendlyName = item >= 0
? // wxGetTranslation
( mCommandNames[item].first )
std::get<0>( mCommandNames[item] )
: Action;
int i = mList->GetItemCount();

View File

@ -126,7 +126,7 @@ private:
int mSelectedCommand;
bool mChanged;
using CommandName = std::pair<wxString, wxString>;
using CommandName = std::tuple<wxString, wxString,wxString>;
using CommandNameVector = std::vector<CommandName>;
CommandNameVector mCommandNames;