21#ifndef _SETTINGS_MANAGER_H
22#define _SETTINGS_MANAGER_H
36class wxSingleInstanceChecker;
42#define PROJECT_BACKUPS_DIR_SUFFIX wxT( "-backups" )
55 bool IsOK() {
return m_ok; }
73 return static_cast<T*
>( registerSettings( aSettings, aLoadNow ) );
89 void FlushAndRelease(
JSON_SETTINGS* aSettings,
bool aSave =
true );
107 size_t typeHash =
typeid( T ).hash_code();
109 if( m_app_settings_cache.count( typeHash ) )
110 ret =
static_cast<T*
>( m_app_settings_cache.at( typeHash ) );
115#if defined(__clang__)
116 auto it = std::find_if( m_settings.begin(), m_settings.end(),
117 [&](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
119 return aSettings->GetFilename() == aFilename;
122 auto it = std::find_if( m_settings.begin(), m_settings.end(),
123 [](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
125 return dynamic_cast<T*>( aSettings.get() );
129 if( it != m_settings.end() )
131 ret =
dynamic_cast<T*
>( it->get() );
135 throw std::runtime_error(
"Tried to GetAppSettings before registering" );
138 m_app_settings_cache[typeHash] = ret;
151 COLOR_SETTINGS* GetColorSettings(
const wxString& aName =
"user" );
155 std::vector<COLOR_SETTINGS*> ret;
157 for(
const std::pair<const wxString, COLOR_SETTINGS*>& entry : m_color_settings )
158 ret.push_back( entry.second );
162 return a->GetName() < b->GetName();
177 void SaveColorSettings(
COLOR_SETTINGS* aSettings,
const std::string& aNamespace =
"" );
225 bool MigrateIfNeeded();
246 bool GetPreviousVersionPaths( std::vector<wxString>* aName =
nullptr );
251 void ReloadColorSettings();
260 bool LoadProject(
const wxString& aFullPath,
bool aSetActive =
true );
269 bool UnloadProject(
PROJECT* aProject,
bool aSave =
true );
278 bool IsProjectOpen()
const;
285 bool IsProjectOpenNotDummy()
const;
300 PROJECT* GetProject(
const wxString& aFullPath )
const;
305 std::vector<wxString> GetOpenProjects()
const;
314 bool SaveProject(
const wxString& aFullPath = wxEmptyString,
PROJECT* aProject =
nullptr );
325 void SaveProjectAs(
const wxString& aFullPath,
PROJECT* aProject =
nullptr );
335 void SaveProjectCopy(
const wxString& aFullPath,
PROJECT* aProject =
nullptr );
340 wxString GetProjectBackupsPath()
const;
350 bool BackupProject(
REPORTER& aReporter, wxFileName& aTarget )
const;
358 bool TriggerBackupIfNeeded(
REPORTER& aReporter )
const;
369 static bool IsSettingsPathValid(
const wxString& aPath );
375 static wxString GetColorSettingsPath();
383 static std::string GetSettingsVersion();
388 static wxString GetUserSettingsPath();
398 static int compareVersions(
const std::string& aFirst,
const std::string& aSecond );
408 static bool extractVersion(
const std::string& aVersionString,
int* aMajor =
nullptr,
409 int* aMinor =
nullptr );
419 COLOR_SETTINGS* registerColorSettings(
const wxString& aFilename,
bool aAbsolutePath =
false );
421 void loadAllColorSettings();
429 bool loadProjectFile(
PROJECT& aProject );
438 bool unloadProjectFile(
PROJECT* aProject,
bool aSave );
441 void registerBuiltinColorSettings();
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...
The backing store for a PROJECT, in JSON format.
Container for project specific data.
A pure virtual class used to derive REPORTER objects from.
std::unique_ptr< LOCKFILE > m_project_lock
Lock for loaded project (expand to multiple once we support MDI).
void SetMigrateLibraryTables(bool aMigrate=true)
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
wxString m_migration_source
std::map< wxString, PROJECT * > m_projects
Loaded projects, mapped according to project full name.
bool m_headless
True if running outside a UI context.
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.
T * GetAppSettings(const wxString &aFilename)
Return a handle to the a given settings by type.
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.