1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-02 00:49:33 +02:00

Define ChoiceSetting::ReadWithDefault ...

... because some calls might not have used the same defaults as in the Tie...
functions
This commit is contained in:
Paul Licameli 2019-04-04 11:48:10 -04:00
parent bc08f571dc
commit 85b06fe6d0
2 changed files with 34 additions and 1 deletions

View File

@ -287,6 +287,11 @@ const EnumValueSymbol &ChoiceSetting::Default() const
wxString ChoiceSetting::Read() const wxString ChoiceSetting::Read() const
{ {
const auto &defaultValue = Default().Internal(); const auto &defaultValue = Default().Internal();
return ReadWithDefault( defaultValue );
}
wxString ChoiceSetting::ReadWithDefault( const wxString &defaultValue ) const
{
wxString value; wxString value;
if ( !gPrefs->Read(mKey, &value, defaultValue) ) if ( !gPrefs->Read(mKey, &value, defaultValue) )
if (!mMigrated) { if (!mMigrated) {
@ -356,10 +361,26 @@ void ChoiceSetting::SetDefault( long value )
int EnumSetting::ReadInt() const int EnumSetting::ReadInt() const
{ {
auto index = Find( Read() ); auto index = Find( Read() );
wxASSERT( index < mIntValues.size() ); wxASSERT( index < mIntValues.size() );
return mIntValues[ index ]; return mIntValues[ index ];
} }
int EnumSetting::ReadIntWithDefault( int defaultValue ) const
{
wxString defaultString;
auto index0 = FindInt( defaultValue );
if ( index0 < mSymbols.size() )
defaultString = mSymbols[ index0 ].Internal();
else
wxASSERT( false );
auto index = Find( ReadWithDefault( defaultString ) );
wxASSERT( index < mSymbols.size() );
return mIntValues[ index ];
}
size_t EnumSetting::FindInt( int code ) const size_t EnumSetting::FindInt( int code ) const
{ {
const auto start = mIntValues.begin(); const auto start = mIntValues.begin();

View File

@ -143,6 +143,12 @@ public:
const EnumValueSymbols &GetSymbols() const { return mSymbols; } const EnumValueSymbols &GetSymbols() const { return mSymbols; }
wxString Read() const; wxString Read() const;
// new direct use is discouraged but it may be needed in legacy code:
// use a default in case the preference is not defined, which may not be
// the default-default stored in this object.
wxString ReadWithDefault( const wxString & ) const;
bool Write( const wxString &value ); // you flush gPrefs afterward bool Write( const wxString &value ); // you flush gPrefs afterward
void SetDefault( long value ); void SetDefault( long value );
@ -178,7 +184,13 @@ public:
); );
// Read and write the encoded values // Read and write the encoded values
virtual int ReadInt() const; int ReadInt() const;
// new direct use is discouraged but it may be needed in legacy code:
// use a default in case the preference is not defined, which may not be
// the default-default stored in this object.
int ReadIntWithDefault( int defaultValue ) const;
bool WriteInt( int code ); // you flush gPrefs afterward bool WriteInt( int code ); // you flush gPrefs afterward
protected: protected: