Added a dialog to confirm discarding unsaved changes in Pin Table dialog.

This commit is contained in:
Maciej Suminski 2018-11-16 16:10:53 +01:00
parent de1a8abd3e
commit e3bcd31bff
5 changed files with 56 additions and 11 deletions

View File

@ -33,6 +33,7 @@
#include <wx/bmpcbox.h>
#include <kiface_i.h>
#include <kicad_string.h>
#include <confirm.h>
#define PinTableShownColumnsKey wxT( "PinTableShownColumns" )
@ -57,10 +58,11 @@ private:
std::vector<LIB_PINS> m_rows;
EDA_UNITS_T m_userUnits;
bool m_edited;
public:
PIN_TABLE_DATA_MODEL( EDA_UNITS_T aUserUnits ) :
m_userUnits( aUserUnits )
m_userUnits( aUserUnits ), m_edited( false )
{}
int GetNumberRows() override { return (int) m_rows.size(); }
@ -209,6 +211,8 @@ public:
break;
}
}
m_edited = true;
}
static int findRow( const std::vector<LIB_PINS>& aRowSet, const wxString& aName )
@ -343,6 +347,11 @@ public:
return removedRow;
}
bool IsEdited()
{
return m_edited;
}
};
@ -623,6 +632,36 @@ void DIALOG_LIB_EDIT_PIN_TABLE::OnUpdateUI( wxUpdateUIEvent& event )
}
void DIALOG_LIB_EDIT_PIN_TABLE::OnCancel( wxCommandEvent& event )
{
Close();
}
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 );
if( m_dataModel->IsEdited() )
{
if( !HandleUnsavedChanges( this, wxEmptyString,
[&]()->bool { return TransferDataFromWindow(); } ) )
{
event.Veto();
return;
}
}
if( IsQuasiModal() )
EndQuasiModal( wxID_OK );
else if( IsModal() )
EndModal( wxID_OK );
else
event.Skip();
}
void DIALOG_LIB_EDIT_PIN_TABLE::updateSummary()
{
PinNumbers pinNumbers;
@ -635,7 +674,3 @@ void DIALOG_LIB_EDIT_PIN_TABLE::updateSummary()
m_summary->SetLabel( pinNumbers.GetSummary() );
}

View File

@ -38,6 +38,8 @@ public:
void OnCellEdited( wxGridEvent& event ) override;
void OnRebuildRows( wxCommandEvent& event ) override;
void OnUpdateUI( wxUpdateUIEvent& event ) override;
void OnCancel( wxCommandEvent& event ) override;
void OnClose( wxCloseEvent& event ) override;
protected:
@ -50,6 +52,7 @@ protected:
wxString m_columnsShown;
LIB_PART* m_part;
LIB_PINS m_pins; // a copy of the pins owned by me
bool m_modified; ///< true when there are unsaved changes
PIN_TABLE_DATA_MODEL* m_dataModel;
};

View File

@ -1,8 +1,8 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 30 2017)
// C++ code generated with wxFormBuilder (version Oct 17 2016)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "widgets/wx_grid.h"
@ -124,6 +124,7 @@ DIALOG_LIB_EDIT_PIN_TABLE_BASE::DIALOG_LIB_EDIT_PIN_TABLE_BASE( wxWindow* parent
this->Centre( wxBOTH );
// Connect Events
this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnClose ) );
this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnUpdateUI ) );
m_grid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnCellEdited ), NULL, this );
m_grid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnSize ), NULL, this );
@ -131,11 +132,13 @@ DIALOG_LIB_EDIT_PIN_TABLE_BASE::DIALOG_LIB_EDIT_PIN_TABLE_BASE( wxWindow* parent
m_deleteButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnDeleteRow ), NULL, this );
m_cbGroup->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnRebuildRows ), NULL, this );
m_refreshButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnRebuildRows ), NULL, this );
m_ButtonsCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnCancel ), NULL, this );
}
DIALOG_LIB_EDIT_PIN_TABLE_BASE::~DIALOG_LIB_EDIT_PIN_TABLE_BASE()
{
// Disconnect Events
this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnClose ) );
this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnUpdateUI ) );
m_grid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnCellEdited ), NULL, this );
m_grid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnSize ), NULL, this );
@ -143,5 +146,6 @@ DIALOG_LIB_EDIT_PIN_TABLE_BASE::~DIALOG_LIB_EDIT_PIN_TABLE_BASE()
m_deleteButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnDeleteRow ), NULL, this );
m_cbGroup->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnRebuildRows ), NULL, this );
m_refreshButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnRebuildRows ), NULL, this );
m_ButtonsCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnCancel ), NULL, this );
}

View File

@ -61,7 +61,7 @@
<event name="OnAuiPaneRestore"></event>
<event name="OnAuiRender"></event>
<event name="OnChar"></event>
<event name="OnClose"></event>
<event name="OnClose">OnClose</event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnHibernate"></event>
@ -967,7 +967,7 @@
<property name="name">m_Buttons</property>
<property name="permission">protected</property>
<event name="OnApplyButtonClick"></event>
<event name="OnCancelButtonClick"></event>
<event name="OnCancelButtonClick">OnCancel</event>
<event name="OnContextHelpButtonClick"></event>
<event name="OnHelpButtonClick"></event>
<event name="OnNoButtonClick"></event>

View File

@ -1,8 +1,8 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 30 2017)
// C++ code generated with wxFormBuilder (version Oct 17 2016)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __DIALOG_LIB_EDIT_PIN_TABLE_BASE_H__
@ -11,6 +11,7 @@
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
class DIALOG_SHIM;
class WX_GRID;
#include "dialog_shim.h"
@ -56,12 +57,14 @@ class DIALOG_LIB_EDIT_PIN_TABLE_BASE : public DIALOG_SHIM
wxButton* m_ButtonsCancel;
// Virtual event handlers, overide them in your derived class
virtual void OnClose( wxCloseEvent& event ) = 0;
virtual void OnUpdateUI( wxUpdateUIEvent& event ) = 0;
virtual void OnCellEdited( wxGridEvent& event ) = 0;
virtual void OnSize( wxSizeEvent& event ) = 0;
virtual void OnAddRow( wxCommandEvent& event ) = 0;
virtual void OnDeleteRow( wxCommandEvent& event ) = 0;
virtual void OnRebuildRows( wxCommandEvent& event ) = 0;
virtual void OnCancel( wxCommandEvent& event ) = 0;
public: