Audacity 3.2.0
Classes | Public Types | Public Member Functions | Private Attributes | List of all members
MacroCommandsCatalog Class Reference

#include <BatchCommands.h>

Collaboration diagram for MacroCommandsCatalog:
[legend]

Classes

struct  Entry
 

Public Types

using Entries = std::vector< Entry >
 

Public Member Functions

 MacroCommandsCatalog (const AudacityProject *project)
 
Entries::const_iterator ByFriendlyName (const TranslatableString &friendlyName) const
 
Entries::const_iterator ByCommandId (const CommandID &commandId) const
 
Entries::const_iterator ByTranslation (const wxString &translation) const
 
const Entryoperator[] (size_t index) const
 
Entries::const_iterator begin () const
 
Entries::const_iterator end () const
 

Private Attributes

Entries mCommands
 

Detailed Description

Definition at line 29 of file BatchCommands.h.

Member Typedef Documentation

◆ Entries

using MacroCommandsCatalog::Entries = std::vector<Entry>

Definition at line 36 of file BatchCommands.h.

Constructor & Destructor Documentation

◆ MacroCommandsCatalog()

MacroCommandsCatalog::MacroCommandsCatalog ( const AudacityProject project)

Definition at line 305 of file BatchCommands.cpp.

306{
307 if (!project)
308 return;
309
310 Entries commands;
311
314 {
315 for (auto &plug
317 auto command = pm.GetCommandIdentifier(plug.GetID());
318 if (!command.empty())
319 commands.push_back( {
320 { command, plug.GetSymbol().Msgid() },
321 plug.GetPluginType() == PluginTypeEffect ?
322 XO("Effect") : XO("Menu Command (With Parameters)")
323 } );
324 }
325 }
326
328 TranslatableStrings mLabels;
329 CommandIDs mNames;
330 std::vector<bool> vExcludeFromMacros;
331 mLabels.clear();
332 mNames.clear();
333 manager.GetAllCommandLabels(mLabels, vExcludeFromMacros, true);
334 manager.GetAllCommandNames(mNames, true);
335
336 const bool english = wxGetLocale()->GetCanonicalName().StartsWith(wxT("en"));
337
338 for(size_t i=0; i<mNames.size(); i++) {
339 if( !vExcludeFromMacros[i] ){
340 auto label = mLabels[i];
341 label.Strip();
342 bool suffix;
343 if (!english)
344 suffix = false;
345 else {
346 // We'll disambiguate if the squashed name is short and shorter than the internal name.
347 // Otherwise not.
348 // This means we won't have repetitive items like "Cut (Cut)"
349 // But we will show important disambiguation like "All (SelectAll)" and "By Date (SortByDate)"
350 // Disambiguation is no longer essential as the details box will show it.
351 // PRL: I think this reasoning applies only when locale is English.
352 // For other locales, show the (CamelCaseCodeName) always. Or, never?
353 wxString squashed = label.Translation();
354 squashed.Replace( " ", "" );
355
356 // uh oh, using GET for dubious comparison of (lengths of)
357 // user-visible name and internal CommandID!
358 // and doing this only for English locale!
359 suffix = squashed.length() < wxMin( 18, mNames[i].GET().length());
360 }
361
362 if( suffix )
363 // uh oh, using GET to expose CommandID to the user, as a
364 // disambiguating suffix on a name, but this is only ever done if
365 // the locale is English!
366 // PRL: In case this logic does get fixed for other locales,
367 // localize even this punctuation format. I'm told Chinese actually
368 // prefers slightly different parenthesis characters
369 label.Join( XO("(%s)").Format( mNames[i].GET() ), wxT(" ") );
370
371 // Bug 2294. The Close command pulls the rug out from under
372 // batch processing, because it destroys the project.
373 // So it is UNSAFE for scripting, and therefore excluded from
374 // the catalog.
375 if (mNames[i] == "Close")
376 continue;
377
378 commands.push_back(
379 {
380 {
381 mNames[i], // Internal name.
382 label // User readable name
383 },
384 XO("Menu Command (No Parameters)")
385 }
386 );
387 }
388 }
389
390 // Sort commands by their user-visible names.
391 // PRL: What exactly should happen if first members of pairs are not unique?
392 // I'm not sure, but at least I can sort stably for a better defined result.
393 auto less =
394 [](const Entry &a, const Entry &b)
395 { return a.name.StrippedTranslation() <
396 b.name.StrippedTranslation(); };
397 std::stable_sort(commands.begin(), commands.end(), less);
398
399 // Now uniquify by friendly name
400 auto equal =
401 [](const Entry &a, const Entry &b)
402 { return a.name.StrippedTranslation() ==
403 b.name.StrippedTranslation(); };
404 std::unique_copy(
405 commands.begin(), commands.end(), std::back_inserter(mCommands), equal);
406}
wxT("CloseDown"))
XO("Cut/Copy/Paste")
std::vector< CommandID > CommandIDs
Definition: Identifier.h:233
@ PluginTypeAudacityCommand
@ PluginTypeEffect
static const AttachedProjectObjects::RegisteredFactory manager
TranslatableString label
Definition: TagsEditor.cpp:165
const auto project
std::vector< TranslatableString > TranslatableStrings
static CommandManager & Get(AudacityProject &project)
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:52
static EffectManager & Get()
Abstract base class used in importing a file.
std::vector< Entry > Entries
Definition: BatchCommands.h:36
PluginManager maintains a list of all plug ins. That covers modules, effects, generators,...
Definition: PluginManager.h:51
Range PluginsOfType(int type)
CommandID GetCommandIdentifier(const PluginID &ID) const
static PluginManager & Get()
TranslatableString & Strip(unsigned options=MenuCodes) &
wxString StrippedTranslation() const
TranslatableString & Join(TranslatableString arg, const wxString &separator={}) &
Append another translatable string.
wxString Translation() const

