Settings: allow multiple project access from Python standalone
We can't handle this in the UI, but we can externally, so allow
it for Python scripting and eventually we'll use this in the UI
also...
Fixes https://gitlab.com/kicad/code/kicad/-/issues/10540
(cherry picked from commit 1394509734
)
This commit is contained in:
parent
8fd87e1f04
commit
cb6d6d7ef4
|
@ -954,15 +954,18 @@ std::vector<wxString> SETTINGS_MANAGER::GetOpenProjects() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SETTINGS_MANAGER::SaveProject( const wxString& aFullPath )
|
bool SETTINGS_MANAGER::SaveProject( const wxString& aFullPath, PROJECT* aProject )
|
||||||
{
|
{
|
||||||
|
if( !aProject )
|
||||||
|
aProject = &Prj();
|
||||||
|
|
||||||
wxString path = aFullPath;
|
wxString path = aFullPath;
|
||||||
|
|
||||||
if( path.empty() )
|
if( path.empty() )
|
||||||
path = Prj().GetProjectFullName();
|
path = aProject->GetProjectFullName();
|
||||||
|
|
||||||
// TODO: refactor for MDI
|
// TODO: refactor for MDI
|
||||||
if( Prj().IsReadOnly() )
|
if( aProject->IsReadOnly() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( !m_project_files.count( path ) )
|
if( !m_project_files.count( path ) )
|
||||||
|
@ -972,24 +975,27 @@ bool SETTINGS_MANAGER::SaveProject( const wxString& aFullPath )
|
||||||
wxString projectPath = GetPathForSettingsFile( project );
|
wxString projectPath = GetPathForSettingsFile( project );
|
||||||
|
|
||||||
project->SaveToFile( projectPath );
|
project->SaveToFile( projectPath );
|
||||||
Prj().GetLocalSettings().SaveToFile( projectPath );
|
aProject->GetLocalSettings().SaveToFile( projectPath );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SETTINGS_MANAGER::SaveProjectAs( const wxString& aFullPath )
|
void SETTINGS_MANAGER::SaveProjectAs( const wxString& aFullPath, PROJECT* aProject )
|
||||||
{
|
{
|
||||||
wxString oldName = Prj().GetProjectFullName();
|
if( !aProject )
|
||||||
|
aProject = &Prj();
|
||||||
|
|
||||||
|
wxString oldName = aProject->GetProjectFullName();
|
||||||
|
|
||||||
if( aFullPath.IsSameAs( oldName ) )
|
if( aFullPath.IsSameAs( oldName ) )
|
||||||
{
|
{
|
||||||
SaveProject( aFullPath );
|
SaveProject( aFullPath, aProject );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changing this will cause UnloadProject to not save over the "old" project when loading below
|
// Changing this will cause UnloadProject to not save over the "old" project when loading below
|
||||||
Prj().setProjectFullName( aFullPath );
|
aProject->setProjectFullName( aFullPath );
|
||||||
|
|
||||||
wxFileName fn( aFullPath );
|
wxFileName fn( aFullPath );
|
||||||
|
|
||||||
|
@ -997,14 +1003,14 @@ void SETTINGS_MANAGER::SaveProjectAs( const wxString& aFullPath )
|
||||||
|
|
||||||
// Ensure read-only flags are copied; this allows doing a "Save As" on a standalong board/sch
|
// Ensure read-only flags are copied; this allows doing a "Save As" on a standalong board/sch
|
||||||
// without creating project files if the checkbox is turned off
|
// without creating project files if the checkbox is turned off
|
||||||
project->SetReadOnly( Prj().IsReadOnly() );
|
project->SetReadOnly( aProject->IsReadOnly() );
|
||||||
Prj().GetLocalSettings().SetReadOnly( Prj().IsReadOnly() );
|
aProject->GetLocalSettings().SetReadOnly( aProject->IsReadOnly() );
|
||||||
|
|
||||||
project->SetFilename( fn.GetName() );
|
project->SetFilename( fn.GetName() );
|
||||||
project->SaveToFile( fn.GetPath() );
|
project->SaveToFile( fn.GetPath() );
|
||||||
|
|
||||||
Prj().GetLocalSettings().SetFilename( fn.GetName() );
|
aProject->GetLocalSettings().SetFilename( fn.GetName() );
|
||||||
Prj().GetLocalSettings().SaveToFile( fn.GetPath() );
|
aProject->GetLocalSettings().SaveToFile( fn.GetPath() );
|
||||||
|
|
||||||
m_project_files[fn.GetFullPath()] = project;
|
m_project_files[fn.GetFullPath()] = project;
|
||||||
m_project_files.erase( oldName );
|
m_project_files.erase( oldName );
|
||||||
|
@ -1014,9 +1020,12 @@ void SETTINGS_MANAGER::SaveProjectAs( const wxString& aFullPath )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SETTINGS_MANAGER::SaveProjectCopy( const wxString& aFullPath )
|
void SETTINGS_MANAGER::SaveProjectCopy( const wxString& aFullPath, PROJECT* aProject )
|
||||||
{
|
{
|
||||||
PROJECT_FILE* project = m_project_files.at( Prj().GetProjectFullName() );
|
if( !aProject )
|
||||||
|
aProject = &Prj();
|
||||||
|
|
||||||
|
PROJECT_FILE* project = m_project_files.at( aProject->GetProjectFullName() );
|
||||||
wxString oldName = project->GetFilename();
|
wxString oldName = project->GetFilename();
|
||||||
wxFileName fn( aFullPath );
|
wxFileName fn( aFullPath );
|
||||||
|
|
||||||
|
@ -1027,9 +1036,11 @@ void SETTINGS_MANAGER::SaveProjectCopy( const wxString& aFullPath )
|
||||||
project->SaveToFile( fn.GetPath() );
|
project->SaveToFile( fn.GetPath() );
|
||||||
project->SetFilename( oldName );
|
project->SetFilename( oldName );
|
||||||
|
|
||||||
Prj().GetLocalSettings().SetFilename( fn.GetName() );
|
PROJECT_LOCAL_SETTINGS& localSettings = aProject->GetLocalSettings();
|
||||||
Prj().GetLocalSettings().SaveToFile( fn.GetPath() );
|
|
||||||
Prj().GetLocalSettings().SetFilename( oldName );
|
localSettings.SetFilename( fn.GetName() );
|
||||||
|
localSettings.SaveToFile( fn.GetPath() );
|
||||||
|
localSettings.SetFilename( oldName );
|
||||||
|
|
||||||
project->SetReadOnly( readOnly );
|
project->SetReadOnly( readOnly );
|
||||||
}
|
}
|
||||||
|
|
|
@ -276,23 +276,27 @@ public:
|
||||||
/**
|
/**
|
||||||
* Saves a loaded project.
|
* Saves a loaded project.
|
||||||
* @param aFullPath is the project name to save. If empty, will save the first loaded project.
|
* @param aFullPath is the project name to save. If empty, will save the first loaded project.
|
||||||
|
* @param aProject is the project to save, or nullptr to save the active project (Prj() return)
|
||||||
* @return true if save was successful
|
* @return true if save was successful
|
||||||
*/
|
*/
|
||||||
bool SaveProject( const wxString& aFullPath = wxEmptyString );
|
bool SaveProject( const wxString& aFullPath = wxEmptyString, PROJECT* aProject = nullptr );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the currently loaded project path and saves it (pointers remain valid)
|
* Sets 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
|
* 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!
|
* if the project is marked as read-only!
|
||||||
* @param aFullPath is the full filename to set for the project
|
* @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)
|
||||||
*/
|
*/
|
||||||
void SaveProjectAs( const wxString& aFullPath );
|
void SaveProjectAs( const wxString& aFullPath, PROJECT* aProject = nullptr );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves a copy of the current project under the given path. Will save the copy even if the
|
* 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.
|
* current project is marked as read-only.
|
||||||
|
* @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)
|
||||||
*/
|
*/
|
||||||
void SaveProjectCopy( const wxString& aFullPath );
|
void SaveProjectCopy( const wxString& aFullPath, PROJECT* aProject = nullptr );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the full path to where project backups should be stored
|
* @return the full path to where project backups should be stored
|
||||||
|
|
|
@ -260,7 +260,7 @@ bool SaveBoard( wxString& aFileName, BOARD* aBoard, IO_MGR::PCB_FILE_T aFormat )
|
||||||
pro.MakeAbsolute();
|
pro.MakeAbsolute();
|
||||||
wxString projectPath = pro.GetFullPath();
|
wxString projectPath = pro.GetFullPath();
|
||||||
|
|
||||||
GetSettingsManager()->SaveProjectAs( pro.GetFullPath() );
|
GetSettingsManager()->SaveProjectAs( pro.GetFullPath(), aBoard->GetProject() );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue