diff --git a/src/Prefs.cpp b/src/Prefs.cpp index 63df6d719..40edb3b40 100755 --- a/src/Prefs.cpp +++ b/src/Prefs.cpp @@ -287,6 +287,11 @@ const EnumValueSymbol &ChoiceSetting::Default() const wxString ChoiceSetting::Read() const { const auto &defaultValue = Default().Internal(); + return ReadWithDefault( defaultValue ); +} + +wxString ChoiceSetting::ReadWithDefault( const wxString &defaultValue ) const +{ wxString value; if ( !gPrefs->Read(mKey, &value, defaultValue) ) if (!mMigrated) { @@ -356,10 +361,26 @@ void ChoiceSetting::SetDefault( long value ) int EnumSetting::ReadInt() const { auto index = Find( Read() ); + wxASSERT( index < mIntValues.size() ); 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 { const auto start = mIntValues.begin(); diff --git a/src/Prefs.h b/src/Prefs.h index eec87f36b..e160bf693 100644 --- a/src/Prefs.h +++ b/src/Prefs.h @@ -143,6 +143,12 @@ public: const EnumValueSymbols &GetSymbols() const { return mSymbols; } 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 void SetDefault( long value ); @@ -178,7 +184,13 @@ public: ); // 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 protected: