1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-17 16:40:07 +02:00

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); S.SetStretchyCol(1);
mParameters = S.AddTextBox(_("&Parameters"), wxT(""), 0); mParameters = S.AddTextBox(_("&Parameters"), wxT(""), 0);
mParameters->SetEditable(false); mParameters->SetEditable(false);
S.Prop(0).AddPrompt( _("&Details" ) );
mDetails = S.AddTextWindow( wxT(""));
mDetails->SetEditable(false);
} }
S.EndMultiColumn(); 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); S.SetStyle(wxSUNKEN_BORDER | wxLC_LIST | wxLC_SINGLE_SEL);
mChoices = S.Id(CommandsListID).AddListControl(); mChoices = S.Id(CommandsListID).AddListControl();
@ -111,7 +114,7 @@ void BatchCommandDialog::PopulateOrExchange(ShuttleGui &S)
PopulateCommandList(); PopulateCommandList();
SetMinSize(wxSize(500, 400)); SetMinSize(wxSize(780, 560));
Fit(); Fit();
Center(); Center();
} }
@ -123,26 +126,9 @@ void BatchCommandDialog::PopulateCommandList()
mChoices->DeleteAllItems(); mChoices->DeleteAllItems();
for (size_t ii = 0, size = mCommandNames.size(); ii < size; ++ii) for (size_t ii = 0, size = mCommandNames.size(); ii < size; ++ii)
// insert the user-facing string // 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() void BatchCommandDialog::ValidateChoices()
{ {
} }
@ -168,25 +154,28 @@ void BatchCommandDialog::OnItemSelected(wxListEvent &event)
const auto &command = mCommandNames[ event.GetIndex() ]; const auto &command = mCommandNames[ event.GetIndex() ];
EffectManager & em = EffectManager::Get(); 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 // If ID is empty, then the effect wasn't found, in which case, the user must have
// selected one of the "special" commands. // selected one of the "special" commands.
mEditParams->Enable(!ID.IsEmpty()); mEditParams->Enable(!ID.IsEmpty());
mUsePreset->Enable(em.HasPresets(ID)); mUsePreset->Enable(em.HasPresets(ID));
if (command.first == mCommand->GetValue()) if (std::get<0>( command ) == mCommand->GetValue())
return; return;
mCommand->SetValue(command.first); mCommand->SetValue(std::get<0> (command));
mInternalCommandName = command.second; mInternalCommandName = std::get<1>( command );
wxString params = BatchCommands::GetCurrentParamsFor(command.second); wxString params = BatchCommands::GetCurrentParamsFor(mInternalCommandName);
if (params.IsEmpty()) if (params.IsEmpty())
{ {
params = em.GetDefaultPreset(ID); 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); mParameters->SetValue(params);
} }
@ -215,7 +204,7 @@ void BatchCommandDialog::OnUsePreset(wxCommandEvent & WXUNUSED(event))
void BatchCommandDialog::SetCommandAndParams(const wxString &Command, const wxString &Params) void BatchCommandDialog::SetCommandAndParams(const wxString &Command, const wxString &Params)
{ {
auto item = make_iterator_range(mCommandNames).index_if( 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 ); mParameters->SetValue( Params );
@ -224,7 +213,8 @@ void BatchCommandDialog::SetCommandAndParams(const wxString &Command, const wxSt
if (item < 0) if (item < 0)
mCommand->SetValue( Command ); mCommand->SetValue( Command );
else { 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); mChoices->SetItemState(item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
EffectManager & em = EffectManager::Get(); EffectManager & em = EffectManager::Get();

View File

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

View File

@ -258,11 +258,9 @@ auto BatchCommands::GetAllCommands() -> CommandNameVector
// CLEANSPEECH remnant // CLEANSPEECH remnant
for( const auto &command : SpecialCommands ) for( const auto &command : SpecialCommands )
commands.push_back( { commands.push_back(
//wxGetTranslation CommandName( command.first, command.second, _("Special Command") )
(command.first), );
command.second
} );
// end CLEANSPEECH remnant // end CLEANSPEECH remnant
@ -274,10 +272,14 @@ auto BatchCommands::GetAllCommands() -> CommandNameVector
{ {
auto command = em.GetCommandIdentifier(plug->GetID()); auto command = em.GetCommandIdentifier(plug->GetID());
if (!command.IsEmpty()) if (!command.IsEmpty())
commands.push_back( { commands.push_back(
CommandName(
plug->GetUntranslatedName(), // plug->GetTranslatedName(), plug->GetUntranslatedName(), // plug->GetTranslatedName(),
command command,
} ); plug->GetPluginType() == PluginTypeEffect ?
_("Effect") : _("Menu Command (With Parameters)")
)
);
plug = pm.GetNextPlugin(PluginTypeEffect|PluginTypeAudacityCommand); plug = pm.GetNextPlugin(PluginTypeEffect|PluginTypeAudacityCommand);
} }
} }
@ -290,13 +292,26 @@ auto BatchCommands::GetAllCommands() -> CommandNameVector
mManager->GetAllCommandLabels(mLabels, false); mManager->GetAllCommandLabels(mLabels, false);
mManager->GetAllCommandNames(mNames, false); mManager->GetAllCommandNames(mNames, false);
for(size_t i=0; i<mNames.GetCount(); i++) { for(size_t i=0; i<mNames.GetCount(); i++) {
if( !mLabels[i].Contains( "..." ) ){ wxString label = mLabels[i];
mLabels[i].Replace( "&", "" ); 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( commands.push_back(
{ CommandName(
mLabels[i] + " (" + mNames[i] + ")", // User readable name label, // User readable name
mNames[i] // Internal name. mNames[i], // Internal name.
} _("Menu Command (No Parameters)")
)
); );
} }
} }
@ -307,7 +322,7 @@ auto BatchCommands::GetAllCommands() -> CommandNameVector
std::sort( std::sort(
commands.begin(), commands.end(), commands.begin(), commands.end(),
[](const CommandName &a, const CommandName &b) [](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__ #ifndef __AUDACITY_BATCH_COMMANDS_DIALOG__
#define __AUDACITY_BATCH_COMMANDS_DIALOG__ #define __AUDACITY_BATCH_COMMANDS_DIALOG__
#include <tuple>
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/string.h> #include <wx/string.h>
@ -43,7 +44,7 @@ class BatchCommands final {
static wxArrayString GetNames(); static wxArrayString GetNames();
// A pair of user-visible name, and internal string identifier // 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>; using CommandNameVector = std::vector<CommandName>;
// Result is sorted by user-visible name // Result is sorted by user-visible name
static CommandNameVector GetAllCommands(); 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 // Translate internal command name to a friendly form
auto item = make_iterator_range(mCommandNames).index_if( 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 auto friendlyName = item >= 0
? // wxGetTranslation ? // wxGetTranslation
( mCommandNames[item].first ) std::get<0>( mCommandNames[item] )
: Action; : Action;
int i = mList->GetItemCount(); int i = mList->GetItemCount();

View File

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