From 9f7bca38b3604b677bf945d83369fae5a0f0c4fe Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 30 Aug 2020 16:04:39 -0400 Subject: [PATCH] A better way of handling standalone project files --- common/project.cpp | 1 + common/settings/settings_manager.cpp | 4 ++++ eeschema/dialogs/dialog_schematic_setup.cpp | 4 ++-- eeschema/files-io.cpp | 7 +++++-- include/project.h | 7 +++++++ pcbnew/dialogs/dialog_board_setup.cpp | 4 ++-- pcbnew/files.cpp | 7 +++++-- 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/common/project.cpp b/common/project.cpp index a6829338bc..54a2e0a291 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -40,6 +40,7 @@ PROJECT::PROJECT() : + m_readOnly( false ), m_projectFile( nullptr ), m_localSettings( nullptr ) { diff --git a/common/settings/settings_manager.cpp b/common/settings/settings_manager.cpp index d57352ed3e..6eaeb39ff6 100644 --- a/common/settings/settings_manager.cpp +++ b/common/settings/settings_manager.cpp @@ -794,6 +794,10 @@ bool SETTINGS_MANAGER::SaveProject( const wxString& aFullPath ) if( path.empty() ) path = Prj().GetProjectFullName(); + // TODO: refactor for MDI + if( Prj().IsReadOnly() ) + return false; + if( !m_project_files.count( path ) ) return false; diff --git a/eeschema/dialogs/dialog_schematic_setup.cpp b/eeschema/dialogs/dialog_schematic_setup.cpp index c8dc374315..c616d37f06 100644 --- a/eeschema/dialogs/dialog_schematic_setup.cpp +++ b/eeschema/dialogs/dialog_schematic_setup.cpp @@ -82,8 +82,8 @@ DIALOG_SCHEMATIC_SETUP::DIALOG_SCHEMATIC_SETUP( SCH_EDIT_FRAME* aFrame ) : m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED, wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), NULL, this ); - if( Prj().IsNullProject() ) - m_infoBar->ShowMessage( _( "No project is loaded. Changes will not be saved." ) ); + if( Prj().IsReadOnly() ) + m_infoBar->ShowMessage( _( "Project is missing or read-only. Changes will not be saved." ) ); FinishDialogSettings(); } diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 5e62ee53c8..f6afca69d8 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -290,9 +290,12 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in Schematic().SetProject( nullptr ); GetSettingsManager()->UnloadProject( &Prj() ); - // Do not load a project if one doesn't exist. This normally happens if we are + GetSettingsManager()->LoadProject( pro.GetFullPath() ); + + // Do not allow saving a project if one doesn't exist. This normally happens if we are // standalone and opening a board that has been moved from its project folder. - GetSettingsManager()->LoadProject( pro.Exists() ? pro.GetFullPath() : "" ); + if( !pro.Exists() ) + Prj().SetReadOnly(); CreateScreens(); } diff --git a/include/project.h b/include/project.h index 59745ead97..6ddb74bbac 100644 --- a/include/project.h +++ b/include/project.h @@ -117,6 +117,10 @@ public: */ VTBL_ENTRY bool IsNullProject() const; + VTBL_ENTRY bool IsReadOnly() const { return m_readOnly || IsNullProject(); } + + VTBL_ENTRY void SetReadOnly( bool aReadOnly = true ) { m_readOnly = aReadOnly; } + /** * Return the name of the sheet identified by the given UUID. */ @@ -332,6 +336,9 @@ private: wxFileName m_project_name; ///< \/\.pro wxString m_pro_date_and_time; + ///> True if the project is read-only: no project files will be written + bool m_readOnly; + /// Backing store for project data -- owned by SETTINGS_MANAGER PROJECT_FILE* m_projectFile; diff --git a/pcbnew/dialogs/dialog_board_setup.cpp b/pcbnew/dialogs/dialog_board_setup.cpp index be37716af5..879b8b046e 100644 --- a/pcbnew/dialogs/dialog_board_setup.cpp +++ b/pcbnew/dialogs/dialog_board_setup.cpp @@ -95,8 +95,8 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) : m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED, wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), NULL, this ); - if( Prj().IsNullProject() ) - m_infoBar->ShowMessage( _( "No project is loaded. Changes will not be saved." ) ); + if( Prj().IsReadOnly() ) + m_infoBar->ShowMessage( _( "Project is missing or read-only. Changes will not be saved." ) ); FinishDialogSettings(); } diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index d757b0245d..c68dcaf04c 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -521,9 +521,12 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in mgr->UnloadProject( &mgr->Prj() ); - // Do not load a project if one doesn't exist. This normally happens if we are + mgr->LoadProject( pro.GetFullPath() ); + + // Do not allow saving a project if one doesn't exist. This normally happens if we are // standalone and opening a board that has been moved from its project folder. - mgr->LoadProject( pro.Exists() ? pro.GetFullPath() : "" ); + if( !pro.Exists() ) + Prj().SetReadOnly(); } }