EDA_BASE_FRAME::windowClosing( wxCloseEvent& event ): fix incorrect behavior.

windowClosing() calls Destroy() when the wxCloseEvent has no veto.
This is fine for usual EDA_BASE_FRAME frames, but not for frames shown in modal mode.
In modal mode, windowClosing() should not call Destroy(), because the calling frame
expects the instance not deleted after closing.
(the caller has to call Destroy() only once the frame can be actually deleted)
This commit is contained in:
jean-pierre charras 2020-09-01 17:45:20 +02:00
parent e6f4e156b6
commit 9fdadcbcf5
6 changed files with 50 additions and 42 deletions

View File

@ -153,7 +153,7 @@ void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event )
} }
if( event.GetId() == wxEVT_QUERY_END_SESSION if( event.GetId() == wxEVT_QUERY_END_SESSION
|| event.GetId() == wxEVT_END_SESSION ) || event.GetId() == wxEVT_END_SESSION )
{ {
// End session means the OS is going to terminate us // End session means the OS is going to terminate us
@ -170,7 +170,10 @@ void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event )
doCloseWindow(); doCloseWindow();
Destroy(); // Destroy (safe delete frame) this frame only in non modal mode.
// In modal mode, the caller will call Destroy().
if( !IsModal() )
Destroy();
} }
else else
{ {

View File

@ -125,6 +125,14 @@ class EDA_BASE_FRAME : public wxFrame, public TOOLS_HOLDER, public KIWAY_HOLDER
wxWindow* findQuasiModalDialog(); wxWindow* findQuasiModalDialog();
/**
* Return true if the frame is shown in our modal mode
* and false if the frame is shown as an usual frame
* In modal mode, the caller that created the frame is responsible to Destroy()
* this frame after closing
*/
virtual bool IsModal() const { return false; }
protected: protected:
FRAME_T m_Ident; // Id Type (pcb, schematic, library..) FRAME_T m_Ident; // Id Type (pcb, schematic, library..)
wxPoint m_FramePos; wxPoint m_FramePos;

View File

@ -173,7 +173,7 @@ public:
*/ */
bool Destroy() override; bool Destroy() override;
bool IsModal() const { return m_modal; } bool IsModal() const override { return m_modal; }
void SetModal( bool aIsModal ) { m_modal = aIsModal; } void SetModal( bool aIsModal ) { m_modal = aIsModal; }
/** /**

View File

@ -190,48 +190,48 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
} }
} }
auto wizard = (FOOTPRINT_WIZARD_FRAME*) Kiway().Player( FRAME_FOOTPRINT_WIZARD, true, FOOTPRINT_WIZARD_FRAME* wizard =
this ); (FOOTPRINT_WIZARD_FRAME*) Kiway().Player( FRAME_FOOTPRINT_WIZARD, true, this );
if( wizard->ShowModal( NULL, this ) ) if( wizard->ShowModal( NULL, this ) )
{ {
// Creates the new footprint from python script wizard // Creates the new footprint from python script wizard
MODULE* module = wizard->GetBuiltFootprint(); MODULE* module = wizard->GetBuiltFootprint();
if( module == NULL ) // i.e. if create module command aborted if( module ) // i.e. if create module command is OK
break;
Clear_Pcb( false );
GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
// Add the new object to board
AddModuleToBoard( module );
// Initialize data relative to nets and netclasses (for a new
// module the defaults are used)
// This is mandatory to handle and draw pads
GetBoard()->BuildListOfNets();
module->SetPosition( wxPoint( 0, 0 ) );
module->ClearFlags();
Zoom_Automatique( false );
GetScreen()->SetModify();
// If selected from the library tree then go ahead and save it there
if( !selected.GetLibNickname().empty() )
{ {
LIB_ID fpid = module->GetFPID(); Clear_Pcb( false );
fpid.SetLibNickname( selected.GetLibNickname() );
module->SetFPID( fpid ); GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
SaveFootprint( module ); // Add the new object to board
GetScreen()->ClrModify(); AddModuleToBoard( module );
// Initialize data relative to nets and netclasses (for a new
// module the defaults are used)
// This is mandatory to handle and draw pads
GetBoard()->BuildListOfNets();
module->SetPosition( wxPoint( 0, 0 ) );
module->ClearFlags();
Zoom_Automatique( false );
GetScreen()->SetModify();
// If selected from the library tree then go ahead and save it there
if( !selected.GetLibNickname().empty() )
{
LIB_ID fpid = module->GetFPID();
fpid.SetLibNickname( selected.GetLibNickname() );
module->SetFPID( fpid );
SaveFootprint( module );
GetScreen()->ClrModify();
}
updateView();
GetCanvas()->Refresh();
Update3DView( true );
SyncLibraryTree( false );
} }
updateView();
GetCanvas()->Refresh();
Update3DView( true );
SyncLibraryTree( false );
} }
wizard->Destroy(); wizard->Destroy();

View File

@ -255,10 +255,7 @@ void FOOTPRINT_WIZARD_FRAME::doCloseWindow()
if( !IsDismissed() ) if( !IsDismissed() )
DismissModal( false ); DismissModal( false );
} }
else // else do nothing
{
Destroy();
}
} }

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2012 Miguel Angel Ajo Pelayo, miguelangel@nbee.es * Copyright (C) 2012 Miguel Angel Ajo Pelayo, miguelangel@nbee.es
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License