KiCad PCB EDA Suite
Loading...
Searching...
No Matches
SETTINGS_MANAGER Class Reference

#include <settings_manager.h>

Public Member Functions

 SETTINGS_MANAGER ()
 
 ~SETTINGS_MANAGER ()
 
bool SettingsDirectoryValid () const
 
bool IsOK ()
 
void SetKiway (KIWAY *aKiway)
 Associate this setting manager with the given Kiway.
 
template<typename T>
TRegisterSettings (T *aSettings, bool aLoadNow=true)
 Take ownership of the pointer passed in.
 
void Load ()
 
void Load (JSON_SETTINGS *aSettings)
 
void Save ()
 
void Save (JSON_SETTINGS *aSettings)
 
void FlushAndRelease (JSON_SETTINGS *aSettings, bool aSave=true)
 If the given settings object is registered, save it to disk and unregister it.
 
void ResetToDefaults ()
 Reset all program settings to defaults.
 
void ClearFileHistory ()
 Clear saved file history from all settings files.
 
template<typename T>
TGetAppSettings (const char *aFilename)
 Return a handle to the a given settings by type.
 
template<typename T>
TGetToolbarSettings (const wxString &aFilename)
 Return a handle to the given toolbar settings.
 
COLOR_SETTINGSGetColorSettings (const wxString &aName)
 Retrieve a color settings object that applications can read colors from.
 
std::vector< COLOR_SETTINGS * > GetColorSettingsList ()
 
