diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 0b9135c947..247183075a 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -655,6 +655,16 @@ bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) if( symbolViewer && !symbolViewer->Close() ) // Can close modal symbol viewer? return false; } + else + { + auto* symbolEditor = (SYMBOL_EDIT_FRAME*) Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false ); + + if( symbolEditor && symbolEditor->IsSymbolFromSchematic() ) + { + if( !symbolEditor->CanCloseSymbolFromSchematic( true ) ) + return false; + } + } SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) Kiway().Player( FRAME_SIMULATOR, false ); diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index a4044da970..e4364d7752 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -502,41 +502,57 @@ void SYMBOL_EDIT_FRAME::setupUIConditions() } -bool SYMBOL_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) +bool SYMBOL_EDIT_FRAME::CanCloseSymbolFromSchematic( bool doClose ) { - // Shutdown blocks must be determined and vetoed as early as possible - if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION - && IsContentModified() ) - { - return false; - } - - if( m_isSymbolFromSchematic && IsContentModified() ) + if( IsContentModified() ) { SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, false ); + wxString msg = _( "Save changes to '%s' before closing?" ); - switch( UnsavedChangesDialog( this, - _( "Save changes to schematic before closing?" ), - nullptr ) ) + switch( UnsavedChangesDialog( this, wxString::Format( msg, m_reference ), nullptr ) ) { case wxID_YES: if( schframe && GetCurSymbol() ) // Should be always the case schframe->SaveSymbolToSchematic( *GetCurSymbol(), m_schematicSymbolUUID ); - return true; + break; - case wxID_NO: return true; + case wxID_NO: + break; default: - case wxID_CANCEL: return false; + case wxID_CANCEL: + return false; } } - if( !saveAllLibraries( true ) ) + if( doClose ) + { + GetInfoBar()->ShowMessageFor( wxEmptyString, 1 ); + SetCurSymbol( nullptr, false ); + updateTitle(); + } + + return true; +} + + +bool SYMBOL_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) +{ + // Shutdown blocks must be determined and vetoed as early as possible + if( KIPLATFORM::APP::SupportsShutdownBlockReason() + && aEvent.GetId() == wxEVT_QUERY_END_SESSION + && IsContentModified() ) { return false; } + if( m_isSymbolFromSchematic && !CanCloseSymbolFromSchematic( false ) ) + return false; + + if( !saveAllLibraries( true ) ) + return false; + return true; } diff --git a/eeschema/symbol_editor/symbol_edit_frame.h b/eeschema/symbol_editor/symbol_edit_frame.h index 55cc6da05b..5f6d7f8bf9 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.h +++ b/eeschema/symbol_editor/symbol_edit_frame.h @@ -78,6 +78,8 @@ public: */ bool HasLibModifications() const; + bool CanCloseSymbolFromSchematic( bool doClose ); + /** * The nickname of the current library being edited and empty string if none. */ diff --git a/eeschema/symbol_editor/symbol_editor.cpp b/eeschema/symbol_editor/symbol_editor.cpp index 15cb487589..9b895062ce 100644 --- a/eeschema/symbol_editor/symbol_editor.cpp +++ b/eeschema/symbol_editor/symbol_editor.cpp @@ -137,7 +137,7 @@ void SYMBOL_EDIT_FRAME::updateTitle() wxString lib = GetCurLib(); wxString title; - if( IsSymbolFromSchematic() ) + if( GetCurSymbol() && IsSymbolFromSchematic() ) { if( GetScreen() && GetScreen()->IsContentModified() ) title = wxT( "*" ); diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index 0a0748d238..859b884e1c 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -649,6 +649,34 @@ const BOX2I FOOTPRINT_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) } +bool FOOTPRINT_EDIT_FRAME::CanCloseFPFromBoard( bool doClose ) +{ + if( IsContentModified() ) + { + wxString footprintName = GetBoard()->GetFirstFootprint()->GetReference(); + wxString msg = _( "Save changes to '%s' before closing?" ); + + if( !HandleUnsavedChanges( this, wxString::Format( msg, footprintName ), + [&]() -> bool + { + return SaveFootprint( GetBoard()->GetFirstFootprint() ); + } ) ) + { + return false; + } + } + + if( doClose ) + { + GetInfoBar()->ShowMessageFor( wxEmptyString, 1 ); + Clear_Pcb( false ); + UpdateTitle(); + } + + return true; +} + + bool FOOTPRINT_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) { if( IsContentModified() ) @@ -662,6 +690,10 @@ bool FOOTPRINT_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) } wxString footprintName = GetBoard()->GetFirstFootprint()->GetFPID().GetLibItemName(); + + if( IsCurrentFPFromBoard() ) + footprintName = GetBoard()->GetFirstFootprint()->GetReference(); + wxString msg = _( "Save changes to '%s' before closing?" ); if( !HandleUnsavedChanges( this, wxString::Format( msg, footprintName ), diff --git a/pcbnew/footprint_edit_frame.h b/pcbnew/footprint_edit_frame.h index 7e7d6c271a..79eaf92840 100644 --- a/pcbnew/footprint_edit_frame.h +++ b/pcbnew/footprint_edit_frame.h @@ -59,6 +59,8 @@ public: bool IsCurrentFPFromBoard() const; + bool CanCloseFPFromBoard( bool doClose ); + FOOTPRINT_EDITOR_SETTINGS* GetSettings(); APP_SETTINGS_BASE* config() const override; diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index b29d50241e..835fa4f9c2 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -104,6 +104,7 @@ #include #include #include +#include #include #include "../scripting/python_scripting.h" @@ -842,6 +843,34 @@ bool PCB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) return false; } + if( Kiface().IsSingle() ) + { + auto* fpEditor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, false ); + + if( fpEditor && !fpEditor->Close() ) // Can close footprint editor? + return false; + + auto* fpViewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_FOOTPRINT_VIEWER, false ); + + if( fpViewer && !fpViewer->Close() ) // Can close footprint viewer? + return false; + + fpViewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_FOOTPRINT_VIEWER_MODAL, false ); + + if( fpViewer && !fpViewer->Close() ) // Can close modal footprint viewer? + return false; + } + else + { + auto* fpEditor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, false ); + + if( fpEditor && fpEditor->IsCurrentFPFromBoard() ) + { + if( !fpEditor->CanCloseFPFromBoard( true ) ) + return false; + } + } + if( IsContentModified() ) { wxFileName fileName = GetBoard()->GetFileName();