7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-07 21:55:32 +00:00

Use a persistent flag to track JSON modifications

This commit is contained in:
Jon Evans 2024-10-31 08:37:19 -04:00
parent 6e5aad204c
commit eb6d85bacf
2 changed files with 12 additions and 5 deletions
common/settings
include/settings

View File

@ -73,6 +73,7 @@ JSON_SETTINGS::JSON_SETTINGS( const wxString& aFilename, SETTINGS_LOC aLocation,
m_createIfMissing( aCreateIfMissing ),
m_createIfDefault( aCreateIfDefault ),
m_writeFile( aWriteFile ),
m_modified( false ),
m_deleteLegacyAfterMigration( true ),
m_resetParamsIfMissing( true ),
m_schemaVersion( aSchemaVersion ),
@ -351,6 +352,8 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory )
wxLogTrace( traceSettings, wxT( "Loaded <%s> with schema %d" ), GetFullFilename(),
m_schemaVersion );
m_modified = false;
// If we migrated, clean up the legacy file (with no extension)
if( m_writeFile && ( legacy_migrated || migrated ) )
{
@ -371,15 +374,13 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory )
bool JSON_SETTINGS::Store()
{
bool modified = false;
for( PARAM_BASE* param : m_params )
{
modified |= !param->MatchesFile( *this );
m_modified |= !param->MatchesFile( *this );
param->Store( this );
}
return modified;
return m_modified;
}
@ -502,6 +503,9 @@ bool JSON_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce )
success = false;
}
if( success )
m_modified = false;
return success;
}

View File

@ -109,7 +109,7 @@ public:
/**
* Stores the current parameters into the JSON document represented by this object
* Note: this doesn't do any writing to disk; that's handled by SETTINGS_MANAGER
* @return true if any part of the JSON document was updated
* @return true if any part of the JSON document has been updated since the last save to disk
*/
virtual bool Store();
@ -327,6 +327,9 @@ protected:
/// Whether or not the backing store file should be written
bool m_writeFile;
/// True if the JSON data store has been written to since the last file write
bool m_modified;
/// Whether or not to delete legacy file after migration
bool m_deleteLegacyAfterMigration;