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 );
104 size_t typeHash =
typeid( T ).hash_code();
106 if( m_app_settings_cache.count( typeHash ) )
107 ret =
static_cast<T*
>( m_app_settings_cache.at( typeHash ) );
112#if defined(__clang__)
113 auto it = std::find_if( m_settings.begin(), m_settings.end(),
114 [&](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
116 return aSettings->GetFilename() == aFilename;
119 auto it = std::find_if( m_settings.begin(), m_settings.end(),
120 [](
const std::unique_ptr<JSON_SETTINGS>& aSettings )
122 return dynamic_cast<T*>( aSettings.get() );
126 if( it != m_settings.end() )
128 ret =
dynamic_cast<T*
>( it->get() );
132 throw std::runtime_error(
"Tried to GetAppSettings before registering" );
135 m_app_settings_cache[typeHash] = ret;
147 COLOR_SETTINGS* GetColorSettings(
const wxString& aName =
"user" );
151 std::vector<COLOR_SETTINGS*> ret;
153 for(
const std::pair<const wxString, COLOR_SETTINGS*>& entry : m_color_settings )
154 ret.push_back( entry.second );
158 return a->GetName() < b->GetName();
173 void SaveColorSettings(
COLOR_SETTINGS* aSettings,
const std::string& aNamespace =
"" );
215 bool MigrateIfNeeded();
233 bool GetPreviousVersionPaths( std::vector<wxString>* aName =
nullptr );
238 void ReloadColorSettings();
246 bool LoadProject(
const wxString& aFullPath,
bool aSetActive =
true );
254 bool UnloadProject(
PROJECT* aProject,
bool aSave =
true );
261 bool IsProjectOpen()
const;
267 bool IsProjectOpenNotDummy()
const;
280 PROJECT* GetProject(
const wxString& aFullPath )
const;
285 std::vector<wxString> GetOpenProjects()
const;
293 bool SaveProject(
const wxString& aFullPath = wxEmptyString,
PROJECT* aProject =
nullptr );
302 void SaveProjectAs(
const wxString& aFullPath,
PROJECT* aProject =
nullptr );
310 void SaveProjectCopy(
const wxString& aFullPath,
PROJECT* aProject =
nullptr );
315 wxString GetProjectBackupsPath()
const;
324 bool BackupProject(
REPORTER& aReporter, wxFileName& aTarget )
const;
331 bool TriggerBackupIfNeeded(
REPORTER& aReporter )
const;
341 static bool IsSettingsPathValid(
const wxString& aPath );
347 static wxString GetColorSettingsPath();
355 static std::string GetSettingsVersion();
360 static wxString GetUserSettingsPath();
368 static int compareVersions(
const std::string& aFirst,
const std::string& aSecond );
377 static bool extractVersion(
const std::string& aVersionString,
int* aMajor =
nullptr,
378 int* aMinor =
nullptr );
387 COLOR_SETTINGS* registerColorSettings(
const wxString& aFilename,
bool aAbsolutePath =
false );
389 void loadAllColorSettings();
396 bool loadProjectFile(
PROJECT& aProject );
404 bool unloadProjectFile(
PROJECT* aProject,
bool aSave );
407 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 * 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)
Returns a handle to the a given settings by type If the settings have already been loaded,...
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.