mirror of
https://github.com/cookiengineer/audacity
synced 2025-12-24 01:21:13 +01:00
Define EnumSetting and EncodedEnumSetting
This commit is contained in:
81
src/Prefs.h
81
src/Prefs.h
@@ -30,6 +30,7 @@
|
||||
#define __AUDACITY_PREFS__
|
||||
|
||||
#include "Audacity.h"
|
||||
#include "../include/audacity/IdentInterface.h"
|
||||
|
||||
#include <wx/config.h>
|
||||
#include <wx/fileconf.h>
|
||||
@@ -40,4 +41,84 @@ void FinishPreferences();
|
||||
extern AUDACITY_DLL_API wxFileConfig *gPrefs;
|
||||
extern int gMenusDirty;
|
||||
|
||||
// Packages a table of user-visible choices each with an internal code string,
|
||||
// a preference key path,
|
||||
// and a default choice
|
||||
class EnumSetting
|
||||
{
|
||||
public:
|
||||
EnumSetting(
|
||||
const wxString &key,
|
||||
const IdentInterfaceSymbol symbols[], size_t nSymbols,
|
||||
size_t defaultSymbol
|
||||
)
|
||||
: mKey{ key }
|
||||
|
||||
, mSymbols{ symbols }
|
||||
, mnSymbols{ nSymbols }
|
||||
|
||||
, mDefaultSymbol{ defaultSymbol }
|
||||
{
|
||||
wxASSERT( defaultSymbol < nSymbols );
|
||||
}
|
||||
|
||||
const wxString &Key() const { return mKey; }
|
||||
const IdentInterfaceSymbol &Default() const
|
||||
{ return mSymbols[mDefaultSymbol]; }
|
||||
const IdentInterfaceSymbol *begin() const { return mSymbols; }
|
||||
const IdentInterfaceSymbol *end() const { return mSymbols + mnSymbols; }
|
||||
|
||||
wxString Read() const;
|
||||
bool Write( const wxString &value ); // you flush gPrefs afterward
|
||||
|
||||
protected:
|
||||
size_t Find( const wxString &value ) const;
|
||||
virtual void Migrate( wxString& );
|
||||
|
||||
const wxString mKey;
|
||||
|
||||
const IdentInterfaceSymbol *mSymbols;
|
||||
const size_t mnSymbols;
|
||||
|
||||
// stores an internal value
|
||||
mutable bool mMigrated { false };
|
||||
|
||||
const size_t mDefaultSymbol;
|
||||
};
|
||||
|
||||
// Extends EnumSetting with a corresponding table of integer codes
|
||||
// (generally not equal to their table positions),
|
||||
// and optionally an old preference key path that stored integer codes, to be
|
||||
// migrated into one that stores internal string values instead
|
||||
class EncodedEnumSetting : public EnumSetting
|
||||
{
|
||||
public:
|
||||
EncodedEnumSetting(
|
||||
const wxString &key,
|
||||
const IdentInterfaceSymbol symbols[], size_t nSymbols,
|
||||
size_t defaultSymbol,
|
||||
|
||||
const int intValues[] = nullptr, // must have same size as symbols
|
||||
const wxString &oldKey = {}
|
||||
)
|
||||
: EnumSetting{ key, symbols, nSymbols, defaultSymbol }
|
||||
, mIntValues{ intValues }
|
||||
, mOldKey{ oldKey }
|
||||
{
|
||||
wxASSERT( mIntValues );
|
||||
}
|
||||
|
||||
// Read and write the encoded values
|
||||
virtual int ReadInt() const;
|
||||
bool WriteInt( int code ); // you flush gPrefs afterward
|
||||
|
||||
protected:
|
||||
size_t FindInt( int code ) const;
|
||||
void Migrate( wxString& ) override;
|
||||
|
||||
private:
|
||||
const int *mIntValues;
|
||||
const wxString mOldKey;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user