PCM: Treat color themes as read-only; don't copy to settings dir

Fixes https://gitlab.com/kicad/code/kicad/-/issues/9548
This commit is contained in:
Jon Evans 2021-11-09 22:11:59 -05:00
parent 89f5842a17
commit 42eb063697
5 changed files with 18 additions and 15 deletions

View File

@ -33,11 +33,13 @@
const int colorsSchemaVersion = 3; const int colorsSchemaVersion = 3;
COLOR_SETTINGS::COLOR_SETTINGS( const wxString& aFilename ) : COLOR_SETTINGS::COLOR_SETTINGS( const wxString& aFilename, bool aAbsolutePath ) :
JSON_SETTINGS( std::move( aFilename ), SETTINGS_LOC::COLORS, colorsSchemaVersion ), JSON_SETTINGS( std::move( aFilename ), SETTINGS_LOC::COLORS, colorsSchemaVersion ),
m_overrideSchItemColors( false ), m_overrideSchItemColors( false ),
m_useBoardStackupColors( true ) m_useBoardStackupColors( true )
{ {
if( aAbsolutePath )
SetLocation( SETTINGS_LOC::NONE );
m_params.emplace_back( new PARAM<wxString>( "meta.name", &m_displayName, "KiCad Default" ) ); m_params.emplace_back( new PARAM<wxString>( "meta.name", &m_displayName, "KiCad Default" ) );

View File

@ -249,11 +249,12 @@ public:
}; };
COLOR_SETTINGS* SETTINGS_MANAGER::registerColorSettings( const wxString& aName ) COLOR_SETTINGS* SETTINGS_MANAGER::registerColorSettings( const wxString& aName, bool aAbsolutePath )
{ {
if( !m_color_settings.count( aName ) ) if( !m_color_settings.count( aName ) )
{ {
COLOR_SETTINGS* colorSettings = RegisterSettings( new COLOR_SETTINGS( aName ) ); COLOR_SETTINGS* colorSettings = RegisterSettings( new COLOR_SETTINGS( aName,
aAbsolutePath ) );
m_color_settings[aName] = colorSettings; m_color_settings[aName] = colorSettings;
} }
@ -303,27 +304,25 @@ void SETTINGS_MANAGER::loadAllColorSettings()
wxDir third_party_colors_dir( third_party_path.GetFullPath() ); wxDir third_party_colors_dir( third_party_path.GetFullPath() );
wxString color_settings_path = GetColorSettingsPath(); wxString color_settings_path = GetColorSettingsPath();
JSON_DIR_TRAVERSER copier(
[&]( const wxFileName& aFilename )
{
wxFileName new_file( color_settings_path, aFilename.GetFullName() );
if( !new_file.Exists() )
wxCopyFile( aFilename.GetFullPath(), new_file.GetFullPath());
} );
// Search for and load any other settings // Search for and load any other settings
JSON_DIR_TRAVERSER loader( [&]( const wxFileName& aFilename ) JSON_DIR_TRAVERSER loader( [&]( const wxFileName& aFilename )
{ {
registerColorSettings( aFilename.GetName() ); registerColorSettings( aFilename.GetName() );
} ); } );
JSON_DIR_TRAVERSER thirdPartyLoader(
[&]( const wxFileName& aFilename )
{
COLOR_SETTINGS* settings = registerColorSettings( aFilename.GetFullPath(), true );
settings->SetReadOnly( true );
} );
wxDir colors_dir( color_settings_path ); wxDir colors_dir( color_settings_path );
if( colors_dir.IsOpened() ) if( colors_dir.IsOpened() )
{ {
if( third_party_colors_dir.IsOpened() ) if( third_party_colors_dir.IsOpened() )
third_party_colors_dir.Traverse( copier ); third_party_colors_dir.Traverse( thirdPartyLoader );
colors_dir.Traverse( loader ); colors_dir.Traverse( loader );
} }

View File

@ -58,7 +58,8 @@ public:
*/ */
std::vector<COLOR4D> m_Palette; std::vector<COLOR4D> m_Palette;
explicit COLOR_SETTINGS( const wxString& aFilename = wxT( "user" ) ); explicit COLOR_SETTINGS( const wxString& aFilename = wxT( "user" ),
bool aAbsolutePath = false );
virtual ~COLOR_SETTINGS() {} virtual ~COLOR_SETTINGS() {}

View File

@ -75,6 +75,7 @@ public:
void SetFilename( const wxString& aFilename ) { m_filename = aFilename; } void SetFilename( const wxString& aFilename ) { m_filename = aFilename; }
void SetLocation( SETTINGS_LOC aLocation ) { m_location = aLocation; }
SETTINGS_LOC GetLocation() const { return m_location; } SETTINGS_LOC GetLocation() const { return m_location; }
void SetLegacyFilename( const wxString& aFilename ) { m_legacy_filename = aFilename; } void SetLegacyFilename( const wxString& aFilename ) { m_legacy_filename = aFilename; }

View File

@ -390,7 +390,7 @@ private:
*/ */
COLOR_SETTINGS* loadColorSettingsByName( const wxString& aName ); COLOR_SETTINGS* loadColorSettingsByName( const wxString& aName );
COLOR_SETTINGS* registerColorSettings( const wxString& aFilename ); COLOR_SETTINGS* registerColorSettings( const wxString& aFilename, bool aAbsolutePath = false );
void loadAllColorSettings(); void loadAllColorSettings();