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" ) )
99 void FlushAndRelease(
JSON_SETTINGS* aSettings,
bool aSave =
true );
104 void ResetToDefaults();
109 void ClearFileHistory();
129 size_t typeHash =
typeid(
T ).hash_code();
137#if defined(__clang__)
139 [&](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
141 return aSettings->GetFilename() == aFilename;
145 [](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
147 return dynamic_cast<T*>( aSettings.get() );
155 ret =
static_cast<T*
>( it->get() );
159 wxFAIL_MSG(
"Tried to GetAppSettings before registering" );
184#if defined(__clang__)
186 [&](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
188 return aSettings->GetFilename() == aFilename;
192 [](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
194 return dynamic_cast<T*>( aSettings.get() );
202 ret =
static_cast<T*
>( it->get() );
224 std::vector<COLOR_SETTINGS*> ret;
226 for(
const std::pair<const wxString, COLOR_SETTINGS*>& entry :
m_color_settings )
227 ret.push_back( entry.second );
231 return a->GetName() < b->GetName();
246 void SaveColorSettings(
COLOR_SETTINGS* aSettings,
const std::string& aNamespace =
"" );
286 bool MigrateFromPreviousVersion(
const wxString& aSourcePath );
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();
540 return pgm->GetSettingsManager().GetAppSettings<
T>( aFilename );
550 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.
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< 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)