Formatting.
This commit is contained in:
parent
7f29ac39d8
commit
445ed380b8
|
@ -100,7 +100,7 @@ JSON_SETTINGS::JSON_SETTINGS( const wxString& aFilename, SETTINGS_LOC aLocation,
|
|||
|
||||
JSON_SETTINGS::~JSON_SETTINGS()
|
||||
{
|
||||
for( auto param: m_params )
|
||||
for( PARAM_BASE* param: m_params )
|
||||
delete param;
|
||||
|
||||
m_params.clear();
|
||||
|
@ -136,7 +136,7 @@ JSON_SETTINGS_INTERNALS* JSON_SETTINGS::Internals()
|
|||
|
||||
void JSON_SETTINGS::Load()
|
||||
{
|
||||
for( auto param : m_params )
|
||||
for( PARAM_BASE* param : m_params )
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -163,8 +163,11 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory )
|
|||
|
||||
LOCALE_IO locale;
|
||||
|
||||
auto migrateFromLegacy = [&] ( wxFileName& aPath ) {
|
||||
// Backup and restore during migration so that the original can be mutated if convenient
|
||||
auto migrateFromLegacy =
|
||||
[&] ( wxFileName& aPath )
|
||||
{
|
||||
// Backup and restore during migration so that the original can be mutated if
|
||||
// convenient
|
||||
bool backed_up = false;
|
||||
wxFileName temp;
|
||||
|
||||
|
@ -174,21 +177,25 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory )
|
|||
|
||||
if( !wxCopyFile( aPath.GetFullPath(), temp.GetFullPath() ) )
|
||||
{
|
||||
wxLogTrace( traceSettings, wxT( "%s: could not create temp file for migration" ),
|
||||
wxLogTrace( traceSettings,
|
||||
wxT( "%s: could not create temp file for migration" ),
|
||||
GetFullFilename() );
|
||||
}
|
||||
else
|
||||
{
|
||||
backed_up = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Silence popups if legacy file is read-only
|
||||
wxLogNull doNotLog;
|
||||
|
||||
wxConfigBase::DontCreateOnDemand();
|
||||
auto cfg = std::make_unique<wxFileConfig>( wxT( "" ), wxT( "" ), aPath.GetFullPath() );
|
||||
auto cfg = std::make_unique<wxFileConfig>( wxT( "" ), wxT( "" ),
|
||||
aPath.GetFullPath() );
|
||||
|
||||
// If migrate fails or is not implemented, fall back to built-in defaults that were
|
||||
// already loaded above
|
||||
// If migrate fails or is not implemented, fall back to built-in defaults that
|
||||
// were already loaded above
|
||||
if( !MigrateFromLegacy( cfg.get() ) )
|
||||
{
|
||||
success = false;
|
||||
|
@ -211,7 +218,8 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory )
|
|||
{
|
||||
wxLogTrace( traceSettings,
|
||||
wxT( "migrate; copy temp file %s to %s failed" ),
|
||||
temp.GetFullPath(), aPath.GetFullPath() );
|
||||
temp.GetFullPath(),
|
||||
aPath.GetFullPath() );
|
||||
}
|
||||
|
||||
if( !wxRemoveFile( temp.GetFullPath() ) )
|
||||
|
@ -339,7 +347,7 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory )
|
|||
Load();
|
||||
|
||||
// And finally load any nested settings
|
||||
for( auto settings : m_nested_settings )
|
||||
for( NESTED_SETTINGS* settings : m_nested_settings )
|
||||
settings->LoadFromFile();
|
||||
|
||||
wxLogTrace( traceSettings, wxT( "Loaded <%s> with schema %d" ), GetFullFilename(),
|
||||
|
@ -367,7 +375,7 @@ bool JSON_SETTINGS::Store()
|
|||
{
|
||||
bool modified = false;
|
||||
|
||||
for( auto param : m_params )
|
||||
for( PARAM_BASE* param : m_params )
|
||||
{
|
||||
modified |= !param->MatchesFile( this );
|
||||
param->Store( this );
|
||||
|
@ -379,7 +387,7 @@ bool JSON_SETTINGS::Store()
|
|||
|
||||
void JSON_SETTINGS::ResetToDefaults()
|
||||
{
|
||||
for( auto param : m_params )
|
||||
for( PARAM_BASE* param : m_params )
|
||||
param->SetDefault();
|
||||
}
|
||||
|
||||
|
@ -432,7 +440,7 @@ bool JSON_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce )
|
|||
|
||||
bool modified = false;
|
||||
|
||||
for( auto settings : m_nested_settings )
|
||||
for( NESTED_SETTINGS* settings : m_nested_settings )
|
||||
modified |= settings->SaveToFile();
|
||||
|
||||
modified |= Store();
|
||||
|
@ -832,7 +840,8 @@ void JSON_SETTINGS::ReleaseNestedSettings( NESTED_SETTINGS* aSettings )
|
|||
return;
|
||||
|
||||
auto it = std::find_if( m_nested_settings.begin(), m_nested_settings.end(),
|
||||
[&aSettings]( const JSON_SETTINGS* aPtr ) {
|
||||
[&aSettings]( const JSON_SETTINGS* aPtr )
|
||||
{
|
||||
return aPtr == aSettings;
|
||||
} );
|
||||
|
||||
|
|
|
@ -311,13 +311,13 @@ void PARAM_WXSTRING_MAP::Load( JSON_SETTINGS* aSettings, bool aResetIfMissing )
|
|||
m_ptr->clear();
|
||||
|
||||
for( const auto& el : js->items() )
|
||||
{
|
||||
( *m_ptr )[wxString( el.key().c_str(), wxConvUTF8 )] = el.value().get<wxString>();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( aResetIfMissing )
|
||||
{
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ public:
|
|||
/**
|
||||
* Calls Store() and then writes the contents of the JSON document to a file
|
||||
* @param aDirectory is the directory to save to, including trailing separator
|
||||
c * @return true if the file was saved
|
||||
* @return true if the file was saved
|
||||
*/
|
||||
virtual bool SaveToFile( const wxString& aDirectory = "", bool aForce = false );
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
|
||||
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2020-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
|
@ -18,8 +18,8 @@
|
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _PARAMETERS_H
|
||||
#define _PARAMETERS_H
|
||||
#ifndef PARAMETERS_H
|
||||
#define PARAMETERS_H
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
@ -69,13 +69,8 @@ public:
|
|||
const std::string& GetJsonPath() const { return m_path; }
|
||||
|
||||
protected:
|
||||
/**
|
||||
* the string used to store the param in json files
|
||||
*/
|
||||
std::string m_path;
|
||||
|
||||
///! True if the parameter pointer should never be overwritten
|
||||
bool m_readOnly;
|
||||
std::string m_path; ///< Address of the param in the json files
|
||||
bool m_readOnly; ///< Indicates param pointer should never be overwritten
|
||||
};
|
||||
|
||||
|
||||
|
@ -121,8 +116,10 @@ public:
|
|||
*m_ptr = val;
|
||||
}
|
||||
else if( aResetIfMissing )
|
||||
{
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
}
|
||||
|
||||
void Store( JSON_SETTINGS* aSettings ) const override
|
||||
{
|
||||
|
@ -240,8 +237,10 @@ public:
|
|||
|
||||
}
|
||||
else if( aResetIfMissing )
|
||||
{
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
}
|
||||
|
||||
void Store( JSON_SETTINGS* aSettings ) const override
|
||||
{
|
||||
|
@ -317,9 +316,7 @@ public:
|
|||
|
||||
private:
|
||||
ValueType m_default;
|
||||
|
||||
std::function<ValueType()> m_getter;
|
||||
|
||||
std::function<void( ValueType )> m_setter;
|
||||
};
|
||||
|
||||
|
@ -442,7 +439,6 @@ public:
|
|||
|
||||
protected:
|
||||
std::vector<Type>* m_ptr;
|
||||
|
||||
std::vector<Type> m_default;
|
||||
};
|
||||
|
||||
|
@ -477,7 +473,6 @@ public:
|
|||
|
||||
protected:
|
||||
std::set<Type>* m_ptr;
|
||||
|
||||
std::set<Type> m_default;
|
||||
};
|
||||
|
||||
|
@ -568,7 +563,6 @@ public:
|
|||
|
||||
private:
|
||||
std::map<std::string, Value>* m_ptr;
|
||||
|
||||
std::map<std::string, Value> m_default;
|
||||
};
|
||||
|
||||
|
@ -600,7 +594,6 @@ public:
|
|||
|
||||
private:
|
||||
std::map<wxString, wxString>* m_ptr;
|
||||
|
||||
std::map<wxString, wxString> m_default;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue