21#ifndef _SETTINGS_MANAGER_H
22#define _SETTINGS_MANAGER_H
42#define PROJECT_BACKUPS_DIR_SUFFIX wxT( "-backups" )
44#define DEFAULT_THEME wxString( wxT( "user" ) )
98 void FlushAndRelease(
JSON_SETTINGS* aSettings,
bool aSave =
true );
103 void ResetToDefaults();
108 void ClearFileHistory();
128 size_t typeHash =
typeid(
T ).hash_code();
136#if defined(__clang__)
138 [&](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
140 return aSettings->GetFilename() == aFilename;
144 [](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
146 return dynamic_cast<T*>( aSettings.get() );
154 ret =
static_cast<T*
>( it->get() );
158 wxFAIL_MSG( wxString::Format(
"Tried to GetAppSettings before registering: %s", aFilename ) );
183#if defined(__clang__)
185 [&](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
187 return aSettings->GetFilename() == aFilename;
191 [](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
193 return dynamic_cast<T*>( aSettings.get() );
201 ret =
static_cast<T*
>( it->get() );
221 std::vector<COLOR_SETTINGS*> GetColorSettingsList();
232 void SaveColorSettings(
COLOR_SETTINGS* aSettings,
const std::string& aNamespace =
"" );
272 bool MigrateFromPreviousVersion(
const wxString& aSourcePath );
284 bool GetPreviousVersionPaths( std::vector<wxString>* aName =
nullptr );
289 void ReloadColorSettings();
298 bool LoadProject(
const wxString& aFullPath,
bool aSetActive =
true );
307 bool UnloadProject(
PROJECT* aProject,
bool aSave =
true );
316 bool IsProjectOpen()
const;
323 bool IsProjectOpenNotDummy()
const;
338 PROJECT* GetProject(
const wxString& aFullPath )
const;
345 bool IsProjectLoaded(
PROJECT* aProject )
const;
352 PROJECT* GetProjectForPath(
const wxString& aProjectPath )
const;
357 std::vector<wxString> GetOpenProjects()
const;
362 void SyncGlobalFieldNameTemplatesToProjects();
371 bool SaveProject(
const wxString& aFullPath = wxEmptyString,
PROJECT* aProject =
nullptr );
382 void SaveProjectAs(
const wxString& aFullPath,
PROJECT* aProject =
nullptr );
393 bool SaveProjectCopy(
const wxString& aFullPath,
PROJECT* aProject =
nullptr );
398 wxString GetProjectBackupsPath()
const;
410 wxString GetBackupRootForProject(
const PROJECT* aProject =
nullptr )
const;
417 wxString GetLocalHistoryDirForProject(
const PROJECT* aProject =
nullptr )
const;
425 wxString GetLocalHistoryDirForPath(
const wxString& aProjectPath )
const;
434 wxString GetAutosaveRootForProject(
const PROJECT* aProject =
nullptr )
const;
444 bool BackupProject(
REPORTER& aReporter, wxFileName& aTarget )
const;
452 bool TriggerBackupIfNeeded(
REPORTER& aReporter )
const;
463 static bool IsSettingsPathValid(
const wxString& aPath );
469 static wxString GetColorSettingsPath();
475 static wxString GetToolbarSettingsPath();
483 static std::string GetSettingsVersion();
488 static wxString GetUserSettingsPath();
498 static int compareVersions(
const std::string& aFirst,
const std::string& aSecond );
508 static bool extractVersion(
const std::string& aVersionString,
int* aMajor =
nullptr,
509 int* aMinor =
nullptr );
519 COLOR_SETTINGS* registerColorSettings(
const wxString& aFilename,
bool aAbsolutePath =
false );
521 void loadAllColorSettings();
528 static wxString projectKeySuffix(
const PROJECT* aProject );
541 bool loadProjectFile(
PROJECT& aProject );
550 bool unloadProjectFile(
PROJECT* aProject,
bool aSave );
553 void registerBuiltinColorSettings();
594 return pgm->GetSettingsManager().GetAppSettings<
T>( aFilename );
604 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...
Advisory lock over a file, taken by writing a sibling lock file and holding an exclusive lock on it f...
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.
JSON_SETTINGS * registerSettings(JSON_SETTINGS *aSettings, bool aLoadNow=true)
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
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.
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.
std::mutex m_app_settings_mutex
bool SettingsDirectoryValid() const
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< 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)