2020-01-13 01:44:19 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
|
2021-09-27 12:24:11 +00:00
|
|
|
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-01-13 01:44:19 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SETTINGS_MANAGER_H
|
|
|
|
#define _SETTINGS_MANAGER_H
|
|
|
|
|
2021-06-04 03:52:50 +00:00
|
|
|
#include <algorithm>
|
2023-03-25 15:22:11 +00:00
|
|
|
#include <mutex>
|
2021-03-19 16:12:41 +00:00
|
|
|
#include <typeinfo>
|
2021-04-02 23:29:47 +00:00
|
|
|
#include <core/wx_stl_compat.h> // for wxString hash
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/color_settings.h>
|
|
|
|
|
|
|
|
class COLOR_SETTINGS;
|
|
|
|
class COMMON_SETTINGS;
|
2020-08-09 18:49:26 +00:00
|
|
|
class KIWAY;
|
2020-05-25 17:06:53 +00:00
|
|
|
class PROJECT;
|
|
|
|
class PROJECT_FILE;
|
2020-07-03 13:40:31 +00:00
|
|
|
class REPORTER;
|
2021-04-02 23:29:47 +00:00
|
|
|
class wxSingleInstanceChecker;
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
|
2021-09-27 12:24:11 +00:00
|
|
|
/// Project settings path will be <projectname> + this
|
|
|
|
#define PROJECT_BACKUPS_DIR_SUFFIX wxT( "-backups" )
|
|
|
|
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
class SETTINGS_MANAGER
|
|
|
|
{
|
|
|
|
public:
|
2020-06-20 14:36:16 +00:00
|
|
|
SETTINGS_MANAGER( bool aHeadless = false );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
~SETTINGS_MANAGER();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if settings load was successful
|
|
|
|
*/
|
|
|
|
bool IsOK() { return m_ok; }
|
|
|
|
|
2020-08-09 18:49:26 +00:00
|
|
|
/**
|
|
|
|
* Associate this setting manager with the given Kiway.
|
|
|
|
*
|
|
|
|
* @param aKiway is the kiway this settings manager should use
|
|
|
|
*/
|
|
|
|
void SetKiway( KIWAY* aKiway ) { m_kiway = aKiway; }
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
/**
|
|
|
|
* Takes ownership of the pointer passed in
|
|
|
|
* @param aSettings is a settings object to register
|
|
|
|
* @return a handle to the owned pointer
|
|
|
|
*/
|
2021-08-04 15:44:12 +00:00
|
|
|
template<typename T>
|
|
|
|
T* RegisterSettings( T* aSettings, bool aLoadNow = true )
|
|
|
|
{
|
2023-04-18 20:40:25 +00:00
|
|
|
return static_cast<T*>( registerSettings( aSettings, aLoadNow ) );
|
2021-08-04 15:44:12 +00:00
|
|
|
}
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
void Load();
|
|
|
|
|
|
|
|
void Load( JSON_SETTINGS* aSettings );
|
|
|
|
|
|
|
|
void Save();
|
|
|
|
|
|
|
|
void Save( JSON_SETTINGS* aSettings );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the given settings object is registered, save it to disk and unregister it
|
|
|
|
* @param aSettings is the object to release
|
|
|
|
*/
|
2020-05-31 21:42:04 +00:00
|
|
|
void FlushAndRelease( JSON_SETTINGS* aSettings, bool aSave = true );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns 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.
|
|
|
|
*
|
2021-08-04 15:44:12 +00:00
|
|
|
* @tparam T is a type derived from APP_SETTINGS_BASE
|
2020-01-13 01:44:19 +00:00
|
|
|
* @param aLoadNow is true to load the registered file from disk immediately
|
|
|
|
* @return a pointer to a loaded settings object
|
|
|
|
*/
|
2021-08-04 15:44:12 +00:00
|
|
|
template<typename T>
|
2023-04-18 20:40:25 +00:00
|
|
|
T* GetAppSettings()
|
2020-01-13 01:44:19 +00:00
|
|
|
{
|
2021-08-04 15:44:12 +00:00
|
|
|
T* ret = nullptr;
|
|
|
|
size_t typeHash = typeid( T ).hash_code();
|
2021-03-19 16:12:41 +00:00
|
|
|
|
|
|
|
if( m_app_settings_cache.count( typeHash ) )
|
2021-08-04 15:44:12 +00:00
|
|
|
ret = dynamic_cast<T*>( m_app_settings_cache.at( typeHash ) );
|
2021-03-17 00:46:58 +00:00
|
|
|
|
|
|
|
if( ret )
|
|
|
|
return ret;
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
auto it = std::find_if( m_settings.begin(), m_settings.end(),
|
2020-07-31 13:47:56 +00:00
|
|
|
[]( const std::unique_ptr<JSON_SETTINGS>& aSettings )
|
|
|
|
{
|
2021-08-04 15:44:12 +00:00
|
|
|
return dynamic_cast<T*>( aSettings.get() );
|
2020-01-13 01:44:19 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
if( it != m_settings.end() )
|
2020-09-21 11:05:31 +00:00
|
|
|
{
|
2021-08-04 15:44:12 +00:00
|
|
|
ret = dynamic_cast<T*>( it->get() );
|
2020-09-21 11:05:31 +00:00
|
|
|
}
|
2020-01-13 01:44:19 +00:00
|
|
|
else
|
2020-09-21 11:05:31 +00:00
|
|
|
{
|
2023-04-18 20:40:25 +00:00
|
|
|
throw std::runtime_error( "Tried to GetAppSettings before registering" );
|
2020-09-21 11:05:31 +00:00
|
|
|
}
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2021-03-19 16:12:41 +00:00
|
|
|
m_app_settings_cache[typeHash] = ret;
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a color settings object that applications can read colors from.
|
|
|
|
* If the given settings file cannot be found, returns the default settings.
|
|
|
|
*
|
|
|
|
* @param aName is the name of the color scheme to load
|
|
|
|
* @return a loaded COLOR_SETTINGS object
|
|
|
|
*/
|
2020-02-03 16:46:58 +00:00
|
|
|
COLOR_SETTINGS* GetColorSettings( const wxString& aName = "user" );
|
|
|
|
|
|
|
|
std::vector<COLOR_SETTINGS*> GetColorSettingsList()
|
|
|
|
{
|
|
|
|
std::vector<COLOR_SETTINGS*> ret;
|
|
|
|
|
2020-07-31 13:47:56 +00:00
|
|
|
for( const std::pair<const wxString, COLOR_SETTINGS*>& entry : m_color_settings )
|
|
|
|
ret.push_back( entry.second );
|
2020-02-03 16:46:58 +00:00
|
|
|
|
2020-07-31 13:47:56 +00:00
|
|
|
std::sort( ret.begin(), ret.end(), []( COLOR_SETTINGS* a, COLOR_SETTINGS* b )
|
|
|
|
{
|
|
|
|
return a->GetName() < b->GetName();
|
|
|
|
} );
|
2020-02-03 16:46:58 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Safely saves a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
|
|
|
|
*
|
|
|
|
* A color settings namespace is one of the top-level JSON objects like "board", etc.
|
2021-06-09 19:32:58 +00:00
|
|
|
* This will perform a read-modify-write
|
2020-01-13 01:44:19 +00:00
|
|
|
*
|
|
|
|
* @param aSettings is a pointer to a valid COLOR_SETTINGS object managed by SETTINGS_MANAGER
|
|
|
|
* @param aNamespace is the namespace of settings to save
|
|
|
|
*/
|
|
|
|
void SaveColorSettings( COLOR_SETTINGS* aSettings, const std::string& aNamespace = "" );
|
|
|
|
|
2020-02-03 16:46:58 +00:00
|
|
|
/**
|
|
|
|
* Registers a new color settings object with the given filename
|
|
|
|
* @param aFilename is the location to store the new settings object
|
|
|
|
* @return a pointer to the new object
|
|
|
|
*/
|
|
|
|
COLOR_SETTINGS* AddNewColorSettings( const wxString& aFilename );
|
|
|
|
|
2020-10-15 01:57:36 +00:00
|
|
|
/**
|
|
|
|
* Returns 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".
|
|
|
|
* @return the color settings to be used for migrating legacy settings
|
|
|
|
*/
|
|
|
|
COLOR_SETTINGS* GetMigratedColorSettings();
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
/**
|
|
|
|
* Retrieves the common settings shared by all applications
|
|
|
|
* @return a pointer to a loaded COMMON_SETTINGS
|
|
|
|
*/
|
2020-07-03 13:40:31 +00:00
|
|
|
COMMON_SETTINGS* GetCommonSettings() const { return m_common_settings; }
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the path a given settings file should be loaded from / stored to.
|
|
|
|
* @param aSettings is the settings object
|
|
|
|
* @return a path based on aSettings->m_location
|
|
|
|
*/
|
2020-08-02 09:23:21 +00:00
|
|
|
wxString GetPathForSettingsFile( JSON_SETTINGS* aSettings );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the initialization of the user settings directory and migration from previous
|
|
|
|
* KiCad versions as needed.
|
|
|
|
*
|
|
|
|
* This method will check for the existence of the user settings path for this KiCad version.
|
|
|
|
* If it exists, settings load will proceed normally using that path.
|
|
|
|
*
|
|
|
|
* If that directory is empty or does not exist, the migration wizard will be launched, which
|
|
|
|
* will give users the option to migrate settings from a previous KiCad version (if one is
|
|
|
|
* found), manually specify a directory to migrate fromm, or start with default settings.
|
|
|
|
*
|
|
|
|
* @return true if migration was successful or not necessary, false otherwise
|
|
|
|
*/
|
|
|
|
bool MigrateIfNeeded();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for DIALOG_MIGRATE_SETTINGS to specify a source for migration
|
|
|
|
* @param aSource is a directory containing settings files to migrate from (can be empty)
|
|
|
|
*/
|
|
|
|
void SetMigrationSource( const wxString& aSource ) { m_migration_source = aSource; }
|
|
|
|
|
2020-09-25 00:54:31 +00:00
|
|
|
void SetMigrateLibraryTables( bool aMigrate = true ) { m_migrateLibraryTables = aMigrate; }
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
/**
|
2021-06-09 19:32:58 +00:00
|
|
|
* Retrieves the name of the most recent previous KiCad version that can be found in the
|
2020-01-13 01:44:19 +00:00
|
|
|
* user settings directory. For legacy versions (5.x, and 5.99 builds before this code was
|
|
|
|
* written), this will return "5.x"
|
|
|
|
*
|
|
|
|
* @param aName is filled with the name of the previous version, if one exists
|
|
|
|
* @return true if a previous version to migrate from exists
|
|
|
|
*/
|
|
|
|
bool GetPreviousVersionPaths( std::vector<wxString>* aName = nullptr );
|
|
|
|
|
2020-04-08 21:34:18 +00:00
|
|
|
/**
|
|
|
|
* Re-scans the color themes directory, reloading any changes it finds.
|
|
|
|
*/
|
|
|
|
void ReloadColorSettings();
|
|
|
|
|
2020-05-25 17:06:53 +00:00
|
|
|
/**
|
2020-05-25 20:41:24 +00:00
|
|
|
* Loads a project or sets up a new project with a specified path
|
2020-05-25 17:38:09 +00:00
|
|
|
* @param aFullPath is the full path to the project
|
2020-05-31 21:42:04 +00:00
|
|
|
* @param aSetActive if true will set the loaded project as the active project
|
2020-05-25 20:41:24 +00:00
|
|
|
* @return true if the PROJECT_FILE was successfully loaded from disk
|
2020-05-25 17:06:53 +00:00
|
|
|
*/
|
2020-05-31 21:42:04 +00:00
|
|
|
bool LoadProject( const wxString& aFullPath, bool aSetActive = true );
|
2020-05-25 17:06:53 +00:00
|
|
|
|
|
|
|
/**
|
2020-05-25 17:38:09 +00:00
|
|
|
* Saves, unloads and unregisters the given PROJECT
|
2020-05-25 17:06:53 +00:00
|
|
|
* @param aProject is the project object to unload
|
2020-05-31 21:42:04 +00:00
|
|
|
* @param aSave if true will save the project before unloading
|
2020-05-25 17:06:53 +00:00
|
|
|
* @return true if the PROJECT file was successfully saved
|
|
|
|
*/
|
2020-05-31 21:42:04 +00:00
|
|
|
bool UnloadProject( PROJECT* aProject, bool aSave = true );
|
2020-05-25 17:06:53 +00:00
|
|
|
|
2020-08-09 15:13:42 +00:00
|
|
|
/**
|
|
|
|
* Helper for checking if we have a project open
|
|
|
|
* TODO: This should be deprecated along with Prj() once we support multiple projects fully
|
|
|
|
* @return true if a call to Prj() will succeed
|
|
|
|
*/
|
|
|
|
bool IsProjectOpen() const;
|
|
|
|
|
2020-05-25 17:38:09 +00:00
|
|
|
/**
|
|
|
|
* A helper while we are not MDI-capable -- return the one and only project
|
|
|
|
* @return the loaded project
|
|
|
|
*/
|
|
|
|
PROJECT& Prj() const;
|
|
|
|
|
2020-05-25 20:41:24 +00:00
|
|
|
/**
|
2020-05-31 21:42:04 +00:00
|
|
|
* Retrieves a loaded project by name
|
|
|
|
* @param aFullPath is the full path including name and extension to the project file
|
|
|
|
* @return a pointer to the project if loaded, or nullptr
|
|
|
|
*/
|
|
|
|
PROJECT* GetProject( const wxString& aFullPath ) const;
|
|
|
|
|
2020-08-08 20:00:29 +00:00
|
|
|
/**
|
|
|
|
* @return a list of open projects
|
|
|
|
*/
|
|
|
|
std::vector<wxString> GetOpenProjects() const;
|
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
/**
|
|
|
|
* Saves a loaded project.
|
|
|
|
* @param aFullPath is the project name to save. If empty, will save the first loaded project.
|
2022-03-05 17:45:51 +00:00
|
|
|
* @param aProject is the project to save, or nullptr to save the active project (Prj() return)
|
2020-05-25 20:41:24 +00:00
|
|
|
* @return true if save was successful
|
|
|
|
*/
|
2022-03-05 17:45:51 +00:00
|
|
|
bool SaveProject( const wxString& aFullPath = wxEmptyString, PROJECT* aProject = nullptr );
|
2020-05-25 20:41:24 +00:00
|
|
|
|
2020-10-06 02:13:06 +00:00
|
|
|
/**
|
|
|
|
* Sets the currently loaded project path and saves it (pointers remain valid)
|
2021-04-22 01:27:23 +00:00
|
|
|
* 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!
|
2020-10-06 02:13:06 +00:00
|
|
|
* @param aFullPath is the full filename to set for the project
|
2022-03-05 17:45:51 +00:00
|
|
|
* @param aProject is the project to save, or nullptr to save the active project (Prj() return)
|
2020-10-06 02:13:06 +00:00
|
|
|
*/
|
2022-03-05 17:45:51 +00:00
|
|
|
void SaveProjectAs( const wxString& aFullPath, PROJECT* aProject = nullptr );
|
2020-10-06 02:13:06 +00:00
|
|
|
|
2021-04-13 16:41:23 +00:00
|
|
|
/**
|
2021-04-22 01:27:23 +00:00
|
|
|
* Saves a copy of the current project under the given path. Will save the copy even if the
|
|
|
|
* current project is marked as read-only.
|
2022-03-05 17:45:51 +00:00
|
|
|
* @param aFullPath is the full filename to set for the project
|
|
|
|
* @param aProject is the project to save, or nullptr to save the active project (Prj() return)
|
2021-04-13 16:41:23 +00:00
|
|
|
*/
|
2022-03-05 17:45:51 +00:00
|
|
|
void SaveProjectCopy( const wxString& aFullPath, PROJECT* aProject = nullptr );
|
2021-04-13 16:41:23 +00:00
|
|
|
|
2020-07-03 13:40:31 +00:00
|
|
|
/**
|
|
|
|
* @return the full path to where project backups should be stored
|
|
|
|
*/
|
|
|
|
wxString GetProjectBackupsPath() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a backup archive of the current project
|
|
|
|
* @param aReporter is used for progress reporting
|
|
|
|
* @return true if everything succeeded
|
|
|
|
*/
|
|
|
|
bool BackupProject( REPORTER& aReporter ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls BackupProject if a new backup is needed according to the current backup policy.
|
|
|
|
* @param aReporter is used for progress reporting
|
|
|
|
* @return if everything succeeded
|
|
|
|
*/
|
|
|
|
bool TriggerBackupIfNeeded( REPORTER& aReporter ) const;
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
/**
|
|
|
|
* Checks 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.
|
|
|
|
*
|
|
|
|
* @param aPath is the path to check
|
|
|
|
* @return true if the path contains KiCad settings
|
|
|
|
*/
|
|
|
|
static bool IsSettingsPathValid( const wxString& aPath );
|
|
|
|
|
|
|
|
/**
|
2020-10-25 20:56:22 +00:00
|
|
|
* Returns the path where color scheme files are stored; creating it if missing
|
2020-01-13 01:44:19 +00:00
|
|
|
* (normally ./colors/ under the user settings path)
|
|
|
|
*/
|
2020-08-02 09:23:21 +00:00
|
|
|
static wxString GetColorSettingsPath();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the user configuration path used to store KiCad's configuration files.
|
|
|
|
*
|
|
|
|
* @see calculateUserSettingsPath
|
|
|
|
*
|
|
|
|
* NOTE: The path is cached at startup, it will never change during program lifetime!
|
|
|
|
*
|
|
|
|
* @return A string containing the config path for Kicad
|
|
|
|
*/
|
2020-08-02 09:23:21 +00:00
|
|
|
static wxString GetUserSettingsPath();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses 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.
|
|
|
|
*
|
|
|
|
* @return a string such as "5.1"
|
|
|
|
*/
|
|
|
|
static std::string GetSettingsVersion();
|
|
|
|
|
|
|
|
private:
|
2021-08-04 15:44:12 +00:00
|
|
|
JSON_SETTINGS* registerSettings( JSON_SETTINGS* aSettings, bool aLoadNow = true );
|
|
|
|
|
2023-03-25 14:44:34 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
/**
|
|
|
|
* Determines the base path for user settings files.
|
|
|
|
*
|
|
|
|
* The configuration path order of precedence is determined by the following criteria:
|
|
|
|
*
|
|
|
|
* - The value of the KICAD_CONFIG_HOME environment variable
|
|
|
|
* - The value of the XDG_CONFIG_HOME environment variable.
|
|
|
|
* - The result of the call to wxStandardPaths::GetUserConfigDir() with ".config" appended
|
|
|
|
* as required on Linux builds.
|
|
|
|
*
|
|
|
|
* @param aIncludeVer will append the current KiCad version if true (default)
|
|
|
|
* @param aUseEnv will prefer the base path found in the KICAD_CONFIG_DIR if found (default)
|
|
|
|
* @return A string containing the config path for Kicad
|
|
|
|
*/
|
2020-08-02 09:23:21 +00:00
|
|
|
static wxString calculateUserSettingsPath( bool aIncludeVer = true, bool aUseEnv = true );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares two settings versions, like "5.99" and "6.0"
|
|
|
|
* @return -1 if aFirst is older than aSecond, 1 if aFirst is newer than aSecond, 0 otherwise
|
|
|
|
*/
|
|
|
|
static int compareVersions( const std::string& aFirst, const std::string& aSecond );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extracts the numeric version from a given settings string
|
|
|
|
* @param aVersionString is the string to split at the "."
|
|
|
|
* @param aMajor will store the first part
|
|
|
|
* @param aMinor will store the second part
|
|
|
|
* @return true if extraction succeeded
|
|
|
|
*/
|
2023-01-07 19:24:14 +00:00
|
|
|
static bool extractVersion( const std::string& aVersionString, int* aMajor = nullptr,
|
|
|
|
int* aMinor = nullptr );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2020-02-03 16:46:58 +00:00
|
|
|
/**
|
|
|
|
* Attempts to load a color theme by name (the color theme directory and .json ext are assumed)
|
|
|
|
* @param aName is the filename of the color theme (without the extension or path)
|
|
|
|
* @return the loaded settings, or nullptr if load failed
|
|
|
|
*/
|
|
|
|
COLOR_SETTINGS* loadColorSettingsByName( const wxString& aName );
|
|
|
|
|
2021-11-10 03:11:59 +00:00
|
|
|
COLOR_SETTINGS* registerColorSettings( const wxString& aFilename, bool aAbsolutePath = false );
|
2020-02-03 16:46:58 +00:00
|
|
|
|
|
|
|
void loadAllColorSettings();
|
|
|
|
|
2020-05-25 17:38:09 +00:00
|
|
|
/**
|
|
|
|
* Registers a PROJECT_FILE and attempts to load it from disk
|
|
|
|
* @param aProject is the project object to load the file for
|
|
|
|
* @return true if the PROJECT_FILE was successfully loaded
|
|
|
|
*/
|
|
|
|
bool loadProjectFile( PROJECT& aProject );
|
|
|
|
|
|
|
|
/**
|
2020-05-31 21:42:04 +00:00
|
|
|
* Optionally saves, and then unloads and unregisters the given PROJECT_FILE
|
2020-05-25 17:38:09 +00:00
|
|
|
* @param aProject is the project object to unload the file for
|
2020-05-31 21:42:04 +00:00
|
|
|
* @param aSave if true will save the project file before unloading
|
2020-05-25 17:38:09 +00:00
|
|
|
* @return true if the PROJECT file was successfully saved
|
|
|
|
*/
|
2020-05-31 21:42:04 +00:00
|
|
|
bool unloadProjectFile( PROJECT* aProject, bool aSave );
|
2020-05-25 17:38:09 +00:00
|
|
|
|
2023-02-17 16:32:11 +00:00
|
|
|
// Helper to create built-in colors and register them
|
|
|
|
void registerBuiltinColorSettings();
|
|
|
|
|
2020-05-25 17:38:09 +00:00
|
|
|
private:
|
|
|
|
|
2020-06-20 14:36:16 +00:00
|
|
|
/// True if running outside a UI context
|
|
|
|
bool m_headless;
|
|
|
|
|
2020-08-09 18:49:26 +00:00
|
|
|
/// The kiway this settings manager interacts with
|
|
|
|
KIWAY* m_kiway;
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
std::vector<std::unique_ptr<JSON_SETTINGS>> m_settings;
|
|
|
|
|
2020-02-03 16:46:58 +00:00
|
|
|
std::unordered_map<wxString, COLOR_SETTINGS*> m_color_settings;
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2021-03-19 16:12:41 +00:00
|
|
|
/// Cache for app settings
|
|
|
|
std::unordered_map<size_t, JSON_SETTINGS*> m_app_settings_cache;
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
// Convenience shortcut
|
|
|
|
COMMON_SETTINGS* m_common_settings;
|
|
|
|
|
|
|
|
wxString m_migration_source;
|
|
|
|
|
2020-09-25 00:54:31 +00:00
|
|
|
/// If true, the symbol and footprint library tables will be migrated from the previous version
|
|
|
|
bool m_migrateLibraryTables;
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
/// True if settings loaded successfully at construction
|
|
|
|
bool m_ok;
|
2020-05-25 17:06:53 +00:00
|
|
|
|
2020-10-06 02:13:06 +00:00
|
|
|
/// Loaded projects (ownership here)
|
|
|
|
std::vector<std::unique_ptr<PROJECT>> m_projects_list;
|
|
|
|
|
2020-05-25 17:38:09 +00:00
|
|
|
/// Loaded projects, mapped according to project full name
|
2020-10-06 02:13:06 +00:00
|
|
|
std::map<wxString, PROJECT*> m_projects;
|
2020-05-25 17:38:09 +00:00
|
|
|
|
|
|
|
/// Loaded project files, mapped according to project full name
|
2020-05-25 17:06:53 +00:00
|
|
|
std::map<wxString, PROJECT_FILE*> m_project_files;
|
|
|
|
|
2021-04-02 23:29:47 +00:00
|
|
|
/// Lock for loaded project (expand to multiple once we support MDI)
|
|
|
|
std::unique_ptr<wxSingleInstanceChecker> m_project_lock;
|
|
|
|
|
2020-07-03 13:40:31 +00:00
|
|
|
static wxString backupDateTimeFormat;
|
2020-01-13 01:44:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|