1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-18 17:10:55 +02:00

Use TranslatedInternalString in MacroCommandsCatalog

This commit is contained in:
Paul Licameli 2018-03-15 19:06:30 -04:00
parent 6c8ba8b5bb
commit d258385e3a
5 changed files with 27 additions and 23 deletions

View File

@ -128,7 +128,7 @@ void MacroCommandDialog::PopulateCommandList()
long ii = 0;
for ( const auto &entry : mCatalog )
// insert the user-facing string
mChoices->InsertItem( ii++, entry.friendly /* .Translation() */ );
mChoices->InsertItem( ii++, entry.name.Translated() );
}
void MacroCommandDialog::ValidateChoices()
@ -162,18 +162,19 @@ void MacroCommandDialog::OnItemSelected(wxListEvent &event)
const auto &command = mCatalog[ event.GetIndex() ];
EffectManager & em = EffectManager::Get();
PluginID ID = em.GetEffectByIdentifier( command.internal );
PluginID ID = em.GetEffectByIdentifier( command.name.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 ( command.friendly == mCommand->GetValue() )
if ( command.name.Translated() == mCommand->GetValue() )
// This uses the assumption of uniqueness of translated names!
return;
mCommand->SetValue(command.friendly);
mInternalCommandName = command.internal;
mCommand->SetValue(command.name.Translated());
mInternalCommandName = command.name.Internal();
wxString params = MacroCommands::GetCurrentParamsFor(mInternalCommandName);
if (params.IsEmpty())
@ -221,8 +222,8 @@ void MacroCommandDialog::SetCommandAndParams(const wxString &Command, const wxSt
// -- AVOID THIS!
mCommand->SetValue( Command );
else {
mCommand->SetValue( iter->friendly /* .Translation() */ );
mDetails->SetValue( iter->internal + "\r\n" + iter->category );
mCommand->SetValue( iter->name.Translated() );
mDetails->SetValue( iter->name.Internal() + "\r\n" + iter->category );
mChoices->SetItemState(iter - mCatalog.begin(),
wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);

View File

@ -289,8 +289,7 @@ MacroCommandsCatalog::MacroCommandsCatalog( const AudacityProject *project )
Entries commands;
for( const auto &command : SpecialCommands )
commands.push_back( {
GetCustomTranslation( command.first ),
command.second,
{ command.second, GetCustomTranslation( command.first ) },
_("Special Command")
} );
@ -305,8 +304,7 @@ MacroCommandsCatalog::MacroCommandsCatalog( const AudacityProject *project )
auto command = em.GetCommandIdentifier(plug->GetID());
if (!command.IsEmpty())
commands.push_back( {
plug->GetTranslatedName(),
command,
{ command, plug->GetTranslatedName() },
plug->GetPluginType() == PluginTypeEffect ?
_("Effect") : _("Menu Command (With Parameters)")
} );
@ -350,8 +348,10 @@ MacroCommandsCatalog::MacroCommandsCatalog( const AudacityProject *project )
commands.push_back(
{
label, // User readable name
mNames[i], // Internal name.
{
mNames[i], // Internal name.
label // User readable name
},
_("Menu Command (No Parameters)")
}
);
@ -363,12 +363,14 @@ MacroCommandsCatalog::MacroCommandsCatalog( const AudacityProject *project )
// 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; };
[](const Entry &a, const Entry &b)
{ return a.name.Translated() < b.name.Translated(); };
std::stable_sort(commands.begin(), commands.end(), less);
// Now uniquify by friendly name
auto equal =
[](const Entry &a, const Entry &b) { return a.friendly == b.friendly; };
[](const Entry &a, const Entry &b)
{ return a.name.Translated() == b.name.Translated(); };
std::unique_copy(
commands.begin(), commands.end(), std::back_inserter(mCommands), equal);
}
@ -378,9 +380,10 @@ auto MacroCommandsCatalog::ByFriendlyName( const wxString &friendlyName ) const
-> Entries::const_iterator
{
const auto less = [](const Entry &entryA, const Entry &entryB)
{ return entryA.friendly < entryB.friendly; };
{ return entryA.name.Translated() < entryB.name.Translated(); };
auto range = std::equal_range(
begin(), end(), Entry{ friendlyName, {}, {} }, less);
begin(), end(), Entry{ { {}, friendlyName }, {} }, less
);
if (range.first != range.second) {
wxASSERT_MSG( range.first + 1 == range.second,
"Non-unique user-visible command name" );
@ -396,7 +399,8 @@ auto MacroCommandsCatalog::ByCommandId( const wxString &commandId ) const
{
// Maybe this too should have a uniqueness check?
return std::find_if( begin(), end(),
[&](const Entry &entry){ return entry.internal == commandId; });
[&](const Entry &entry)
{ return entry.name.Internal() == commandId; });
}
@ -839,7 +843,7 @@ bool MacroCommands::ApplyMacro(
auto iter = catalog.ByCommandId(command);
auto friendly = (iter == catalog.end())
? command // Expose internal name to user, in default of a better one!
: iter->friendly;
: iter->name.Translated();
if (!ApplyCommandInBatchMode(friendly, command, mParamsMacro[i]) || mAbort)
break;
}

View File

@ -25,8 +25,7 @@ class MacroCommandsCatalog {
public:
// A triple of user-visible name, internal string identifier and type/help string.
struct Entry {
wxString friendly;
wxString internal;
TranslatedInternalString name;
wxString category;
};
using Entries = std::vector<Entry>;

View File

@ -686,7 +686,7 @@ void MacrosWindow::AddItem(const wxString &Action, const wxString &Params)
{
auto entry = mCatalog.ByCommandId(Action);
auto friendlyName = entry != mCatalog.end()
? entry->friendly /* .Translation() */
? entry->name.Translated()
:
// Expose an internal name to the user in default of any friendly name
// -- AVOID THIS!

View File

@ -57,7 +57,7 @@ bool BatchEvalCommand::Apply(const CommandContext & context)
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;
: iter->name.Translated();
// Create a Batch that will have just one command in it...
MacroCommands Batch;