Lock project files when opening; open locked projects read-only

Also clean up an include-what-you-use problem

Fixes https://gitlab.com/kicad/code/kicad/-/issues/8037
This commit is contained in:
Jon Evans 2021-04-02 19:29:47 -04:00
parent 8ea18c0639
commit c1573744be
6 changed files with 29 additions and 2 deletions

View File

@ -47,6 +47,7 @@
#include "sg/scenegraph.h"
#include "plugins/3dapi/ifsg_api.h"
#include <common.h> // For ExpandEnvVarSubstitutions
#include <filename_resolver.h>
#include <paths.h>
#include <pgm_base.h>

View File

@ -20,6 +20,7 @@
#include <wx/filename.h>
#include <wx/stdpaths.h>
#include <wx/string.h>
#include <wx/utils.h>
#include <kiplatform/environment.h>
#include <paths.h>

View File

@ -22,6 +22,7 @@
#include <wx/debug.h>
#include <wx/dir.h>
#include <wx/filename.h>
#include <wx/snglinst.h>
#include <wx/stdpaths.h>
#include <wx/utils.h>
@ -31,6 +32,7 @@
#include <gestfich.h>
#include <kiplatform/environment.h>
#include <kiway.h>
#include <lockfile.h>
#include <macros.h>
#include <paths.h>
#include <project.h>
@ -757,6 +759,15 @@ bool SETTINGS_MANAGER::LoadProject( const wxString& aFullPath, bool aSetActive )
if( m_projects.count( fullPath ) )
return true;
bool readOnly = false;
std::unique_ptr<wxSingleInstanceChecker> lockFile = ::LockFile( fullPath );
if( !lockFile )
{
wxLogTrace( traceSettings, "Project %s is locked; opening read-only", fullPath );
readOnly = true;
}
// No MDI yet
if( aSetActive && !m_projects.empty() )
{
@ -773,7 +784,12 @@ bool SETTINGS_MANAGER::LoadProject( const wxString& aFullPath, bool aSetActive )
bool success = loadProjectFile( *project );
if( success )
project->SetReadOnly( project->GetProjectFile().IsReadOnly() );
{
project->SetReadOnly( readOnly || project->GetProjectFile().IsReadOnly() );
if( lockFile )
m_project_lock.reset( lockFile.release() );
}
m_projects_list.push_back( std::move( project ) );
m_projects[fullPath] = m_projects_list.back().get();
@ -825,6 +841,9 @@ bool SETTINGS_MANAGER::UnloadProject( PROJECT* aProject, bool aSave )
// Remove the reference in the environment to the previous project
wxSetEnv( PROJECT_VAR_NAME, "" );
// Release lock on the file, in case we had one
m_project_lock = nullptr;
if( m_kiway )
m_kiway->ProjectChanged();

View File

@ -25,6 +25,7 @@
*/
#include <bitmaps.h>
#include <common.h> // For ExpandEnvVarSubstitutions
#include <dialogs/wx_html_report_panel.h>
#include <dialog_plot_schematic.h>
#include <eeschema_settings.h>

View File

@ -22,6 +22,7 @@
#include <set>
#include <wx/regex.h>
#include <common.h> // For ExpandEnvVarSubstitutions
#include <project.h>
#include <panel_sym_lib_table.h>
#include <lib_id.h>

View File

@ -22,7 +22,7 @@
#define _SETTINGS_MANAGER_H
#include <typeinfo>
#include <common.h> // for wxString hash
#include <core/wx_stl_compat.h> // for wxString hash
#include <settings/color_settings.h>
class COLOR_SETTINGS;
@ -31,6 +31,7 @@ class KIWAY;
class PROJECT;
class PROJECT_FILE;
class REPORTER;
class wxSingleInstanceChecker;
class SETTINGS_MANAGER
@ -425,6 +426,9 @@ private:
/// Loaded project files, mapped according to project full name
std::map<wxString, PROJECT_FILE*> m_project_files;
/// Lock for loaded project (expand to multiple once we support MDI)
std::unique_ptr<wxSingleInstanceChecker> m_project_lock;
static wxString backupDateTimeFormat;
};