21#ifndef _SETTINGS_MANAGER_H
22#define _SETTINGS_MANAGER_H
37class wxSingleInstanceChecker;
43#define PROJECT_BACKUPS_DIR_SUFFIX wxT( "-backups" )
45#define DEFAULT_THEME wxString( wxT( "user" ) )
58 bool IsOK() {
return m_ok; }
76 return static_cast<T*
>( registerSettings( aSettings, aLoadNow ) );
92 void FlushAndRelease(
JSON_SETTINGS* aSettings,
bool aSave =
true );
109 std::lock_guard lock( m_app_settings_mutex );
112 size_t typeHash =
typeid(
T ).hash_code();
114 if( m_app_settings_cache.count( typeHash ) )
115 ret =
static_cast<T*
>( m_app_settings_cache.at( typeHash ) );
120#if defined(__clang__)
121 auto it = std::find_if( m_settings.begin(), m_settings.end(),
122 [&](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
124 return aSettings->GetFilename() == aFilename;
127 auto it = std::find_if( m_settings.begin(), m_settings.end(),
128 [](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
130 return dynamic_cast<T*>( aSettings.get() );
134 if( it != m_settings.end() )
138 ret =
static_cast<T*
>( it->get() );
142 wxFAIL_MSG(
"Tried to GetAppSettings before registering" );
145 m_app_settings_cache[typeHash] = ret;
167#if defined(__clang__)
168 auto it = std::find_if( m_settings.begin(), m_settings.end(),
169 [&](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
171 return aSettings->GetFilename() == aFilename;
174 auto it = std::find_if( m_settings.begin(), m_settings.end(),
175 [](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
177 return dynamic_cast<T*>( aSettings.get() );
181 if( it != m_settings.end() )
185 ret =
static_cast<T*
>( it->get() );
189 ret = RegisterSettings(
new T );
207 std::vector<COLOR_SETTINGS*> ret;
209 for(
const std::pair<const wxString, COLOR_SETTINGS*>& entry : m_color_settings )
210 ret.push_back( entry.second );
214 return a->GetName() < b->GetName();
229 void SaveColorSettings(
COLOR_SETTINGS* aSettings,
const std::string& aNamespace =
"" );
277 bool MigrateIfNeeded();
298 bool GetPreviousVersionPaths( std::vector<wxString>* aName =
nullptr );
303 void ReloadColorSettings();
312 bool LoadProject(
const wxString& aFullPath,
bool aSetActive =
true );
321 bool UnloadProject(
PROJECT* aProject,
bool aSave =
true );
330 bool IsProjectOpen()
const;
337 bool IsProjectOpenNotDummy()
const;
352 PROJECT* GetProject(
const wxString& aFullPath )
const;
357 std::vector<wxString> GetOpenProjects()
const;
366 bool SaveProject(
const wxString& aFullPath = wxEmptyString,
PROJECT* aProject =
nullptr );
377 void SaveProjectAs(
const wxString& aFullPath,
PROJECT* aProject =
nullptr );
387 void SaveProjectCopy(
const wxString& aFullPath,
PROJECT* aProject =
nullptr );
392 wxString GetProjectBackupsPath()
const;
402 bool BackupProject(
REPORTER& aReporter, wxFileName& aTarget )
const;
410 bool TriggerBackupIfNeeded(
REPORTER& aReporter )
const;
421 static bool IsSettingsPathValid(
const wxString& aPath );
427 static wxString GetColorSettingsPath();
433 static wxString GetToolbarSettingsPath();
441 static std::string GetSettingsVersion();
446 static wxString GetUserSettingsPath();
456 static int compareVersions(
const std::string& aFirst,
const std::string& aSecond );
466 static bool extractVersion(
const std::string& aVersionString,
int* aMajor =
nullptr,
467 int* aMinor =
nullptr );
477 COLOR_SETTINGS* registerColorSettings(
const wxString& aFilename,
bool aAbsolutePath =
false );
479 void loadAllColorSettings();
487 bool loadProjectFile(
PROJECT& aProject );
496 bool unloadProjectFile(
PROJECT* aProject,
bool aSave );
499 void registerBuiltinColorSettings();
545 return pgm->GetSettingsManager().GetAppSettings<
T>( aFilename );
555 return pgm->GetSettingsManager().GetToolbarSettings<
T>( aFilename );
KICAD_PLUGIN_EXPORT SCENEGRAPH * Load(char const *aFileName)
Read a model file and creates a generic display structure.
Color settings are a bit different than most of the settings objects in that there can be more than o...
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Container for data for KiCad programs.
virtual SETTINGS_MANAGER & GetSettingsManager() const
The backing store for a PROJECT, in JSON format.
Container for project specific data.
A pure virtual class used to derive REPORTER objects from.
T * GetAppSettings(const char *aFilename)
Return a handle to the a given settings by type.
void SetMigrateLibraryTables(bool aMigrate=true)
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
wxString m_migration_source
T * GetToolbarSettings(const wxString &aFilename)
Return a handle to the given toolbar settings.
std::map< wxString, PROJECT * > m_projects
Loaded projects, mapped according to project full name.
bool m_headless
True if running outside a UI context.
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
Retrieve a color settings object that applications can read colors from.
COMMON_SETTINGS * GetCommonSettings() const
Retrieve the common settings shared by all applications.
void SetMigrationSource(const wxString &aSource)
Helper for DIALOG_MIGRATE_SETTINGS to specify a source for migration.
std::mutex m_app_settings_mutex
std::map< wxString, PROJECT_FILE * > m_project_files
Loaded project files, mapped according to project full name.
std::unordered_map< wxString, COLOR_SETTINGS * > m_color_settings
void SetKiway(KIWAY *aKiway)
Associate this setting manager with the given Kiway.
std::vector< COLOR_SETTINGS * > GetColorSettingsList()
std::vector< std::unique_ptr< PROJECT > > m_projects_list
Loaded projects (ownership here).
std::vector< std::unique_ptr< JSON_SETTINGS > > m_settings
bool m_migrateLibraryTables
If true, the symbol and footprint library tables will be migrated from the previous version.
std::unordered_map< size_t, JSON_SETTINGS * > m_app_settings_cache
Cache for app settings.
bool m_ok
True if settings loaded successfully at construction.
static wxString backupDateTimeFormat
COMMON_SETTINGS * m_common_settings
KIWAY * m_kiway
The kiway this settings manager interacts with.
PGM_BASE & Pgm()
The global program "get" accessor.
PGM_BASE * PgmOrNull()
Return a reference that can be nullptr when running a shared lib from a script, not from a kicad app.
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
T * GetToolbarSettings(const wxString &aFilename)
T * GetAppSettings(const char *aFilename)