From 24435fcc621b764d56cdce03ae4514af0db58a3c Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Mon, 24 Aug 2020 22:17:21 -0400 Subject: [PATCH] Don't create new project files when opening boards/schematics Display warning infobar in the board/schematic setup when no project is loaded, since most of the settings in those dialogs are saved in the project and not in the board/schematic file. Fixes https://gitlab.com/kicad/code/kicad/-/issues/4868 --- common/widgets/paged_dialog.cpp | 4 ++++ eeschema/dialogs/dialog_schematic_setup.cpp | 4 ++++ eeschema/files-io.cpp | 17 +++++++++++++---- include/widgets/paged_dialog.h | 4 ++++ pcbnew/dialogs/dialog_board_setup.cpp | 6 +++++- pcbnew/files.cpp | 6 ++++-- pcbnew/pcbnew_config.cpp | 3 ++- 7 files changed, 36 insertions(+), 8 deletions(-) diff --git a/common/widgets/paged_dialog.cpp b/common/widgets/paged_dialog.cpp index 6e266d43a6..80f15cba8e 100644 --- a/common/widgets/paged_dialog.cpp +++ b/common/widgets/paged_dialog.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -91,6 +92,9 @@ PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aUse auto mainSizer = new wxBoxSizer( wxVERTICAL ); SetSizer( mainSizer ); + m_infoBar = new WX_INFOBAR( this ); + mainSizer->Add( m_infoBar, 0, wxEXPAND, 0 ); + m_treebook = new PAGED_TREEBOOK( this, wxID_ANY ); mainSizer->Add( m_treebook, 1, wxEXPAND|wxLEFT|wxTOP, 10 ); diff --git a/eeschema/dialogs/dialog_schematic_setup.cpp b/eeschema/dialogs/dialog_schematic_setup.cpp index 2d82d07946..502323d980 100644 --- a/eeschema/dialogs/dialog_schematic_setup.cpp +++ b/eeschema/dialogs/dialog_schematic_setup.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "dialog_schematic_setup.h" #include "panel_eeschema_template_fieldnames.h" @@ -81,6 +82,9 @@ 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." ) ); + FinishDialogSettings(); } diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 6057ce0c1b..5e62ee53c8 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -284,10 +284,16 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in if( differentProject ) { - GetSettingsManager()->SaveProject(); + if( !Prj().IsNullProject() ) + GetSettingsManager()->SaveProject(); + Schematic().SetProject( nullptr ); GetSettingsManager()->UnloadProject( &Prj() ); - GetSettingsManager()->LoadProject( pro.GetFullPath() ); + + // Do not load 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() : "" ); + CreateScreens(); } @@ -622,7 +628,9 @@ void SCH_EDIT_FRAME::OnImportProject( wxCommandEvent& aEvent ) if( setProject ) { - GetSettingsManager()->SaveProject(); + if( !Prj().IsNullProject() ) + GetSettingsManager()->SaveProject(); + Schematic().SetProject( nullptr ); GetSettingsManager()->UnloadProject( &Prj() ); @@ -777,7 +785,8 @@ bool SCH_EDIT_FRAME::SaveProject() sheets.emplace_back( std::make_pair( sheet->m_Uuid, sheet->GetName() ) ); } - Pgm().GetSettingsManager().SaveProject(); + if( !Prj().IsNullProject() ) + Pgm().GetSettingsManager().SaveProject(); if( !Kiface().IsSingle() ) { diff --git a/include/widgets/paged_dialog.h b/include/widgets/paged_dialog.h index 144a434dd6..2415a089c2 100644 --- a/include/widgets/paged_dialog.h +++ b/include/widgets/paged_dialog.h @@ -25,6 +25,9 @@ #include +class WX_INFOBAR; + + class PAGED_TREEBOOK : public wxTreebook { public: @@ -89,6 +92,7 @@ protected: wxButton* m_auxiliaryButton; wxButton* m_resetButton; wxButton* m_cancelButton; + WX_INFOBAR* m_infoBar; }; diff --git a/pcbnew/dialogs/dialog_board_setup.cpp b/pcbnew/dialogs/dialog_board_setup.cpp index 4f23307b79..18efa27868 100644 --- a/pcbnew/dialogs/dialog_board_setup.cpp +++ b/pcbnew/dialogs/dialog_board_setup.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include "dialog_board_setup.h" @@ -94,7 +95,10 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) : m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED, wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), NULL, this ); - FinishDialogSettings(); + if( Prj().IsNullProject() ) + m_infoBar->ShowMessage( _( "No project is loaded. Changes will not be saved." ) ); + + FinishDialogSettings(); } diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 8d9e3f46e8..b1d5cd2421 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -519,12 +519,14 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in if( pro.GetFullPath() != mgr->Prj().GetProjectFullName() ) { + // calls SaveProject SaveProjectSettings(); - mgr->SaveProject( mgr->Prj().GetProjectFullName() ); mgr->UnloadProject( &mgr->Prj() ); - mgr->LoadProject( pro.GetFullPath() ); + // Do not load 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() : "" ); } } diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index a8a8e25018..25f1c3a2c8 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -227,5 +227,6 @@ void PCB_EDIT_FRAME::SaveProjectSettings() SELECTION_FILTER_OPTIONS& filterOpts = GetToolManager()->GetTool()->GetFilter(); localSettings.m_SelectionFilter = filterOpts; - GetSettingsManager()->SaveProject(); + if( !Prj().IsNullProject() ) + GetSettingsManager()->SaveProject(); }