Use constants for the names of the built-in colors

- Avoid repetition and errors from typos
- Allow simple changes
- Simpler data type handling, the constants are wxString
This commit is contained in:
Salvador E. Tropea 2023-02-18 19:42:36 -03:00 committed by Ian McInerney
parent 839301f81e
commit f135881bd6
5 changed files with 16 additions and 6 deletions

View File

@ -25,6 +25,7 @@
#include <pgm_base.h>
#include <settings/app_settings.h>
#include <settings/json_settings_internals.h>
#include <settings/color_settings.h>
#include <settings/common_settings.h>
#include <settings/parameters.h>
@ -147,7 +148,7 @@ APP_SETTINGS_BASE::APP_SETTINGS_BASE( const std::string& aFilename, int aSchemaV
&m_System.last_imperial_units, static_cast<int>( EDA_UNITS::INCHES ) ) );
m_params.emplace_back( new PARAM<wxString>( "appearance.color_theme",
&m_ColorTheme, wxS( "_builtin_default" ) ) );
&m_ColorTheme, COLOR_SETTINGS::COLOR_BUILTIN_DEFAULT ) );
addParamsForWindow( &m_Window, "window" );

View File

@ -31,6 +31,8 @@
///! Update the schema version whenever a migration is required
const int colorsSchemaVersion = 5;
const wxString COLOR_SETTINGS::COLOR_BUILTIN_DEFAULT = "_builtin_default";
const wxString COLOR_SETTINGS::COLOR_BUILTIN_CLASSIC = "_builtin_classic";
COLOR_SETTINGS::COLOR_SETTINGS( const wxString& aFilename, bool aAbsolutePath ) :
@ -378,12 +380,12 @@ void COLOR_SETTINGS::SetColor( int aLayer, const COLOR4D& aColor )
std::vector<COLOR_SETTINGS*> COLOR_SETTINGS::CreateBuiltinColorSettings()
{
COLOR_SETTINGS* defaultTheme = new COLOR_SETTINGS( wxT( "_builtin_default" ) );
COLOR_SETTINGS* defaultTheme = new COLOR_SETTINGS( COLOR_BUILTIN_DEFAULT );
defaultTheme->SetName( _( "KiCad Default" ) );
defaultTheme->m_writeFile = false;
defaultTheme->Load(); // We can just get the colors out of the param defaults for this one
COLOR_SETTINGS* classicTheme = new COLOR_SETTINGS( wxT( "_builtin_classic" ) );
COLOR_SETTINGS* classicTheme = new COLOR_SETTINGS( COLOR_BUILTIN_CLASSIC );
classicTheme->SetName( _( "KiCad Classic" ) );
classicTheme->m_writeFile = false;

View File

@ -207,7 +207,7 @@ COLOR_SETTINGS* SETTINGS_MANAGER::GetColorSettings( const wxString& aName )
if( !ret )
{
ret = registerColorSettings( aName );
*ret = *m_color_settings.at( "_builtin_default" );
*ret = *m_color_settings.at( COLOR_SETTINGS::COLOR_BUILTIN_DEFAULT );
ret->SetFilename( wxT( "user" ) );
ret->SetReadOnly( false );
}
@ -216,7 +216,7 @@ COLOR_SETTINGS* SETTINGS_MANAGER::GetColorSettings( const wxString& aName )
}
// This had better work
return m_color_settings.at( "_builtin_default" );
return m_color_settings.at( COLOR_SETTINGS::COLOR_BUILTIN_DEFAULT );
}

View File

@ -338,7 +338,10 @@ COLOR_SETTINGS* DIALOG_PLOT_SCHEMATIC::getColorSettings()
int selection = m_colorTheme->GetSelection();
if( selection < 0 )
return m_parent->GetSettingsManager()->GetColorSettings( "_builtin_default" );
{
return m_parent->GetSettingsManager()->GetColorSettings(
COLOR_SETTINGS::COLOR_BUILTIN_DEFAULT );
}
return static_cast<COLOR_SETTINGS*>( m_colorTheme->GetClientData( selection ) );
}

View File

@ -90,6 +90,10 @@ public:
*/
static std::vector<COLOR_SETTINGS*> CreateBuiltinColorSettings();
// Names for the built-in color settings
static const wxString COLOR_BUILTIN_DEFAULT;
static const wxString COLOR_BUILTIN_CLASSIC;
private:
bool migrateSchema0to1();