References EffectManager::Get(), PluginManager::Get(), CommandManager::Get(), PluginManager::GetCommandIdentifier(), TranslatableString::Join(), label, manager, mCommands, MacroCommandsCatalog::Entry::name, PluginManager::PluginsOfType(), PluginTypeAudacityCommand, PluginTypeEffect, project, TranslatableString::Strip(), ComponentInterfaceSymbol::StrippedTranslation(), TranslatableString::Translation(), wxT(), and XO().

Here is the call graph for this function:

Member Function Documentation

◆ begin()

Entries::const_iterator MacroCommandsCatalog::begin ( ) const
inline

Definition at line 51 of file BatchCommands.h.

51{ return mCommands.begin(); }

References mCommands.

Referenced by MacroCommandDialog::SetCommandAndParams().

Here is the caller graph for this function:

◆ ByCommandId()

auto MacroCommandsCatalog::ByCommandId ( const CommandID commandId) const

Definition at line 428 of file BatchCommands.cpp.

430{
431 // Maybe this too should have a uniqueness check?
432 return std::find_if( begin(), end(),
433 [&](const Entry &entry)
434 { return entry.name.Internal() == commandId; });
435}
static ProjectFileIORegistry::AttributeWriterEntry entry
Entries::const_iterator end() const
Definition: BatchCommands.h:52
Entries::const_iterator begin() const
Definition: BatchCommands.h:51

References details::begin(), details::end(), and entry.

Referenced by MacrosWindow::AddItem(), BatchEvalCommand::Apply(), MacroCommands::ApplyMacro(), and MacroCommandDialog::SetCommandAndParams().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ByFriendlyName()

auto MacroCommandsCatalog::ByFriendlyName ( const TranslatableString friendlyName) const

Definition at line 409 of file BatchCommands.cpp.

411{
412 const auto less = [](const Entry &entryA, const Entry &entryB)
413 { return entryA.name.StrippedTranslation() <
414 entryB.name.StrippedTranslation(); };
415 auto range = std::equal_range(
416 begin(), end(), Entry{ { {}, friendlyName }, {} }, less
417 );
418 if (range.first != range.second) {
419 wxASSERT_MSG( range.first + 1 == range.second,
420 "Non-unique user-visible command name" );
421 return range.first;
422 }
423 else
424 return end();
425}

References details::begin(), details::end(), MacroCommandsCatalog::Entry::name, and ComponentInterfaceSymbol::StrippedTranslation().

Here is the call graph for this function:

◆ ByTranslation()

auto MacroCommandsCatalog::ByTranslation ( const wxString &  translation) const

Definition at line 438 of file BatchCommands.cpp.

440{
441 return std::find_if(begin(), end(),
442 [&](const Entry& entry)
443 { return entry.name.Translation() == translation; });
444}

References details::begin(), details::end(), and entry.

Referenced by MacrosWindow::OnListSelected().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ end()

Entries::const_iterator MacroCommandsCatalog::end ( ) const
inline

Definition at line 52 of file BatchCommands.h.

52{ return mCommands.end(); }

References mCommands.

Referenced by MacrosWindow::AddItem(), BatchEvalCommand::Apply(), MacroCommands::ApplyMacro(), MacrosWindow::OnListSelected(), and MacroCommandDialog::SetCommandAndParams().

Here is the caller graph for this function:

◆ operator[]()

const Entry & MacroCommandsCatalog::operator[] ( size_t  index) const
inline

Definition at line 49 of file BatchCommands.h.

49{ return mCommands[index]; }

References mCommands.

Member Data Documentation

◆ mCommands

Entries MacroCommandsCatalog::mCommands
private

Definition at line 56 of file BatchCommands.h.

Referenced by begin(), end(), MacroCommandsCatalog(), and operator[]().


The documentation for this class was generated from the following files: