diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index 4a874b47eb..17c47779de 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -93,6 +93,7 @@ protected: SCH_EDIT_FRAME* m_frame; SCH_REFERENCE_LIST m_componentRefs; + bool m_edited; std::vector m_fieldNames; int m_sortColumn; bool m_sortAscending; @@ -116,6 +117,7 @@ public: FIELDS_EDITOR_GRID_DATA_MODEL( SCH_EDIT_FRAME* aFrame, SCH_REFERENCE_LIST& aComponentList ) : m_frame( aFrame ), m_componentRefs( aComponentList ), + m_edited( false ), m_sortAscending( false ) { m_componentRefs.SplitReferences(); @@ -237,6 +239,8 @@ public: for( const auto& ref : rowGroup.m_Refs ) m_dataStore[ ref.GetComp()->GetTimeStamp() ][ fieldName ] = aValue; + + m_edited = true; } @@ -513,6 +517,13 @@ public: destField->SetText( srcValue ); } } + + m_edited = false; + } + + bool IsEdited() + { + return m_edited; } }; @@ -847,3 +858,35 @@ void DIALOG_FIELDS_EDITOR_GLOBAL::OnSaveAndContinue( wxCommandEvent& aEvent ) m_parent->OnSaveProject( dummyEvent ); } } + + +void DIALOG_FIELDS_EDITOR_GLOBAL::OnCancel( wxCommandEvent& event ) +{ + Close(); +} + + +void DIALOG_FIELDS_EDITOR_GLOBAL::OnClose( wxCloseEvent& event ) +{ + // Commit any pending in-place edits and close the editor + m_grid->DisableCellEditControl(); + + if( m_dataModel->IsEdited() ) + { + switch( DisplayExitDialog( this, wxEmptyString ) ) + { + case wxID_CANCEL: + event.Veto(); + break; + + case wxID_YES: + if( TransferDataFromWindow() ) + event.Skip(); + break; + + case wxID_NO: + event.Skip(); + break; + } + } +} diff --git a/eeschema/dialogs/dialog_fields_editor_global.h b/eeschema/dialogs/dialog_fields_editor_global.h index b7872a4588..b6e6d2c7ed 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.h +++ b/eeschema/dialogs/dialog_fields_editor_global.h @@ -64,6 +64,8 @@ private: void OnTableItemContextMenu( wxGridEvent& event ) override; void OnSizeFieldList( wxSizeEvent& event ) override; void OnSaveAndContinue( wxCommandEvent& aEvent ) override; + void OnCancel( wxCommandEvent& event ) override; + void OnClose( wxCloseEvent& event ) override; }; #endif /* DIALOG_FIELDS_EDITOR_GLOBAL_H */ diff --git a/eeschema/dialogs/dialog_fields_editor_global_base.cpp b/eeschema/dialogs/dialog_fields_editor_global_base.cpp index 9745cd70ca..47a96a2c44 100644 --- a/eeschema/dialogs/dialog_fields_editor_global_base.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global_base.cpp @@ -120,6 +120,7 @@ DIALOG_FIELDS_EDITOR_GLOBAL_BASE::DIALOG_FIELDS_EDITOR_GLOBAL_BASE( wxWindow* pa this->Centre( wxBOTH ); // Connect Events + this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnClose ) ); m_groupComponentsBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnGroupComponentsToggled ), NULL, this ); m_bRefresh->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnRegroupComponents ), NULL, this ); m_fieldsCtrl->Connect( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnColumnItemToggled ), NULL, this ); @@ -130,12 +131,12 @@ DIALOG_FIELDS_EDITOR_GLOBAL_BASE::DIALOG_FIELDS_EDITOR_GLOBAL_BASE( wxWindow* pa m_grid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnTableItemContextMenu ), NULL, this ); m_button1->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnSaveAndContinue ), NULL, this ); m_sdbSizer1Cancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnCancel ), NULL, this ); - m_sdbSizer1OK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnOK ), NULL, this ); } DIALOG_FIELDS_EDITOR_GLOBAL_BASE::~DIALOG_FIELDS_EDITOR_GLOBAL_BASE() { // Disconnect Events + this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnClose ) ); m_groupComponentsBox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnGroupComponentsToggled ), NULL, this ); m_bRefresh->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnRegroupComponents ), NULL, this ); m_fieldsCtrl->Disconnect( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnColumnItemToggled ), NULL, this ); @@ -146,6 +147,5 @@ DIALOG_FIELDS_EDITOR_GLOBAL_BASE::~DIALOG_FIELDS_EDITOR_GLOBAL_BASE() m_grid->Disconnect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnTableItemContextMenu ), NULL, this ); m_button1->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnSaveAndContinue ), NULL, this ); m_sdbSizer1Cancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnCancel ), NULL, this ); - m_sdbSizer1OK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnOK ), NULL, this ); } diff --git a/eeschema/dialogs/dialog_fields_editor_global_base.fbp b/eeschema/dialogs/dialog_fields_editor_global_base.fbp index 5e8fab549b..d7b91578ed 100644 --- a/eeschema/dialogs/dialog_fields_editor_global_base.fbp +++ b/eeschema/dialogs/dialog_fields_editor_global_base.fbp @@ -61,7 +61,7 @@ - + OnClose @@ -890,7 +890,7 @@ - OnOK + diff --git a/eeschema/dialogs/dialog_fields_editor_global_base.h b/eeschema/dialogs/dialog_fields_editor_global_base.h index 9307d1cc8a..3894a6eec9 100644 --- a/eeschema/dialogs/dialog_fields_editor_global_base.h +++ b/eeschema/dialogs/dialog_fields_editor_global_base.h @@ -55,6 +55,7 @@ class DIALOG_FIELDS_EDITOR_GLOBAL_BASE : public DIALOG_SHIM wxButton* m_sdbSizer1Cancel; // Virtual event handlers, overide them in your derived class + virtual void OnClose( wxCloseEvent& event ) { event.Skip(); } virtual void OnGroupComponentsToggled( wxCommandEvent& event ) { event.Skip(); } virtual void OnRegroupComponents( wxCommandEvent& event ) { event.Skip(); } virtual void OnColumnItemToggled( wxDataViewEvent& event ) { event.Skip(); } @@ -64,7 +65,6 @@ class DIALOG_FIELDS_EDITOR_GLOBAL_BASE : public DIALOG_SHIM virtual void OnTableItemContextMenu( wxGridEvent& event ) { event.Skip(); } virtual void OnSaveAndContinue( wxCommandEvent& event ) { event.Skip(); } virtual void OnCancel( wxCommandEvent& event ) { event.Skip(); } - virtual void OnOK( wxCommandEvent& event ) { event.Skip(); } public: