From 34d069ffd823a1f8acdd3b6509738d9ccdbf0d58 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 31 Aug 2020 00:47:16 +0100 Subject: [PATCH] Bubble cancel up from app to kicad manager when closing. Fixes https://gitlab.com/kicad/code/kicad/issues/5402 --- common/eda_base_frame.cpp | 7 +++++-- kicad/kicad_manager_frame.cpp | 32 +++++++++++++++++++++++--------- kicad/kicad_manager_frame.h | 1 + 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index 93019f4286..a4f2143d20 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -144,7 +144,9 @@ void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event ) quasiModal->Raise(); wxBell(); - event.Veto(); + if( event.CanVeto() ) + event.Veto(); + return; } @@ -170,7 +172,8 @@ void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event ) } else { - event.Veto(); + if( event.CanVeto() ) + event.Veto(); } } diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index 40769e794a..2bfde87156 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -324,6 +324,27 @@ void KICAD_MANAGER_FRAME::OnSize( wxSizeEvent& event ) } +bool KICAD_MANAGER_FRAME::canCloseWindow( wxCloseEvent& aEvent ) +{ + KICAD_SETTINGS* settings = kicadSettings(); + settings->m_OpenProjects = GetSettingsManager()->GetOpenProjects(); + + // CloseProject will recursively ask all the open editors if they need to save changes. + // If any of them cancel then we need to cancel closing the KICAD_MANAGER_FRAME. + if( CloseProject( true ) ) + { + return true; + } + else + { + if( aEvent.CanVeto() ) + aEvent.Veto(); + + return false; + } +} + + void KICAD_MANAGER_FRAME::doCloseWindow() { #ifdef _WINDOWS_ @@ -342,16 +363,9 @@ void KICAD_MANAGER_FRAME::doCloseWindow() } #endif - // Save the list of open projects before closing the project - KICAD_SETTINGS* settings = kicadSettings(); - settings->m_OpenProjects = GetSettingsManager()->GetOpenProjects(); + m_leftWin->Show( false ); - if( CloseProject( true ) ) - { - m_leftWin->Show( false ); - - Destroy(); - } + Destroy(); #ifdef _WINDOWS_ lock_close_event = 0; // Reenable event management diff --git a/kicad/kicad_manager_frame.h b/kicad/kicad_manager_frame.h index 89250b041f..6ab6533301 100644 --- a/kicad/kicad_manager_frame.h +++ b/kicad/kicad_manager_frame.h @@ -85,6 +85,7 @@ public: void OnIdle( wxIdleEvent& event ); + bool canCloseWindow( wxCloseEvent& aCloseEvent ) override; void doCloseWindow() override; void OnSize( wxSizeEvent& event );