void SaveColorSettings (COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
 Safely save a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
 
COLOR_SETTINGSAddNewColorSettings (const wxString &aFilename)
 Register a new color settings object with the given filename.
 
COLOR_SETTINGSGetMigratedColorSettings ()
 Return a color theme for storing colors migrated from legacy (5.x and earlier) settings, creating the theme if necessary.
 
COMMON_SETTINGSGetCommonSettings () const
 Retrieve the common settings shared by all applications.
 
wxString GetPathForSettingsFile (JSON_SETTINGS *aSettings)
 Return the path a given settings file should be loaded from / stored to.
 
bool MigrateFromPreviousVersion (const wxString &aSourcePath)
 Handle migration of the settings from previous KiCad versions.
 
bool GetPreviousVersionPaths (std::vector< wxString > *aName=nullptr)
 Retrieve the name of the most recent previous KiCad version that can be found in the user settings directory.
 
void ReloadColorSettings ()
 Re-scan the color themes directory, reloading any changes it finds.
 
bool LoadProject (const wxString &aFullPath, bool aSetActive=true)
 Load a project or sets up a new project with a specified path.
 
bool UnloadProject (PROJECT *aProject, bool aSave=true)
 Save, unload and unregister the given PROJECT.
 
bool IsProjectOpen () const
 Helper for checking if we have a project open.
 
bool IsProjectOpenNotDummy () const
 Helper for checking if we have a project open that is not a dummy project.
 
PROJECTPrj () const
 A helper while we are not MDI-capable – return the one and only project.
 
PROJECTGetProject (const wxString &aFullPath) const
 Retrieve a loaded project by name.
 
PROJECTGetProjectForPath (const wxString &aProjectPath) const
 Return the active project iff its path matches aProjectPath, else nullptr.
 
std::vector< wxString > GetOpenProjects () const
 
bool SaveProject (const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
 Save a loaded project.
 
void SaveProjectAs (const wxString &aFullPath, PROJECT *aProject=nullptr)
 Set the currently loaded project path and saves it (pointers remain valid).
 
void SaveProjectCopy (const wxString &aFullPath, PROJECT *aProject=nullptr)
 Save a copy of the current project under the given path.
 
wxString GetProjectBackupsPath () const
 
wxString GetBackupRootForProject (const PROJECT *aProject=nullptr) const
 Resolve the backup root directory for a project, honoring the active BACKUP_LOCATION preference.
 
wxString GetLocalHistoryDirForProject (const PROJECT *aProject=nullptr) const
 Resolve the local-history (.history) storage directory for a project.
 
wxString GetLocalHistoryDirForPath (const wxString &aProjectPath) const
 Resolve the local-history directory for a project given by its on-disk path.
 
wxString GetAutosaveRootForProject (const PROJECT *aProject=nullptr) const
 Resolve the autosave-files root for a project.
 
bool BackupProject (REPORTER &aReporter, wxFileName &aTarget) const
 Create a backup archive of the current project.
 
bool TriggerBackupIfNeeded (REPORTER &aReporter) const
 Call BackupProject() if a new backup is needed according to the current backup policy.
 

Static Public Member Functions

static bool IsSettingsPathValid (const wxString &aPath)
 Check if a given path is probably a valid KiCad configuration directory.
 
static wxString GetColorSettingsPath ()
 Return the path where color scheme files are stored; creating it if missing (normally .
 
static wxString GetToolbarSettingsPath ()
 Return the path where toolbar configuration files are stored; creating it if missing (normally .
 
static std::string GetSettingsVersion ()
 Parse the current KiCad build version and extracts the major and minor revision to use as the name of the settings directory for this KiCad version.
 
static wxString GetUserSettingsPath ()
 A proxy for PATHS::GetUserSettingsPath() rather than fighting swig.
 

Private Member Functions

JSON_SETTINGSregisterSettings (JSON_SETTINGS *aSettings, bool aLoadNow=true)
 
COLOR_SETTINGSloadColorSettingsByName (const wxString &aName)
 Attempt to load a color theme by name (the color theme directory and .json ext are assumed).
 
COLOR_SETTINGSregisterColorSettings (const wxString &aFilename, bool aAbsolutePath=false)
 
void loadAllColorSettings ()
 
const PROJECTresolveProject (const PROJECT *aProject) const
 Pick the project to resolve a backup path against, falling back to Prj().
 
bool loadProjectFile (PROJECT &aProject)
 Register a PROJECT_FILE and attempt to load it from disk.
 
bool unloadProjectFile (PROJECT *aProject, bool aSave)
 Optionally save, unload and unregister the given PROJECT_FILE.
 
void registerBuiltinColorSettings ()
 

Static Private Member Functions

static int compareVersions (const std::string &aFirst, const std::string &aSecond)
 Compare two settings versions, like "5.99" and "6.0".
 
static bool extractVersion (const std::string &aVersionString, int *aMajor=nullptr, int *aMinor=nullptr)
 Extract the numeric version from a given settings string.
 
static wxString projectKeySuffix (const PROJECT *aProject)
 Build "<projectname>-<sha256prefix>" suffix used to disambiguate per-project subdirectories under the user data path.
 

Private Attributes

KIWAYm_kiway
 The kiway this settings manager interacts with.
 
std::vector< std::unique_ptr< JSON_SETTINGS > > m_settings
 
std::unordered_map< wxString, COLOR_SETTINGS * > m_color_settings
 
std::unordered_map< size_t, JSON_SETTINGS * > m_app_settings_cache
 Cache for app settings.
 
std::mutex m_app_settings_mutex
 
COMMON_SETTINGSm_common_settings
 
bool m_migrateLibraryTables
 If true, the symbol and footprint library tables will be migrated from the previous version.
 
bool m_ok
 True if settings loaded successfully at construction.
 
std::vector< std::unique_ptr< PROJECT > > m_projects_list
 Loaded projects (ownership here).
 
std::map< wxString, PROJECT * > m_projects
 Loaded projects, mapped according to project full name.
 
std::map< wxString, PROJECT_FILE * > m_project_files
 Loaded project files, mapped according to project full name.
 

Static Private Attributes

static wxString backupDateTimeFormat = wxT( "%Y-%m-%d_%H%M%S" )
 

Detailed Description

Definition at line 48 of file settings_manager.h.

Constructor & Destructor Documentation

◆ SETTINGS_MANAGER()

◆ ~SETTINGS_MANAGER()

SETTINGS_MANAGER::~SETTINGS_MANAGER ( )

Definition at line 90 of file settings_manager.cpp.

References m_color_settings, m_projects, m_projects_list, m_settings, and project.

Member Function Documentation

◆ AddNewColorSettings()

COLOR_SETTINGS * SETTINGS_MANAGER::AddNewColorSettings ( const wxString & aFilename)

Register a new color settings object with the given filename.

Parameters
aFilenameis the location to store the new settings object.
Returns
a pointer to the new object.

Definition at line 373 of file settings_manager.cpp.

References registerColorSettings().

Referenced by FOOTPRINT_EDITOR_SETTINGS::MigrateFromLegacy(), and PANEL_COLOR_SETTINGS::OnThemeChanged().

◆ BackupProject()

bool SETTINGS_MANAGER::BackupProject ( REPORTER & aReporter,
wxFileName & aTarget ) const

Create a backup archive of the current project.

Parameters
aReporteris used for progress reporting.
aTargetis the full path to the backup file. If empty, will generate and return the full path to the backup file.
Returns
true if everything succeeded.

Definition at line 1477 of file settings_manager.cpp.

References PROJECT_ARCHIVER::Archive(), FILEEXT::ArchiveFileExtension, backupDateTimeFormat, PATHS::EnsurePathExists(), GetProjectBackupsPath(), Prj(), and traceSettings.

Referenced by TriggerBackupIfNeeded().

◆ ClearFileHistory()

void SETTINGS_MANAGER::ClearFileHistory ( )

Clear saved file history from all settings files.

Definition at line 126 of file settings_manager.cpp.

References GetPathForSettingsFile(), m_settings, path, and USER.

Referenced by PANEL_MAINTENANCE::onClearFileHistory().

◆ compareVersions()

int SETTINGS_MANAGER::compareVersions ( const std::string & aFirst,
const std::string & aSecond )
staticprivate

Compare two settings versions, like "5.99" and "6.0".

Returns
-1 if aFirst is older than aSecond, 1 if aFirst is newer than aSecond, 0 otherwise.

Definition at line 886 of file settings_manager.cpp.

References extractVersion(), and traceSettings.

Referenced by GetPreviousVersionPaths().

◆ extractVersion()

bool SETTINGS_MANAGER::extractVersion ( const std::string & aVersionString,
int * aMajor = nullptr,
int * aMinor = nullptr )
staticprivate

Extract the numeric version from a given settings string.

Parameters
aVersionStringis the string to split at the ".".
aMajorwill store the first part.
aMinorwill store the second part.
Returns
true if extraction succeeded.

Definition at line 926 of file settings_manager.cpp.

Referenced by compareVersions(), and GetPreviousVersionPaths().

◆ FlushAndRelease()

void SETTINGS_MANAGER::FlushAndRelease ( JSON_SETTINGS * aSettings,
bool aSave = true )

If the given settings object is registered, save it to disk and unregister it.

Parameters
aSettingsis the object to release

Definition at line 226 of file settings_manager.cpp.

References GetPathForSettingsFile(), m_app_settings_cache, m_settings, and traceSettings.

Referenced by BIN_MOD::End(), and unloadProjectFile().

◆ GetAppSettings()

template<typename T>
T * SETTINGS_MANAGER::GetAppSettings ( const char * aFilename)
inline

Return a handle to the a given settings by type.

If the settings have already been loaded, returns the existing pointer. If the settings have not been loaded, creates a new object owned by the settings manager and returns a pointer to it.

Template Parameters
Tis a type derived from APP_SETTINGS_BASE.
Parameters
aFilenameis used to find the correct settings under clang (where RTTI doesn't work across compile boundaries).
Returns
a pointer to a loaded settings object.

Definition at line 124 of file settings_manager.h.

References m_app_settings_cache, m_app_settings_mutex, m_settings, and T.

Referenced by STARTWIZARD_PROVIDER_PRIVACY::ApplyDefaults(), FOOTPRINT_EDIT_FRAME::config(), DIALOG_TEMPLATE_SELECTOR::DIALOG_TEMPLATE_SELECTOR(), STARTWIZARD_PROVIDER_PRIVACY::Finish(), PCB_BASE_FRAME::GetFootprintEditorSettings(), PCB_BASE_FRAME::GetPcbNewSettings(), PCB_BASE_FRAME::GetViewerSettingsBase(), gvconfig(), LIBRARY_MANAGER::LoadGlobalTables(), FOOTPRINT_PREVIEW_PANEL::New(), DIALOG_TEMPLATE_SELECTOR::OnFilterChanged(), and KIGFX::PCB_PAINTER::viewer_settings().

◆ GetAutosaveRootForProject()

wxString SETTINGS_MANAGER::GetAutosaveRootForProject ( const PROJECT * aProject = nullptr) const

Resolve the autosave-files root for a project.

In PROJECT_DIR mode this is the project directory itself (autosave files are written as siblings with a "_autosave-" prefix in the filename). In USER_DIR mode it is a per-project subdirectory under the user data path that mirrors the project tree.

Definition at line 1454 of file settings_manager.cpp.

References GetCommonSettings(), PATHS::GetUserSettingsPath(), COMMON_SETTINGS::AUTO_BACKUP::location, location, COMMON_SETTINGS::m_Backup, project, PROJECT_DIR, projectKeySuffix(), and resolveProject().

Referenced by findAutosaveFilePairs(), and LOCAL_HISTORY::RunRegisteredSaversAsAutosaveFiles().

◆ GetBackupRootForProject()

wxString SETTINGS_MANAGER::GetBackupRootForProject ( const PROJECT * aProject = nullptr) const

Resolve the backup root directory for a project, honoring the active BACKUP_LOCATION preference.

PROJECT_DIR yields the legacy "<projectpath>/<name>-backups/" path; USER_DIR yields a per-project subdirectory under the user data path keyed by SHA-256 of the project full path so identically-named projects do not collide.

Parameters
aProjectis the project whose backup root to resolve, or nullptr to use Prj().
Returns
absolute directory path with a trailing separator.

Definition at line 1397 of file settings_manager.cpp.

References GetCommonSettings(), PATHS::GetUserSettingsPath(), COMMON_SETTINGS::AUTO_BACKUP::location, location, COMMON_SETTINGS::m_Backup, project, PROJECT_BACKUPS_DIR_SUFFIX, PROJECT_DIR, projectKeySuffix(), and resolveProject().

Referenced by GetProjectBackupsPath().

◆ GetColorSettings()

COLOR_SETTINGS * SETTINGS_MANAGER::GetColorSettings ( const wxString & aName)

Retrieve a color settings object that applications can read colors from.

If the given settings file cannot be found, returns the default settings.

Parameters
aNameis the name of the color scheme to load.
Returns
a loaded COLOR_SETTINGS object.

Definition at line 252 of file settings_manager.cpp.

References COLOR_SETTINGS::COLOR_BUILTIN_DEFAULT, DEFAULT_THEME, loadColorSettingsByName(), m_color_settings, registerColorSettings(), JSON_SETTINGS::SetFilename(), and JSON_SETTINGS::SetReadOnly().

Referenced by GetColorSettings(), and PCB_TEST_FRAME_BASE::LoadSettings().

◆ GetColorSettingsList()

std::vector< COLOR_SETTINGS * > SETTINGS_MANAGER::GetColorSettingsList ( )

Definition at line 291 of file settings_manager.cpp.

References m_color_settings.

◆ GetColorSettingsPath()

wxString SETTINGS_MANAGER::GetColorSettingsPath ( )
static

Return the path where color scheme files are stored; creating it if missing (normally .

/colors/ under the user settings path).

Definition at line 837 of file settings_manager.cpp.

References PATHS::GetUserSettingsPath(), path, and traceSettings.

Referenced by GetPathForSettingsFile(), loadAllColorSettings(), loadColorSettingsByName(), PANEL_COLOR_SETTINGS::OnBtnOpenThemeFolderClicked(), PANEL_COLOR_SETTINGS::OnThemeChanged(), and SaveColorSettings().

◆ GetCommonSettings()

◆ GetLocalHistoryDirForPath()

wxString SETTINGS_MANAGER::GetLocalHistoryDirForPath ( const wxString & aProjectPath) const

Resolve the local-history directory for a project given by its on-disk path.

In PROJECT_DIR mode the supplied path is used verbatim (so callers can target a project that is not the active one); in USER_DIR mode the keying defers to GetLocalHistoryDirForProject when aProjectPath matches the active project.

Definition at line 1441 of file settings_manager.cpp.

References GetCommonSettings(), GetLocalHistoryDirForProject(), GetProjectForPath(), and PROJECT_DIR.

Referenced by historyPath(), and historyPath().

◆ GetLocalHistoryDirForProject()

wxString SETTINGS_MANAGER::GetLocalHistoryDirForProject ( const PROJECT * aProject = nullptr) const

Resolve the local-history (.history) storage directory for a project.

PROJECT_DIR yields "<projectpath>/.history/"; USER_DIR yields a per-project subdirectory under the user data path.

Definition at line 1417 of file settings_manager.cpp.

References GetCommonSettings(), PATHS::GetUserSettingsPath(), COMMON_SETTINGS::AUTO_BACKUP::location, location, COMMON_SETTINGS::m_Backup, project, PROJECT_DIR, projectKeySuffix(), and resolveProject().

Referenced by GetLocalHistoryDirForPath().

◆ GetMigratedColorSettings()

COLOR_SETTINGS * SETTINGS_MANAGER::GetMigratedColorSettings ( )

Return a color theme for storing colors migrated from legacy (5.x and earlier) settings, creating the theme if necessary.

This theme will be called "user.json" / "User".

Returns
the color settings to be used for migrating legacy settings.

Definition at line 382 of file settings_manager.cpp.

References m_color_settings, registerColorSettings(), Save(), and COLOR_SETTINGS::SetName().

Referenced by EESCHEMA_SETTINGS::MigrateFromLegacy(), GERBVIEW_SETTINGS::MigrateFromLegacy(), and PCBNEW_SETTINGS::MigrateFromLegacy().

◆ GetOpenProjects()

std::vector< wxString > SETTINGS_MANAGER::GetOpenProjects ( ) const
Returns
a list of open projects.

Definition at line 1187 of file settings_manager.cpp.

References m_projects.

Referenced by KICAD_MANAGER_FRAME::canCloseWindow(), and KICAD_MANAGER_FRAME::SaveSettings().

◆ GetPathForSettingsFile()

wxString SETTINGS_MANAGER::GetPathForSettingsFile ( JSON_SETTINGS * aSettings)

◆ GetPreviousVersionPaths()

bool SETTINGS_MANAGER::GetPreviousVersionPaths ( std::vector< wxString > * aName = nullptr)

Retrieve the name of the most recent previous KiCad version that can be found in the user settings directory.

For legacy versions (5.x, and 5.99 builds before this code was written), this will return "5.x".

Parameters
aNameis filled with the name of the previous version, if one exists.
Returns
true if a previous version to migrate from exists.

Definition at line 682 of file settings_manager.cpp.

References PATHS::CalculateUserSettingsPath(), compareVersions(), extractVersion(), GetSettingsVersion(), IsSettingsPathValid(), and traceSettings.

Referenced by PANEL_STARTWIZARD_SETTINGS::TransferDataToWindow().

◆ GetProject()

PROJECT * SETTINGS_MANAGER::GetProject ( const wxString & aFullPath) const

Retrieve a loaded project by name.

Parameters
aFullPathis the full path including name and extension to the project file.
Returns
a pointer to the project if loaded, or nullptr.

Definition at line 1178 of file settings_manager.cpp.

References m_projects.

Referenced by CLI::JOBSET_RUN_COMMAND::doPerform(), PCBNEW_JOBS_HANDLER::getBoard(), EESCHEMA_HELPERS::LoadSchematic(), and SCH::readSchematicFromFile().

◆ GetProjectBackupsPath()

wxString SETTINGS_MANAGER::GetProjectBackupsPath ( ) const
Returns
the full path to where project backups should be stored.

Definition at line 1391 of file settings_manager.cpp.

References GetBackupRootForProject().

Referenced by BackupProject(), and TriggerBackupIfNeeded().

◆ GetProjectForPath()

PROJECT * SETTINGS_MANAGER::GetProjectForPath ( const wxString & aProjectPath) const

Return the active project iff its path matches aProjectPath, else nullptr.

Lets backup/history helpers feed the right PROJECT* into per-project path resolvers without falling back to Prj() for an unrelated project.

Definition at line 1377 of file settings_manager.cpp.

References PROJECT::GetProjectPath(), IsProjectOpen(), and Prj().

Referenced by findAutosaveFilePairs(), GetLocalHistoryDirForPath(), and LOCAL_HISTORY::RunRegisteredSaversAsAutosaveFiles().

◆ GetSettingsVersion()

std::string SETTINGS_MANAGER::GetSettingsVersion ( )
static

Parse the current KiCad build version and extracts the major and minor revision to use as the name of the settings directory for this KiCad version.

Returns
a string such as "5.1".

Definition at line 879 of file settings_manager.cpp.

References GetMajorMinorVersion().

Referenced by GetPreviousVersionPaths().

◆ GetToolbarSettings()

template<typename T>
T * SETTINGS_MANAGER::GetToolbarSettings ( const wxString & aFilename)
inline

Return a handle to the given toolbar settings.

If the settings have already been loaded, returns the existing pointer. If the settings have not been loaded, creates a new object owned by the settings manager and returns a pointer to it.

Template Parameters
Tis a type derived from TOOLBAR_SETTINGS.
Parameters
aFilenameis used to find the correct settings under clang (where RTTI doesn't work across compile boundaries).
Returns
a pointer to a loaded settings object.

Definition at line 180 of file settings_manager.h.

References m_settings, RegisterSettings(), and T.

Referenced by CVPCB_MAINFRAME::CVPCB_MAINFRAME(), and EVT_TOOL_RANGE().

◆ GetToolbarSettingsPath()

wxString SETTINGS_MANAGER::GetToolbarSettingsPath ( )
static

Return the path where toolbar configuration files are stored; creating it if missing (normally .

/toolbars/ under the user settings path).

Definition at line 858 of file settings_manager.cpp.

References PATHS::GetUserSettingsPath(), path, and traceSettings.

Referenced by GetPathForSettingsFile().

◆ GetUserSettingsPath()

wxString SETTINGS_MANAGER::GetUserSettingsPath ( )
static

A proxy for PATHS::GetUserSettingsPath() rather than fighting swig.

Definition at line 1715 of file settings_manager.cpp.

References PATHS::GetUserSettingsPath().

◆ IsOK()

bool SETTINGS_MANAGER::IsOK ( )
inline
Returns
true if settings load was successful

Definition at line 65 of file settings_manager.h.

References m_ok.

◆ IsProjectOpen()

bool SETTINGS_MANAGER::IsProjectOpen ( ) const

Helper for checking if we have a project open.

Todo
This should be deprecated along with Prj() once we support multiple projects fully.
Returns
true if a call to Prj() will succeed.

Definition at line 1165 of file settings_manager.cpp.

References m_projects.

Referenced by PCB_BASE_EDIT_FRAME::doCloseWindow(), KICAD_MANAGER_FRAME::GetProjectFileName(), and GetProjectForPath().

◆ IsProjectOpenNotDummy()

bool SETTINGS_MANAGER::IsProjectOpenNotDummy ( ) const

Helper for checking if we have a project open that is not a dummy project.

Returns
true if a call to Prj() will succeed and the project is not a dummy project.

Definition at line 1171 of file settings_manager.cpp.

References m_projects.

◆ IsSettingsPathValid()

bool SETTINGS_MANAGER::IsSettingsPathValid ( const wxString & aPath)
static

Check if a given path is probably a valid KiCad configuration directory.

Actually it just checks if a file called "kicad_common" exists, because that's probably good enough for now.

Parameters
aPathis the path to check.
Returns
true if the path contains KiCad settings.

Definition at line 824 of file settings_manager.cpp.

Referenced by GetPreviousVersionPaths(), and PANEL_STARTWIZARD_SETTINGS::validatePath().

◆ Load() [1/2]

void SETTINGS_MANAGER::Load ( )

◆ Load() [2/2]

void SETTINGS_MANAGER::Load ( JSON_SETTINGS * aSettings)

Definition at line 176 of file settings_manager.cpp.

References GetPathForSettingsFile(), and m_settings.

◆ loadAllColorSettings()

◆ loadColorSettingsByName()

COLOR_SETTINGS * SETTINGS_MANAGER::loadColorSettingsByName ( const wxString & aName)
private

Attempt to load a color theme by name (the color theme directory and .json ext are assumed).

Parameters
aNameis the filename of the color theme (without the extension or path).
Returns
the loaded settings, or nullptr if load failed.

Definition at line 305 of file settings_manager.cpp.

References GetColorSettingsPath(), JSON_SETTINGS::GetFilename(), m_color_settings, RegisterSettings(), and traceSettings.

Referenced by GetColorSettings().

◆ LoadProject()

◆ loadProjectFile()

bool SETTINGS_MANAGER::loadProjectFile ( PROJECT & aProject)
private

Register a PROJECT_FILE and attempt to load it from disk.

Parameters
aProjectis the project object to load the file for.
Returns
true if the PROJECT_FILE was successfully loaded.

Definition at line 1294 of file settings_manager.cpp.

References PROJECT::GetProjectFullName(), PROJECT_FILE::LoadFromFile(), m_project_files, path, RegisterSettings(), PROJECT_FILE::SetProject(), and PROJECT::setProjectFile().

Referenced by LoadProject().

◆ MigrateFromPreviousVersion()

bool SETTINGS_MANAGER::MigrateFromPreviousVersion ( const wxString & aSourcePath)

◆ Prj()

◆ projectKeySuffix()

wxString SETTINGS_MANAGER::projectKeySuffix ( const PROJECT * aProject)
staticprivate

Build "<projectname>-<sha256prefix>" suffix used to disambiguate per-project subdirectories under the user data path.

Returns an empty string if the project is null or has no full name yet (e.g., a fresh standalone editor).

Definition at line 1353 of file settings_manager.cpp.

References PROJECT::GetProjectFullName(), and PROJECT::GetProjectName().

Referenced by GetAutosaveRootForProject(), GetBackupRootForProject(), and GetLocalHistoryDirForProject().

◆ registerBuiltinColorSettings()

void SETTINGS_MANAGER::registerBuiltinColorSettings ( )
private

◆ registerColorSettings()

COLOR_SETTINGS * SETTINGS_MANAGER::registerColorSettings ( const wxString & aFilename,
bool aAbsolutePath = false )
private

◆ RegisterSettings()

◆ registerSettings()

JSON_SETTINGS * SETTINGS_MANAGER::registerSettings ( JSON_SETTINGS * aSettings,
bool aLoadNow = true )
private

Definition at line 141 of file settings_manager.cpp.

References GetPathForSettingsFile(), m_settings, and traceSettings.

Referenced by RegisterSettings().

◆ ReloadColorSettings()

void SETTINGS_MANAGER::ReloadColorSettings ( )

Re-scan the color themes directory, reloading any changes it finds.

Definition at line 451 of file settings_manager.cpp.

References loadAllColorSettings(), and m_color_settings.

Referenced by PANEL_FP_EDITOR_COLOR_SETTINGS::PANEL_FP_EDITOR_COLOR_SETTINGS(), and KICAD_MANAGER_CONTROL::ShowPluginManager().

◆ ResetToDefaults()

void SETTINGS_MANAGER::ResetToDefaults ( )

Reset all program settings to defaults.

Definition at line 106 of file settings_manager.cpp.

References COLORS, GetPathForSettingsFile(), m_settings, path, and USER.

Referenced by PANEL_MAINTENANCE::onResetAll().

◆ resolveProject()

const PROJECT & SETTINGS_MANAGER::resolveProject ( const PROJECT * aProject) const
private

Pick the project to resolve a backup path against, falling back to Prj().

Definition at line 1371 of file settings_manager.cpp.

References Prj().

Referenced by GetAutosaveRootForProject(), GetBackupRootForProject(), and GetLocalHistoryDirForProject().

◆ Save() [1/2]

◆ Save() [2/2]

void SETTINGS_MANAGER::Save ( JSON_SETTINGS * aSettings)

Definition at line 210 of file settings_manager.cpp.

References GetPathForSettingsFile(), m_settings, and traceSettings.

◆ SaveColorSettings()

void SETTINGS_MANAGER::SaveColorSettings ( COLOR_SETTINGS * aSettings,
const std::string & aNamespace = "" )

◆ SaveProject()

bool SETTINGS_MANAGER::SaveProject ( const wxString & aFullPath = wxEmptyString,
PROJECT * aProject = nullptr )

◆ SaveProjectAs()

void SETTINGS_MANAGER::SaveProjectAs ( const wxString & aFullPath,
PROJECT * aProject = nullptr )

Set the currently loaded project path and saves it (pointers remain valid).

Note
that this will not modify the read-only state of the project, so it will have no effect if the project is marked as read-only!
Parameters
aFullPathis the full filename to set for the project.
aProjectis the project to save, or nullptr to save the active project (Prj() return).

Definition at line 1229 of file settings_manager.cpp.

References PROJECT::GetLocalSettings(), PROJECT::GetProjectFullName(), PROJECT::IsReadOnly(), m_project_files, m_projects, Prj(), project, SaveProject(), PROJECT_LOCAL_SETTINGS::SaveToFile(), JSON_SETTINGS::SetFilename(), PROJECT::setProjectFullName(), and JSON_SETTINGS::SetReadOnly().

Referenced by HEADLESS_BOARD_CONTEXT::SaveBoard(), HEADLESS_BOARD_CONTEXT::SavePcbCopy(), PCB_EDIT_FRAME::SavePcbFile(), and SCH_EDIT_FRAME::SaveProject().

◆ SaveProjectCopy()

void SETTINGS_MANAGER::SaveProjectCopy ( const wxString & aFullPath,
PROJECT * aProject = nullptr )

Save a copy of the current project under the given path.

Warning
This will save the copy even if the current project is marked as read-only.
Parameters
aFullPathis the full filename to set for the project.
aProjectis the project to save, or nullptr to save the active project (Prj() return).

Definition at line 1268 of file settings_manager.cpp.

References PROJECT::GetLocalSettings(), PROJECT::GetProjectFullName(), m_project_files, Prj(), project, PROJECT_LOCAL_SETTINGS::SaveToFile(), and JSON_SETTINGS::SetFilename().

Referenced by PCB_EDIT_FRAME::SavePcbCopy(), and SCH_EDIT_FRAME::SaveProject().

◆ SetKiway()

void SETTINGS_MANAGER::SetKiway ( KIWAY * aKiway)
inline

Associate this setting manager with the given Kiway.

Parameters
aKiwayis the kiway this settings manager should use

Definition at line 72 of file settings_manager.h.

References m_kiway.

Referenced by PGM_KICAD::OnPgmInit().

◆ SettingsDirectoryValid()

bool SETTINGS_MANAGER::SettingsDirectoryValid ( ) const
Returns
true if the settings directory for this version of KiCad exists and has at least a common settings file (kicad_common.json). Used to know whether or not the first-run wizard needs to be shown.

Definition at line 605 of file settings_manager.cpp.

References PATHS::GetUserSettingsPath(), path, and traceSettings.

Referenced by STARTWIZARD_PROVIDER_SETTINGS::NeedsUserInput(), and SETTINGS_MANAGER().

◆ TriggerBackupIfNeeded()

◆ UnloadProject()

◆ unloadProjectFile()

bool SETTINGS_MANAGER::unloadProjectFile ( PROJECT * aProject,
bool aSave )
private

Optionally save, unload and unregister the given PROJECT_FILE.

Parameters
aProjectis the project object to unload the file for.
aSaveif true will save the project file before unloading.
Returns
true if the PROJECT file was successfully saved. Helper to create built-in colors and register them.

Definition at line 1312 of file settings_manager.cpp.

References FlushAndRelease(), PROJECT::GetLocalSettings(), GetPathForSettingsFile(), PROJECT::GetProjectFullName(), m_project_files, m_settings, name, PROJECT_FILE::ShouldAutoSave(), and PROJECT_LOCAL_SETTINGS::ShouldAutoSave().

Referenced by LoadProject(), and UnloadProject().

Member Data Documentation

◆ backupDateTimeFormat

wxString SETTINGS_MANAGER::backupDateTimeFormat = wxT( "%Y-%m-%d_%H%M%S" )
staticprivate

Definition at line 574 of file settings_manager.h.

Referenced by BackupProject(), and TriggerBackupIfNeeded().

◆ m_app_settings_cache

std::unordered_map<size_t, JSON_SETTINGS*> SETTINGS_MANAGER::m_app_settings_cache
private

Cache for app settings.

Definition at line 553 of file settings_manager.h.

Referenced by FlushAndRelease(), and GetAppSettings().

◆ m_app_settings_mutex

std::mutex SETTINGS_MANAGER::m_app_settings_mutex
private

Definition at line 554 of file settings_manager.h.

Referenced by GetAppSettings().

◆ m_color_settings

◆ m_common_settings

COMMON_SETTINGS* SETTINGS_MANAGER::m_common_settings
private

Definition at line 557 of file settings_manager.h.

Referenced by GetCommonSettings(), and SETTINGS_MANAGER().

◆ m_kiway

KIWAY* SETTINGS_MANAGER::m_kiway
private

The kiway this settings manager interacts with.

Definition at line 546 of file settings_manager.h.

Referenced by LoadProject(), SetKiway(), SETTINGS_MANAGER(), and UnloadProject().

◆ m_migrateLibraryTables

bool SETTINGS_MANAGER::m_migrateLibraryTables
private

If true, the symbol and footprint library tables will be migrated from the previous version.

Definition at line 560 of file settings_manager.h.

Referenced by MigrateFromPreviousVersion(), and SETTINGS_MANAGER().

◆ m_ok

bool SETTINGS_MANAGER::m_ok
private

True if settings loaded successfully at construction.

Definition at line 563 of file settings_manager.h.

Referenced by IsOK(), and SETTINGS_MANAGER().

◆ m_project_files

std::map<wxString, PROJECT_FILE*> SETTINGS_MANAGER::m_project_files
private

Loaded project files, mapped according to project full name.

Definition at line 572 of file settings_manager.h.

Referenced by loadProjectFile(), SaveProject(), SaveProjectAs(), SaveProjectCopy(), and unloadProjectFile().

◆ m_projects

std::map<wxString, PROJECT*> SETTINGS_MANAGER::m_projects
private

Loaded projects, mapped according to project full name.

Definition at line 569 of file settings_manager.h.

Referenced by GetOpenProjects(), GetProject(), IsProjectOpen(), IsProjectOpenNotDummy(), LoadProject(), SaveProjectAs(), UnloadProject(), and ~SETTINGS_MANAGER().

◆ m_projects_list

std::vector<std::unique_ptr<PROJECT> > SETTINGS_MANAGER::m_projects_list
private

Loaded projects (ownership here).

Definition at line 566 of file settings_manager.h.

Referenced by LoadProject(), Prj(), UnloadProject(), and ~SETTINGS_MANAGER().

◆ m_settings

std::vector<std::unique_ptr<JSON_SETTINGS> > SETTINGS_MANAGER::m_settings
private

The documentation for this class was generated from the following files: