diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index e5029ce670..04c4675b64 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -725,6 +725,51 @@ void DIALOG_FIELDS_EDITOR_GLOBAL::LoadFieldNames() } +void DIALOG_FIELDS_EDITOR_GLOBAL::OnAddField( wxCommandEvent& event ) +{ + // quantities column will become new field column, so it needs to be reset + auto attr = new wxGridCellAttr; + m_grid->SetColAttr( m_dataModel->GetColsCount() - 1, attr ); + m_grid->SetColFormatCustom( m_dataModel->GetColsCount() - 1, wxGRID_VALUE_STRING ); + + wxTextEntryDialog dlg( this, _( "New field name:" ), _( "Add Field" ) ); + + if( dlg.ShowModal() != wxID_OK ) + return; + + wxString fieldName = dlg.GetValue(); + + if( fieldName.IsEmpty() ) + { + DisplayError( this, _( "Field must have a name." ) ); + return; + } + + for( int i = 0; i < m_dataModel->GetNumberCols(); ++i ) + { + if( fieldName == m_dataModel->GetColLabelValue( i ) ) + { + DisplayError( this, wxString::Format( _( "Field name \"%s\" already in use." ), fieldName ) ); + return; + } + } + + m_config->Write( "SymbolFieldEditor/Show/" + fieldName, true ); + + AddField( fieldName, true, false ); + + wxGridTableMessage msg( m_dataModel, wxGRIDTABLE_NOTIFY_COLS_INSERTED, m_fieldsCtrl->GetItemCount(), 1 ); + m_grid->ProcessTableMessage( msg ); + + // set up attributes on the new quantities column + attr = new wxGridCellAttr; + attr->SetReadOnly(); + m_grid->SetColAttr( m_dataModel->GetColsCount() - 1, attr ); + m_grid->SetColFormatNumber( m_dataModel->GetColsCount() - 1 ); + m_grid->SetColMinimalWidth( m_dataModel->GetColsCount() - 1, 50 ); +} + + void DIALOG_FIELDS_EDITOR_GLOBAL::OnColumnItemToggled( wxDataViewEvent& event ) { wxDataViewItem item = event.GetItem(); diff --git a/eeschema/dialogs/dialog_fields_editor_global.h b/eeschema/dialogs/dialog_fields_editor_global.h index 122cb8daca..4d8abfc655 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.h +++ b/eeschema/dialogs/dialog_fields_editor_global.h @@ -43,10 +43,10 @@ public: bool TransferDataFromWindow() override; private: - wxConfigBase* m_config; - SCH_EDIT_FRAME* m_parent; - int m_showColWidth; - int m_groupByColWidth; + wxConfigBase* m_config; + SCH_EDIT_FRAME* m_parent; + int m_showColWidth; + int m_groupByColWidth; SCH_REFERENCE_LIST m_componentRefs; FIELDS_EDITOR_GRID_DATA_MODEL* m_dataModel; @@ -63,6 +63,7 @@ private: void OnTableCellClick( wxGridEvent& event ) override; void OnTableItemContextMenu( wxGridEvent& event ) override; void OnSizeFieldList( wxSizeEvent& event ) override; + void OnAddField( wxCommandEvent& event ) override; void OnSaveAndContinue( wxCommandEvent& aEvent ) override; void OnCancel( wxCommandEvent& event ) override; void OnClose( wxCloseEvent& event ) override; diff --git a/eeschema/dialogs/dialog_fields_editor_global_base.cpp b/eeschema/dialogs/dialog_fields_editor_global_base.cpp index 47a96a2c44..c3d00b8ec8 100644 --- a/eeschema/dialogs/dialog_fields_editor_global_base.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global_base.cpp @@ -48,6 +48,9 @@ DIALOG_FIELDS_EDITOR_GLOBAL_BASE::DIALOG_FIELDS_EDITOR_GLOBAL_BASE( wxWindow* pa bLeftSizer->Add( m_fieldsCtrl, 1, wxALL|wxEXPAND, 5 ); + m_addFieldButton = new wxButton( m_leftPanel, wxID_ANY, _("Add Field..."), wxDefaultPosition, wxDefaultSize, 0 ); + bLeftSizer->Add( m_addFieldButton, 0, wxALL|wxEXPAND, 5 ); + m_leftPanel->SetSizer( bLeftSizer ); m_leftPanel->Layout(); @@ -125,6 +128,7 @@ DIALOG_FIELDS_EDITOR_GLOBAL_BASE::DIALOG_FIELDS_EDITOR_GLOBAL_BASE( wxWindow* pa 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 ); m_fieldsCtrl->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnSizeFieldList ), NULL, this ); + m_addFieldButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnAddField ), NULL, this ); m_grid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnTableValueChanged ), NULL, this ); m_grid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnTableCellClick ), NULL, this ); m_grid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnTableCellClick ), NULL, this ); @@ -141,6 +145,7 @@ DIALOG_FIELDS_EDITOR_GLOBAL_BASE::~DIALOG_FIELDS_EDITOR_GLOBAL_BASE() 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 ); m_fieldsCtrl->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnSizeFieldList ), NULL, this ); + m_addFieldButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnAddField ), NULL, this ); m_grid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnTableValueChanged ), NULL, this ); m_grid->Disconnect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnTableCellClick ), NULL, this ); m_grid->Disconnect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnTableCellClick ), NULL, this ); diff --git a/eeschema/dialogs/dialog_fields_editor_global_base.fbp b/eeschema/dialogs/dialog_fields_editor_global_base.fbp index d7b91578ed..b3a9d710a6 100644 --- a/eeschema/dialogs/dialog_fields_editor_global_base.fbp +++ b/eeschema/dialogs/dialog_fields_editor_global_base.fbp @@ -531,6 +531,94 @@ + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Add Field... + + 0 + + + 0 + + 1 + m_addFieldButton + 1 + + + protected + 1 + + Resizable + 1 + + + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnAddField + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eeschema/dialogs/dialog_fields_editor_global_base.h b/eeschema/dialogs/dialog_fields_editor_global_base.h index 3894a6eec9..8f8af6927b 100644 --- a/eeschema/dialogs/dialog_fields_editor_global_base.h +++ b/eeschema/dialogs/dialog_fields_editor_global_base.h @@ -47,6 +47,7 @@ class DIALOG_FIELDS_EDITOR_GLOBAL_BASE : public DIALOG_SHIM wxCheckBox* m_groupComponentsBox; wxBitmapButton* m_bRefresh; wxDataViewListCtrl* m_fieldsCtrl; + wxButton* m_addFieldButton; wxPanel* m_panel4; wxGrid* m_grid; wxButton* m_button1; @@ -60,6 +61,7 @@ class DIALOG_FIELDS_EDITOR_GLOBAL_BASE : public DIALOG_SHIM virtual void OnRegroupComponents( wxCommandEvent& event ) { event.Skip(); } virtual void OnColumnItemToggled( wxDataViewEvent& event ) { event.Skip(); } virtual void OnSizeFieldList( wxSizeEvent& event ) { event.Skip(); } + virtual void OnAddField( wxCommandEvent& event ) { event.Skip(); } virtual void OnTableValueChanged( wxGridEvent& event ) { event.Skip(); } virtual void OnTableCellClick( wxGridEvent& event ) { event.Skip(); } virtual void OnTableItemContextMenu( wxGridEvent& event ) { event.Skip(); }