1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-02-07 04:01:54 +01: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();
}
}
}