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

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

48{ 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 421 of file BatchCommands.cpp.

423{
424 // Maybe this too should have a uniqueness check?
425 return std::find_if( begin(), end(),
426 [&](const Entry &entry)
427 { return entry.name.Internal() == commandId; });
428}
static ProjectFileIORegistry::AttributeWriterEntry entry
Entries::const_iterator end() const
Definition: BatchCommands.h:49
Entries::const_iterator begin() const
Definition: BatchCommands.h:48

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

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

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

49{ 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 46 of file BatchCommands.h.

46{ return mCommands[index]; }

References mCommands.

Member Data Documentation

◆ mCommands

Entries MacroCommandsCatalog::mCommands
private

Definition at line 53 of file BatchCommands.h.

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


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