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 304 of file BatchCommands.cpp.

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

429{
430 // Maybe this too should have a uniqueness check?
431 return std::find_if( begin(), end(),
432 [&](const Entry &entry)
433 { return entry.name.Internal() == commandId; });
434}
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 408 of file BatchCommands.cpp.

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

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: