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; }
72 return static_cast<T*
>( registerSettings( aSettings, aLoadNow ) );
87 void FlushAndRelease(
JSON_SETTINGS* aSettings,
bool aSave =
true );
103 size_t typeHash =
typeid( T ).hash_code();
105 if( m_app_settings_cache.count( typeHash ) )
106 ret =
static_cast<T*
>( m_app_settings_cache.at( typeHash ) );
111 auto it = std::find_if( m_settings.begin(), m_settings.end(),
112 [](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
114 return dynamic_cast<T*>( aSettings.get() );
117 if( it != m_settings.end() )
119 ret =
dynamic_cast<T*
>( it->get() );
123 throw std::runtime_error(
"Tried to GetAppSettings before registering" );
126 m_app_settings_cache[typeHash] = ret;
135 return GetAppSettings<T>();
138 size_t typeHash =
typeid( T ).hash_code();
140 if( m_app_settings_cache.count( typeHash ) )
141 ret =
static_cast<T*
>( m_app_settings_cache.at( typeHash ) );
146 auto it = std::find_if( m_settings.begin(), m_settings.end(),
147 [&](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
149 return aSettings->GetFilename() == aFilename;
152 if( it != m_settings.end() )
154 ret =
static_cast<T*
>( it->get() );
158 throw std::runtime_error(
"Tried to GetAppSettings before registering" );
161 m_app_settings_cache[typeHash] = ret;
174 COLOR_SETTINGS* GetColorSettings(
const wxString& aName =
"user" );
178 std::vector<COLOR_SETTINGS*> ret;
180 for(
const std::pair<const wxString, COLOR_SETTINGS*>& entry : m_color_settings )
181 ret.push_back( entry.second );
185 return a->GetName() < b->GetName();
200 void SaveColorSettings(
COLOR_SETTINGS* aSettings,
const std::string& aNamespace =
"" );
242 bool MigrateIfNeeded();
260 bool GetPreviousVersionPaths( std::vector<wxString>* aName =
nullptr );
265 void ReloadColorSettings();
273 bool LoadProject(
const wxString& aFullPath,
bool aSetActive =
true );
281 bool UnloadProject(
PROJECT* aProject,
bool aSave =
true );
288 bool IsProjectOpen()
const;
294 bool IsProjectOpenNotDummy()
const;
307 PROJECT* GetProject(
const wxString& aFullPath )
const;
312 std::vector<wxString> GetOpenProjects()
const;
320 bool SaveProject(
const wxString& aFullPath = wxEmptyString,
PROJECT* aProject =
nullptr );
329 void SaveProjectAs(
const wxString& aFullPath,
PROJECT* aProject =
nullptr );
337 void SaveProjectCopy(
const wxString& aFullPath,
PROJECT* aProject =
nullptr );
342 wxString GetProjectBackupsPath()
const;
351 bool BackupProject(
REPORTER& aReporter, wxFileName& aTarget )
const;
358 bool TriggerBackupIfNeeded(
REPORTER& aReporter )
const;
368 static bool IsSettingsPathValid(
const wxString& aPath );
374 static wxString GetColorSettingsPath();
382 static std::string GetSettingsVersion();
387 static wxString GetUserSettingsPath();
395 static int compareVersions(
const std::string& aFirst,
const std::string& aSecond );
404 static bool extractVersion(
const std::string& aVersionString,
int* aMajor =
nullptr,
405 int* aMinor =
nullptr );
414 COLOR_SETTINGS* registerColorSettings(
const wxString& aFilename,
bool aAbsolutePath =
false );
416 void loadAllColorSettings();
423 bool loadProjectFile(
PROJECT& aProject );
431 bool unloadProjectFile(
PROJECT* aProject,
bool aSave );
434 void registerBuiltinColorSettings();
KICAD_PLUGIN_EXPORT SCENEGRAPH * Load(char const *aFileName)
reads 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 * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes 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
Retrieves 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)
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.