From 43ab43ec9ec22c0f72af9da752dae2e3e1e66971 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 9 Aug 2020 11:13:42 -0400 Subject: [PATCH] Fix a few issues with Close Project A new empty project needs to be reopened for now Footprint info cache write only works with a project for now --- common/settings/settings_manager.cpp | 6 ++++++ include/settings/settings_manager.h | 7 +++++++ kicad/kicad_manager_frame.cpp | 4 ++++ pcbnew/pcb_base_edit_frame.cpp | 17 ++++++++++++----- pcbnew/pcb_base_edit_frame.h | 2 ++ pcbnew/pcb_edit_frame.cpp | 2 ++ 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/common/settings/settings_manager.cpp b/common/settings/settings_manager.cpp index 1e9eb5409e..780bfe063d 100644 --- a/common/settings/settings_manager.cpp +++ b/common/settings/settings_manager.cpp @@ -742,6 +742,12 @@ PROJECT& SETTINGS_MANAGER::Prj() const } +bool SETTINGS_MANAGER::IsProjectOpen() const +{ + return !m_projects.empty(); +} + + PROJECT* SETTINGS_MANAGER::GetProject( const wxString& aFullPath ) const { if( m_projects.count( aFullPath ) ) diff --git a/include/settings/settings_manager.h b/include/settings/settings_manager.h index d5905d9168..0d90956da6 100644 --- a/include/settings/settings_manager.h +++ b/include/settings/settings_manager.h @@ -200,6 +200,13 @@ public: */ bool UnloadProject( PROJECT* aProject, bool aSave = true ); + /** + * 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; + /** * A helper while we are not MDI-capable -- return the one and only project * @return the loaded project diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index 71123bb915..70a6574b59 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -369,6 +369,10 @@ bool KICAD_MANAGER_FRAME::CloseProject( bool aSave ) m_active_project = false; mgr.UnloadProject( &Prj() ); + + // TODO(JE): Remove this if apps are refactored to not assume Prj() always works + // Need to create a project early for now (it can have an empty path for the moment) + mgr.LoadProject( "" ); } ClearMsg(); diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 01ba1bf3ba..5314ecb59b 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -52,19 +52,26 @@ PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, } } + PCB_BASE_EDIT_FRAME::~PCB_BASE_EDIT_FRAME() { - if( wxFileName::IsDirWritable( Prj().GetProjectPath() ) ) + GetCanvas()->GetView()->Clear(); +} + + +void PCB_BASE_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent ) +{ + SETTINGS_MANAGER* mgr = GetSettingsManager(); + + if( mgr->IsProjectOpen() && wxFileName::IsDirWritable( Prj().GetProjectPath() ) ) { wxTextFile footprintInfoCache( Prj().GetProjectPath() + "fp-info-cache" ); GFootprintList.WriteCacheToFile( &footprintInfoCache ); } // Close the project if we are standalone, so it gets cleaned up properly - if( Kiface().IsSingle() ) - GetSettingsManager()->UnloadProject( &Prj() ); - - GetCanvas()->GetView()->Clear(); + if( mgr->IsProjectOpen() && Kiface().IsSingle() ) + mgr->UnloadProject( &Prj() ); } diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 36d7354d48..23231033df 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -43,6 +43,8 @@ public: virtual ~PCB_BASE_EDIT_FRAME(); + void OnCloseWindow( wxCloseEvent& aEvent ) override; + /** * If a library name is given, creates a new footprint library in the project folder * with the given name. If no library name is given it prompts user for a library path, diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 092d5661a2..aca506e7fa 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -633,6 +633,8 @@ void PCB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent ) // want any paint event Show( false ); + PCB_BASE_EDIT_FRAME::OnCloseWindow( aEvent ); + // Close frame: aEvent.Skip(); }