Simplify "Remove fields"
This commit is contained in:
parent
1b104f20b6
commit
50716ed8f2
|
@ -1103,42 +1103,42 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnAddField( wxCommandEvent& event )
|
|||
|
||||
void DIALOG_SYMBOL_FIELDS_TABLE::OnRemoveField( wxCommandEvent& event )
|
||||
{
|
||||
wxArrayString headers;
|
||||
std::vector<wxArrayString> fieldNames;
|
||||
int col = -1;
|
||||
int col = -1;
|
||||
int row = m_fieldsCtrl->GetSelectedRow();
|
||||
|
||||
headers.Add( _( "User Fields" ) );
|
||||
// Should never occur: "Remove Field..." button should be disabled if invalid selection
|
||||
// via OnFieldsCtrlSelectionChanged()
|
||||
wxCHECK_RET( row != -1, "Some user defined field must be selected first" );
|
||||
wxCHECK_RET( row >= MANDATORY_FIELDS, "Mandatory fields cannot be removed" );
|
||||
|
||||
for( int ii = MANDATORY_FIELDS; ii < m_fieldsCtrl->GetItemCount(); ++ii )
|
||||
wxString fieldName = m_fieldsCtrl->GetTextValue( row, 0 );
|
||||
|
||||
wxString confirm_msg = wxString::Format( _( "Are you sure you want to remove the field '%s'?" ),
|
||||
fieldName );
|
||||
|
||||
if( !IsOK( this, confirm_msg ) )
|
||||
return;
|
||||
|
||||
for( int i = 0; i < m_dataModel->GetNumberCols(); ++i )
|
||||
{
|
||||
wxArrayString fieldName;
|
||||
fieldName.Add( m_fieldsCtrl->GetTextValue( ii, 0 ) );
|
||||
fieldNames.emplace_back( fieldName );
|
||||
if( fieldName == m_dataModel->GetColLabelValue( i ) )
|
||||
col = i;
|
||||
}
|
||||
|
||||
EDA_LIST_DIALOG dlg( this, _( "Delete Field" ), headers, fieldNames, wxEmptyString );
|
||||
dlg.SetListLabel( _( "Select field:" ) );
|
||||
m_fieldsCtrl->DeleteItem( row );
|
||||
m_dataModel->RemoveColumn( col );
|
||||
|
||||
if( dlg.ShowModal() == wxID_OK )
|
||||
{
|
||||
wxString fieldName = dlg.GetTextSelection();
|
||||
// Make selection and update the state of "Remove field..." button via OnFieldsCtrlSelectionChanged()
|
||||
// Safe to decrement row index because we always have mandatory fields
|
||||
m_fieldsCtrl->SelectRow( --row );
|
||||
|
||||
for( int ii = 0; ii < m_dataModel->GetNumberCols(); ++ii )
|
||||
{
|
||||
if( fieldName == m_dataModel->GetColLabelValue( ii ) )
|
||||
col = ii;
|
||||
}
|
||||
}
|
||||
if( row < MANDATORY_FIELDS )
|
||||
m_removeFieldButton->Enable( false );
|
||||
|
||||
if( col >= 0 )
|
||||
{
|
||||
m_fieldsCtrl->DeleteItem( col );
|
||||
m_dataModel->RemoveColumn( col );
|
||||
|
||||
wxGridTableMessage msg( m_dataModel, wxGRIDTABLE_NOTIFY_COLS_DELETED,
|
||||
wxGridTableMessage msg( m_dataModel, wxGRIDTABLE_NOTIFY_COLS_DELETED,
|
||||
m_fieldsCtrl->GetItemCount(), 1 );
|
||||
m_grid->ProcessTableMessage( msg );
|
||||
}
|
||||
|
||||
m_grid->ProcessTableMessage( msg );
|
||||
|
||||
// set up attributes on the new quantities column
|
||||
wxGridCellAttr* attr = new wxGridCellAttr;
|
||||
|
@ -1172,6 +1172,15 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnFilterMouseMoved( wxMouseEvent& aEvent )
|
|||
SetCursor( wxCURSOR_IBEAM );
|
||||
}
|
||||
|
||||
void DIALOG_SYMBOL_FIELDS_TABLE::OnFieldsCtrlSelectionChanged( wxDataViewEvent& event )
|
||||
{
|
||||
int row = m_fieldsCtrl->GetSelectedRow();
|
||||
|
||||
if( row >= MANDATORY_FIELDS )
|
||||
m_removeFieldButton->Enable( true );
|
||||
else
|
||||
m_removeFieldButton->Enable( false );
|
||||
}
|
||||
|
||||
void DIALOG_SYMBOL_FIELDS_TABLE::OnColumnItemToggled( wxDataViewEvent& event )
|
||||
{
|
||||
|
|
|
@ -71,6 +71,7 @@ private:
|
|||
void OnClose( wxCloseEvent& aEvent ) override;
|
||||
void OnFilterText( wxCommandEvent& aEvent ) override;
|
||||
void OnFilterMouseMoved( wxMouseEvent& event ) override;
|
||||
void OnFieldsCtrlSelectionChanged( wxDataViewEvent& event ) override;
|
||||
|
||||
SCH_EDIT_FRAME* m_parent;
|
||||
int m_showColWidth;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version 3.10.0-39-g3487c3cb)
|
||||
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
|
@ -35,6 +35,8 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::DIALOG_SYMBOL_FIELDS_TABLE_BASE( wxWindow* pare
|
|||
bLeftSizer->Add( m_addFieldButton, 0, wxALL|wxEXPAND, 5 );
|
||||
|
||||
m_removeFieldButton = new wxButton( m_leftPanel, wxID_ANY, _("Remove Field..."), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
m_removeFieldButton->Enable( false );
|
||||
|
||||
bLeftSizer->Add( m_removeFieldButton, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
|
||||
|
||||
|
||||
|
@ -150,6 +152,7 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::DIALOG_SYMBOL_FIELDS_TABLE_BASE( wxWindow* pare
|
|||
// Connect Events
|
||||
this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnClose ) );
|
||||
m_fieldsCtrl->Connect( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnColumnItemToggled ), NULL, this );
|
||||
m_fieldsCtrl->Connect( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnFieldsCtrlSelectionChanged ), NULL, this );
|
||||
m_fieldsCtrl->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnSizeFieldList ), NULL, this );
|
||||
m_addFieldButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnAddField ), NULL, this );
|
||||
m_removeFieldButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnRemoveField ), NULL, this );
|
||||
|
@ -172,6 +175,7 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::~DIALOG_SYMBOL_FIELDS_TABLE_BASE()
|
|||
// Disconnect Events
|
||||
this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnClose ) );
|
||||
m_fieldsCtrl->Disconnect( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnColumnItemToggled ), NULL, this );
|
||||
m_fieldsCtrl->Disconnect( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnFieldsCtrlSelectionChanged ), NULL, this );
|
||||
m_fieldsCtrl->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnSizeFieldList ), NULL, this );
|
||||
m_addFieldButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnAddField ), NULL, this );
|
||||
m_removeFieldButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnRemoveField ), NULL, this );
|
||||
|
|
|
@ -206,6 +206,7 @@
|
|||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<event name="OnDataViewListCtrlItemValueChanged">OnColumnItemToggled</event>
|
||||
<event name="OnDataViewListCtrlSelectionChanged">OnFieldsCtrlSelectionChanged</event>
|
||||
<event name="OnSize">OnSizeFieldList</event>
|
||||
</object>
|
||||
</object>
|
||||
|
@ -313,7 +314,7 @@
|
|||
<property name="dock">Dock</property>
|
||||
<property name="dock_fixed">0</property>
|
||||
<property name="docking">Left</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="enabled">0</property>
|
||||
<property name="fg"></property>
|
||||
<property name="floatable">1</property>
|
||||
<property name="focus"></property>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version 3.10.0-39-g3487c3cb)
|
||||
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
|
@ -66,6 +66,7 @@ class DIALOG_SYMBOL_FIELDS_TABLE_BASE : public DIALOG_SHIM
|
|||
// Virtual event handlers, override them in your derived class
|
||||
virtual void OnClose( wxCloseEvent& event ) { event.Skip(); }
|
||||
virtual void OnColumnItemToggled( wxDataViewEvent& event ) { event.Skip(); }
|
||||
virtual void OnFieldsCtrlSelectionChanged( wxDataViewEvent& event ) { event.Skip(); }
|
||||
virtual void OnSizeFieldList( wxSizeEvent& event ) { event.Skip(); }
|
||||
virtual void OnAddField( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void OnRemoveField( wxCommandEvent& event ) { event.Skip(); }
|
||||
|
|
Loading…
Reference in New Issue