1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 08:39:46 +02:00

ChoiceSetting default is changeable and can be unspecified

This commit is contained in:
Paul Licameli 2019-02-23 14:37:57 -05:00
parent 1236c5bfed
commit bc08f571dc
3 changed files with 31 additions and 12 deletions

View File

@ -276,6 +276,14 @@ const wxArrayStringEx &EnumValueSymbols::GetInternals() const
}
//////////
const EnumValueSymbol &ChoiceSetting::Default() const
{
if ( mDefaultSymbol >= 0 && mDefaultSymbol < mSymbols.size() )
return mSymbols[ mDefaultSymbol ];
static EnumValueSymbol empty;
return empty;
}
wxString ChoiceSetting::Read() const
{
const auto &defaultValue = Default().Internal();
@ -321,7 +329,7 @@ bool ChoiceSetting::Write( const wxString &value )
EnumSetting::EnumSetting(
const wxString &key,
EnumValueSymbols symbols,
size_t defaultSymbol,
long defaultSymbol,
std::vector<int> intValues, // must have same size as symbols
const wxString &oldKey
@ -337,6 +345,14 @@ EnumSetting::EnumSetting(
}
}
void ChoiceSetting::SetDefault( long value )
{
if ( value < (long)mSymbols.size() )
mDefaultSymbol = value;
else
wxASSERT( false );
}
int EnumSetting::ReadInt() const
{
auto index = Find( Read() );
@ -361,12 +377,14 @@ void EnumSetting::Migrate( wxString &value )
// Do not DELETE the old key -- let that be read if user downgrades
// Audacity. But further changes will be stored only to the NEW key
// and won't be seen then.
auto index = FindInt( intValue );
auto index = (long) FindInt( intValue );
if ( index >= mSymbols.size() )
index = mDefaultSymbol;
value = mSymbols[index].Internal();
Write(value);
gPrefs->Flush();
if ( index >= 0 && index < mSymbols.size() ) {
value = mSymbols[index].Internal();
Write(value);
gPrefs->Flush();
}
}
}

View File

@ -127,7 +127,7 @@ public:
ChoiceSetting(
const wxString &key,
EnumValueSymbols symbols,
size_t defaultSymbol
long defaultSymbol = -1
)
: mKey{ key }
@ -135,17 +135,18 @@ public:
, mDefaultSymbol{ defaultSymbol }
{
wxASSERT( defaultSymbol < mSymbols.size() );
wxASSERT( defaultSymbol < (long)mSymbols.size() );
}
const wxString &Key() const { return mKey; }
const EnumValueSymbol &Default() const
{ return mSymbols[mDefaultSymbol]; }
const EnumValueSymbol &Default() const;
const EnumValueSymbols &GetSymbols() const { return mSymbols; }
wxString Read() const;
bool Write( const wxString &value ); // you flush gPrefs afterward
void SetDefault( long value );
protected:
size_t Find( const wxString &value ) const;
virtual void Migrate( wxString& );
@ -157,7 +158,7 @@ protected:
// stores an internal value
mutable bool mMigrated { false };
const size_t mDefaultSymbol;
long mDefaultSymbol;
};
/// Extends ChoiceSetting with a corresponding table of integer codes
@ -170,7 +171,7 @@ public:
EnumSetting(
const wxString &key,
EnumValueSymbols symbols,
size_t defaultSymbol,
long defaultSymbol,
std::vector<int> intValues, // must have same size as symbols
const wxString &oldKey

View File

@ -59,7 +59,7 @@ public:
TracksViewModeEnumSetting(
const wxString &key,
EnumValueSymbols symbols,
size_t defaultSymbol,
long defaultSymbol,
std::vector<int> intValues,
const wxString &oldKey