Don't leave stranded symbols/footprints in editors when doc closes.

Fixes https://gitlab.com/kicad/code/kicad/issues/10026

(cherry picked from commit 9af33cdfe8)
This commit is contained in:
Jeff Young 2021-12-22 14:27:38 +00:00
parent 2efa878287
commit 76fd029cd6
7 changed files with 108 additions and 17 deletions

View File

@ -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 );

View File

@ -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;
}

View File

@ -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.
*/

View File

@ -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( "*" );

View File

@ -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 ),

View File

@ -59,6 +59,8 @@ public:
bool IsCurrentFPFromBoard() const;
bool CanCloseFPFromBoard( bool doClose );
FOOTPRINT_EDITOR_SETTINGS* GetSettings();
APP_SETTINGS_BASE* config() const override;

View File

@ -104,6 +104,7 @@
#include <kiplatform/app.h>
#include <profile.h>
#include <view/wx_view_controls.h>
#include <footprint_viewer_frame.h>
#include <action_plugin.h>
#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();