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
 
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 28 of file BatchCommands.h.

Member Typedef Documentation

◆ Entries

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

Definition at line 35 of file BatchCommands.h.

Constructor & Destructor Documentation

◆ MacroCommandsCatalog()

MacroCommandsCatalog::MacroCommandsCatalog ( const AudacityProject project)

Definition at line 303 of file BatchCommands.cpp.

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

47{ 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 426 of file BatchCommands.cpp.

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

References PackedArray::begin(), PackedArray::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 407 of file BatchCommands.cpp.

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

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

Here is the call graph for this function:

◆ end()

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

Definition at line 48 of file BatchCommands.h.

48{ return mCommands.end(); }

References mCommands.

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

Here is the caller graph for this function:

◆ operator[]()

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

Definition at line 45 of file BatchCommands.h.

45{ return mCommands[index]; }

References mCommands.

Member Data Documentation

◆ mCommands

Entries MacroCommandsCatalog::mCommands
private

Definition at line 52 of file BatchCommands.h.

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


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