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" ) )
100 void FlushAndRelease(
JSON_SETTINGS* aSettings,
bool aSave =
true );
105 void ResetToDefaults();
110 void ClearFileHistory();
130 size_t typeHash =
typeid(
T ).hash_code();
138#if defined(__clang__)
140 [&](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
142 return aSettings->GetFilename() == aFilename;
146 [](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
148 return dynamic_cast<T*>( aSettings.get() );
156 ret =
static_cast<T*
>( it->get() );
160 wxFAIL_MSG( wxString::Format(
"Tried to GetAppSettings before registering: %s", aFilename ) );
185#if defined(__clang__)
187 [&](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
189 return aSettings->GetFilename() == aFilename;
193 [](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
195 return dynamic_cast<T*>( aSettings.get() );
203 ret =
static_cast<T*
>( it->get() );
223 std::vector<COLOR_SETTINGS*> GetColorSettingsList();
234 void SaveColorSettings(
COLOR_SETTINGS* aSettings,
const std::string& aNamespace =
"" );
274 bool MigrateFromPreviousVersion(
const wxString& aSourcePath );
286 bool GetPreviousVersionPaths( std::vector<wxString>* aName =
nullptr );
291 void ReloadColorSettings();
300 bool LoadProject(
const wxString& aFullPath,
bool aSetActive =
true );
309 bool UnloadProject(
PROJECT* aProject,
bool aSave =
true );
318 bool IsProjectOpen()
const;
325 bool IsProjectOpenNotDummy()
const;
340 PROJECT* GetProject(
const wxString& aFullPath )
const;
347 bool IsProjectLoaded(
PROJECT* aProject )
const;
354 PROJECT* GetProjectForPath(
const wxString& aProjectPath )
const;
359 std::vector<wxString> GetOpenProjects()
const;
364 void SyncGlobalFieldNameTemplatesToProjects();
373 bool SaveProject(
const wxString& aFullPath = wxEmptyString,
PROJECT* aProject =
nullptr );
384 void SaveProjectAs(
const wxString& aFullPath,
PROJECT* aProject =
nullptr );
395 bool SaveProjectCopy(
const wxString& aFullPath,
PROJECT* aProject =
nullptr );
400 wxString GetProjectBackupsPath()
const;
412 wxString GetBackupRootForProject(
const PROJECT* aProject =
nullptr )
const;
419 wxString GetLocalHistoryDirForProject(
const PROJECT* aProject =
nullptr )
const;
427 wxString GetLocalHistoryDirForPath(
const wxString& aProjectPath )
const;
436 wxString GetAutosaveRootForProject(
const PROJECT* aProject =
nullptr )
const;
446 bool BackupProject(
REPORTER& aReporter, wxFileName& aTarget )
const;
454 bool TriggerBackupIfNeeded(
REPORTER& aReporter )
const;
465 static bool IsSettingsPathValid(
const wxString& aPath );
471 static wxString GetColorSettingsPath();
477 static wxString GetToolbarSettingsPath();
485 static std::string GetSettingsVersion();
490 static wxString GetUserSettingsPath();
500 static int compareVersions(
const std::string& aFirst,
const std::string& aSecond );
510 static bool extractVersion(
const std::string& aVersionString,
int* aMajor =
nullptr,
511 int* aMinor =
nullptr );
521 COLOR_SETTINGS* registerColorSettings(
const wxString& aFilename,
bool aAbsolutePath =
false );
523 void loadAllColorSettings();
530 static wxString projectKeySuffix(
const PROJECT* aProject );
543 bool loadProjectFile(
PROJECT& aProject );
552 bool unloadProjectFile(
PROJECT* aProject,
bool aSave );
555 void registerBuiltinColorSettings();
596 return pgm->GetSettingsManager().GetAppSettings<
T>( aFilename );
606 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)