mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-19 17:40:15 +02:00
class EnumValueSymbols lets you specify a table...
... of EnumValueSymbol either row-wise or column-wise
This commit is contained in:
parent
9b67e7538f
commit
1236c5bfed
@ -239,6 +239,42 @@ void FinishPreferences()
|
||||
}
|
||||
}
|
||||
|
||||
//////////
|
||||
EnumValueSymbols::EnumValueSymbols(
|
||||
ByColumns_t,
|
||||
const wxArrayStringEx &msgids,
|
||||
wxArrayStringEx internals
|
||||
)
|
||||
: mInternals( std::move( internals ) )
|
||||
{
|
||||
auto size = mInternals.size(), size2 = msgids.size();
|
||||
if ( size != size2 ) {
|
||||
wxASSERT( false );
|
||||
size = std::min( size, size2 );
|
||||
}
|
||||
reserve( size );
|
||||
auto iter1 = mInternals.begin();
|
||||
auto iter2 = msgids.begin();
|
||||
while( size-- )
|
||||
emplace_back( *iter1++, *iter2++ );
|
||||
}
|
||||
|
||||
const wxArrayStringEx &EnumValueSymbols::GetTranslations() const
|
||||
{
|
||||
if ( mTranslations.empty() )
|
||||
mTranslations = transform_container<wxArrayStringEx>( *this,
|
||||
std::mem_fn( &EnumValueSymbol::Translation ) );
|
||||
return mTranslations;
|
||||
}
|
||||
|
||||
const wxArrayStringEx &EnumValueSymbols::GetInternals() const
|
||||
{
|
||||
if ( mInternals.empty() )
|
||||
mInternals = transform_container<wxArrayStringEx>( *this,
|
||||
std::mem_fn( &EnumValueSymbol::Internal ) );
|
||||
return mInternals;
|
||||
}
|
||||
|
||||
//////////
|
||||
wxString ChoiceSetting::Read() const
|
||||
{
|
||||
@ -260,9 +296,9 @@ wxString ChoiceSetting::Read() const
|
||||
|
||||
size_t ChoiceSetting::Find( const wxString &value ) const
|
||||
{
|
||||
auto start = begin();
|
||||
auto start = GetSymbols().begin();
|
||||
return size_t(
|
||||
std::find( start, end(), EnumValueSymbol{ value, {} } )
|
||||
std::find( start, GetSymbols().end(), EnumValueSymbol{ value, {} } )
|
||||
- start );
|
||||
}
|
||||
|
||||
@ -346,3 +382,5 @@ wxString WarningDialogKey(const wxString &internalDialogName)
|
||||
{
|
||||
return wxT("/Warnings/") + internalDialogName;
|
||||
}
|
||||
|
||||
ByColumns_t ByColumns{};
|
||||
|
36
src/Prefs.h
36
src/Prefs.h
@ -32,6 +32,7 @@
|
||||
#include "Audacity.h"
|
||||
|
||||
#include "../include/audacity/ComponentInterface.h"
|
||||
#include "MemoryX.h" // for wxArrayStringEx
|
||||
|
||||
#include <memory>
|
||||
#include <wx/fileconf.h> // to inherit wxFileConfig
|
||||
@ -86,7 +87,37 @@ public:
|
||||
int mVersionMicroKeyInit{};
|
||||
};
|
||||
|
||||
using EnumValueSymbols = std::vector< EnumValueSymbol >;
|
||||
struct ByColumns_t{};
|
||||
extern ByColumns_t ByColumns;
|
||||
|
||||
/// A table of EnumValueSymbol that you can access by "row" with
|
||||
/// operator [] but also allowing access to the "columns" of internal or
|
||||
/// translated strings, and also allowing convenient column-wise construction
|
||||
class EnumValueSymbols : public std::vector< EnumValueSymbol >
|
||||
{
|
||||
public:
|
||||
EnumValueSymbols() = default;
|
||||
EnumValueSymbols( std::initializer_list<EnumValueSymbol> symbols )
|
||||
: vector( symbols )
|
||||
{}
|
||||
|
||||
// columnwise constructor; arguments must have same size
|
||||
// (Implicit constructor takes initial tag argument to avoid unintended
|
||||
// overload resolution to the inherited constructor taking
|
||||
// initializer_list, in the case that each column has exactly two strings)
|
||||
EnumValueSymbols(
|
||||
ByColumns_t,
|
||||
const wxArrayStringEx &msgids, // untranslated!
|
||||
wxArrayStringEx internals
|
||||
);
|
||||
|
||||
const wxArrayStringEx &GetTranslations() const;
|
||||
const wxArrayStringEx &GetInternals() const;
|
||||
|
||||
private:
|
||||
mutable wxArrayStringEx mTranslations;
|
||||
mutable wxArrayStringEx mInternals;
|
||||
};
|
||||
|
||||
/// Packages a table of user-visible choices each with an internal code string,
|
||||
/// a preference key path, and a default choice
|
||||
@ -110,8 +141,7 @@ public:
|
||||
const wxString &Key() const { return mKey; }
|
||||
const EnumValueSymbol &Default() const
|
||||
{ return mSymbols[mDefaultSymbol]; }
|
||||
EnumValueSymbols::const_iterator begin() const { return mSymbols.begin(); }
|
||||
EnumValueSymbols::const_iterator end() const { return mSymbols.end(); }
|
||||
const EnumValueSymbols &GetSymbols() const { return mSymbols; }
|
||||
|
||||
wxString Read() const;
|
||||
bool Write( const wxString &value ); // you flush gPrefs afterward
|
||||
|
@ -1866,14 +1866,15 @@ wxChoice *ShuttleGuiBase::TieChoice(
|
||||
// Do this to force any needed migrations first
|
||||
choiceSetting.Read();
|
||||
|
||||
wxArrayStringEx visibleChoices, internalChoices;
|
||||
for (const auto &ident : choiceSetting) {
|
||||
visibleChoices.push_back( ident.Translation() );
|
||||
internalChoices.push_back( ident.Internal() );
|
||||
}
|
||||
const auto &symbols = choiceSetting.GetSymbols();
|
||||
|
||||
return TieChoice(
|
||||
Prompt, choiceSetting.Key(), choiceSetting.Default().Internal(),
|
||||
visibleChoices, internalChoices );
|
||||
Prompt,
|
||||
choiceSetting.Key(),
|
||||
choiceSetting.Default().Internal(),
|
||||
symbols.GetTranslations(),
|
||||
symbols.GetInternals()
|
||||
);
|
||||
}
|
||||
|
||||
/// Variant of the standard TieChoice which does the two step exchange
|
||||
|
Loading…
x
Reference in New Issue
Block a user