From e1c449902d848d876ffa744baaf07096115d9214 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 10 Aug 2020 21:48:26 +0100 Subject: [PATCH] Ask user before throwing away changes to DRC Rules. Fixes https://gitlab.com/kicad/code/kicad/issues/5135 --- .../dialogs/dialog_fields_editor_global.cpp | 2 +- .../dialogs/dialog_lib_edit_pin_table.cpp | 31 ++++++++++++++----- include/widgets/paged_dialog.h | 8 ++++- pcbnew/dialogs/panel_setup_rules.cpp | 1 + 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index d59f1b02c2..b302e7a61e 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -1187,7 +1187,7 @@ void DIALOG_FIELDS_EDITOR_GLOBAL::OnClose( wxCloseEvent& event ) if( m_dataModel->IsEdited() ) { - if( !HandleUnsavedChanges( this, wxEmptyString, + if( !HandleUnsavedChanges( this, _( "Save changes?" ), [&]()->bool { return TransferDataFromWindow(); } ) ) { event.Veto(); diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp index cbb9bf5aef..ff77fa62a1 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp +++ b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp @@ -727,22 +727,37 @@ void DIALOG_LIB_EDIT_PIN_TABLE::OnClose( wxCloseEvent& event ) // This is a cancel, so commit quietly as we're going to throw the results away anyway. m_grid->CommitPendingChanges( true ); + int retval = wxCANCEL; + if( m_dataModel->IsEdited() ) { - if( !HandleUnsavedChanges( this, wxEmptyString, - [&]()->bool { return TransferDataFromWindow(); } ) ) + if( HandleUnsavedChanges( this, _( "Save changes?" ), + [&]()->bool + { + if( TransferDataFromWindow() ) + { + retval = wxOK; + return true; + } + + return false; + } ) ) + { + if( IsQuasiModal() ) + EndQuasiModal( retval ); + else + EndModal( retval ); + + return; + } + else { event.Veto(); return; } } - if( IsQuasiModal() ) - EndQuasiModal( wxID_CANCEL ); - else if( IsModal() ) - EndModal( wxID_CANCEL ); - else - event.Skip(); + event.Skip(); } diff --git a/include/widgets/paged_dialog.h b/include/widgets/paged_dialog.h index c9c419ea73..144a434dd6 100644 --- a/include/widgets/paged_dialog.h +++ b/include/widgets/paged_dialog.h @@ -46,6 +46,8 @@ class PAGED_DIALOG : public DIALOG_SHIM private: wxString m_title; + bool m_dirty; + wxString m_errorMessage; wxWindow* m_errorCtrl; // the control associated with m_errorMessage int m_errorRow; // the row if m_errorCtrl is a grid @@ -62,6 +64,8 @@ public: void SetInitialPage( const wxString& aPage, const wxString& aParentPage = wxEmptyString ); + void SetModified() { m_modified = true; } + void SetError( const wxString& aMessage, const wxString& aPageName, int aCtrlId, int aRow = -1, int aCol = -1 ); @@ -74,15 +78,17 @@ protected: bool TransferDataToWindow() override; bool TransferDataFromWindow() override; + void OnClose( wxCloseEvent& event ); + void OnCancel( wxCommandEvent& event ); virtual void OnAuxiliaryAction( wxCommandEvent& event ) { event.Skip(); } void OnResetButton( wxCommandEvent& aEvent ); void OnUpdateUI( wxUpdateUIEvent& event ); void OnPageChange( wxBookCtrlEvent& event ); - void OnPageChanging( wxBookCtrlEvent& aEvent ); PAGED_TREEBOOK* m_treebook; wxButton* m_auxiliaryButton; wxButton* m_resetButton; + wxButton* m_cancelButton; }; diff --git a/pcbnew/dialogs/panel_setup_rules.cpp b/pcbnew/dialogs/panel_setup_rules.cpp index 109a8b5f96..4293f63684 100644 --- a/pcbnew/dialogs/panel_setup_rules.cpp +++ b/pcbnew/dialogs/panel_setup_rules.cpp @@ -66,6 +66,7 @@ void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent ) { constexpr int flags = wxSTC_FIND_REGEXP| wxSTC_FIND_POSIX; + m_Parent->SetModified(); m_textEditor->SearchAnchor(); int i = std::max( 0, m_textEditor->SearchPrev( flags, "\( *rule " ) );