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" ) )
92 void FlushAndRelease(
JSON_SETTINGS* aSettings,
bool aSave =
true );
97 void ResetToDefaults();
102 void ClearFileHistory();
122 size_t typeHash =
typeid(
T ).hash_code();
130#if defined(__clang__)
132 [&](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
134 return aSettings->GetFilename() == aFilename;
138 [](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
140 return dynamic_cast<T*>( aSettings.get() );
148 ret =
static_cast<T*
>( it->get() );
152 wxFAIL_MSG(
"Tried to GetAppSettings before registering" );
177#if defined(__clang__)
179 [&](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
181 return aSettings->GetFilename() == aFilename;
185 [](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
187 return dynamic_cast<T*>( aSettings.get() );
195 ret =
static_cast<T*
>( it->get() );
217 std::vector<COLOR_SETTINGS*> ret;
219 for(
const std::pair<const wxString, COLOR_SETTINGS*>& entry :
m_color_settings )
220 ret.push_back( entry.second );
224 return a->GetName() < b->GetName();
239 void SaveColorSettings(
COLOR_SETTINGS* aSettings,
const std::string& aNamespace =
"" );
287 bool MigrateIfNeeded();
308 bool GetPreviousVersionPaths( std::vector<wxString>* aName =
nullptr );
313 void ReloadColorSettings();
322 bool LoadProject(
const wxString& aFullPath,
bool aSetActive =
true );
331 bool UnloadProject(
PROJECT* aProject,
bool aSave =
true );
340 bool IsProjectOpen()
const;
347 bool IsProjectOpenNotDummy()
const;
362 PROJECT* GetProject(
const wxString& aFullPath )
const;
367 std::vector<wxString> GetOpenProjects()
const;
376 bool SaveProject(
const wxString& aFullPath = wxEmptyString,
PROJECT* aProject =
nullptr );
387 void SaveProjectAs(
const wxString& aFullPath,
PROJECT* aProject =
nullptr );
397 void SaveProjectCopy(
const wxString& aFullPath,
PROJECT* aProject =
nullptr );
402 wxString GetProjectBackupsPath()
const;
412 bool BackupProject(
REPORTER& aReporter, wxFileName& aTarget )
const;
420 bool TriggerBackupIfNeeded(
REPORTER& aReporter )
const;
431 static bool IsSettingsPathValid(
const wxString& aPath );
437 static wxString GetColorSettingsPath();
443 static wxString GetToolbarSettingsPath();
451 static std::string GetSettingsVersion();
456 static wxString GetUserSettingsPath();
466 static int compareVersions(
const std::string& aFirst,
const std::string& aSecond );
476 static bool extractVersion(
const std::string& aVersionString,
int* aMajor =
nullptr,
477 int* aMinor =
nullptr );
487 COLOR_SETTINGS* registerColorSettings(
const wxString& aFilename,
bool aAbsolutePath =
false );
489 void loadAllColorSettings();
497 bool loadProjectFile(
PROJECT& aProject );
506 bool unloadProjectFile(
PROJECT* aProject,
bool aSave );
509 void registerBuiltinColorSettings();
555 return pgm->GetSettingsManager().GetAppSettings<
T>( aFilename );
565 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)
JSON_SETTINGS * registerSettings(JSON_SETTINGS *aSettings, bool aLoadNow=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.
SETTINGS_MANAGER(bool aHeadless=false)
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)