Browse Source

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
7.0
Salvador E. Tropea 3 years ago
committed by Ian McInerney
parent
commit
f135881bd6
  1. 3
      common/settings/app_settings.cpp
  2. 6
      common/settings/color_settings.cpp
  3. 4
      common/settings/settings_manager.cpp
  4. 5
      eeschema/dialogs/dialog_plot_schematic.cpp
  5. 4
      include/settings/color_settings.h

3
common/settings/app_settings.cpp

@ -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" );

6
common/settings/color_settings.cpp

@ -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;

4
common/settings/settings_manager.cpp

@ -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 );
}

5
eeschema/dialogs/dialog_plot_schematic.cpp

@ -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 ) );
}

4
include/settings/color_settings.h

@ -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();

Loading…
Cancel
Save