Symbol Fields Table: add rename column functionality

This commit is contained in:
Mike Williams 2023-01-27 09:18:32 -05:00
parent 7286555529
commit e53ee9df4b
5 changed files with 176 additions and 4 deletions

View File

@ -241,6 +241,22 @@ public:
}
}
void RenameColumn( int aCol, const wxString& newName )
{
wxString fieldName = m_fieldNames[aCol];
m_fieldNames[aCol] = newName;
for( unsigned i = 0; i < m_symbolsList.GetCount(); ++i )
{
SCH_SYMBOL* symbol = m_symbolsList[i].GetSymbol();
auto node = m_dataStore[symbol->m_Uuid].extract( fieldName );
node.key() = newName;
m_dataStore[symbol->m_Uuid].insert( std::move( node ) );
}
}
int GetNumberRows() override { return m_rows.size(); }
// Columns are fieldNames + quantity column
@ -1136,7 +1152,10 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnRemoveField( wxCommandEvent& event )
m_fieldsCtrl->SelectRow( --row );
if( row < MANDATORY_FIELDS )
{
m_removeFieldButton->Enable( false );
m_renameFieldButton->Enable( false );
}
wxGridTableMessage msg( m_dataModel, wxGRIDTABLE_NOTIFY_COLS_DELETED,
m_fieldsCtrl->GetItemCount(), 1 );
@ -1153,6 +1172,69 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnRemoveField( wxCommandEvent& event )
}
void DIALOG_SYMBOL_FIELDS_TABLE::OnRenameField( wxCommandEvent& event )
{
int col = -1;
int row = m_fieldsCtrl->GetSelectedRow();
// Should never occur: "Rename Field..." button should be disabled if invalid selection
// via OnFieldsCtrlSelectionChanged()
wxCHECK_RET( row != -1, wxS( "Some user defined field must be selected first" ) );
wxCHECK_RET( row >= MANDATORY_FIELDS, wxS( "Mandatory fields cannot be renamed" ) );
wxString fieldName = m_fieldsCtrl->GetTextValue( row, 0 );
wxTextEntryDialog dlg( this, _( "New field name:" ), _( "Rename Field" ) );
if( dlg.ShowModal() != wxID_OK )
return;
wxString newFieldName = 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 ) )
{
if( col == -1 )
{
col = i;
}
else
{
wxString confirm_msg = wxString::Format(
_( "Field name %s already exists. Cannot rename over existing field." ),
fieldName );
DisplayError( this, confirm_msg );
return;
}
}
}
m_dataModel->RenameColumn( col, newFieldName );
m_fieldsCtrl->SetTextValue( newFieldName, col, 0 );
std::string oldKey( fieldName.ToUTF8() );
std::string newKey( newFieldName.ToUTF8() );
EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
//In-place rename map key
auto node = cfg->m_FieldEditorPanel.fields_show.extract( oldKey );
node.key() = newKey;
cfg->m_FieldEditorPanel.fields_show.insert( std::move( node ) );
cfg->m_FieldEditorPanel.fields_show[newKey] = true;
}
void DIALOG_SYMBOL_FIELDS_TABLE::OnFilterText( wxCommandEvent& aEvent )
{
m_dataModel->RebuildRows( m_filter, m_groupSymbolsBox, m_fieldsCtrl );
@ -1181,9 +1263,15 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnFieldsCtrlSelectionChanged( wxDataViewEvent&
int row = m_fieldsCtrl->GetSelectedRow();
if( row >= MANDATORY_FIELDS )
{
m_removeFieldButton->Enable( true );
m_renameFieldButton->Enable( true );
}
else
{
m_removeFieldButton->Enable( false );
m_renameFieldButton->Enable( false );
}
}
void DIALOG_SYMBOL_FIELDS_TABLE::OnColumnItemToggled( wxDataViewEvent& event )

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 Oliver Walters
* Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -66,6 +66,7 @@ private:
void OnSizeFieldList( wxSizeEvent& event ) override;
void OnAddField( wxCommandEvent& event ) override;
void OnRemoveField( wxCommandEvent& event ) override;
void OnRenameField( wxCommandEvent& event ) override;
void OnExport( wxCommandEvent& aEvent ) override;
void OnSaveAndContinue( wxCommandEvent& aEvent ) override;
void OnCancel( wxCommandEvent& aEvent ) override;

View File

@ -37,7 +37,12 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::DIALOG_SYMBOL_FIELDS_TABLE_BASE( wxWindow* pare
m_removeFieldButton = new wxButton( m_leftPanel, wxID_ANY, _("Remove Field..."), wxDefaultPosition, wxDefaultSize, 0 );
m_removeFieldButton->Enable( false );
bLeftSizer->Add( m_removeFieldButton, 0, wxEXPAND|wxBOTTOM|wxLEFT, 5 );
bLeftSizer->Add( m_removeFieldButton, 0, wxEXPAND|wxLEFT, 5 );
m_renameFieldButton = new wxButton( m_leftPanel, wxID_ANY, _("Rename Field..."), wxDefaultPosition, wxDefaultSize, 0 );
m_renameFieldButton->Enable( false );
bLeftSizer->Add( m_renameFieldButton, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxTOP, 5 );
m_leftPanel->SetSizer( bLeftSizer );
@ -156,6 +161,7 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::DIALOG_SYMBOL_FIELDS_TABLE_BASE( wxWindow* pare
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 );
m_renameFieldButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnRenameField ), NULL, this );
m_filter->Connect( wxEVT_MOTION, wxMouseEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnFilterMouseMoved ), NULL, this );
m_filter->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnFilterText ), NULL, this );
m_groupSymbolsBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnGroupSymbolsToggled ), NULL, this );
@ -180,6 +186,7 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::~DIALOG_SYMBOL_FIELDS_TABLE_BASE()
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 );
m_renameFieldButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnRenameField ), NULL, this );
m_filter->Disconnect( wxEVT_MOTION, wxMouseEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnFilterMouseMoved ), NULL, this );
m_filter->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnFilterText ), NULL, this );
m_groupSymbolsBox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_FIELDS_TABLE_BASE::OnGroupSymbolsToggled ), NULL, this );

View File

@ -286,7 +286,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxBOTTOM|wxLEFT</property>
<property name="flag">wxEXPAND|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
@ -358,6 +358,80 @@
<event name="OnButtonClick">OnRemoveField</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxEXPAND|wxLEFT|wxTOP</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="current"></property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="disabled"></property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">0</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="focus"></property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Rename Field...</property>
<property name="margins"></property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_renameFieldButton</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="position"></property>
<property name="pressed"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">OnRenameField</event>
</object>
</object>
</object>
</object>
</object>

View File

@ -50,6 +50,7 @@ class DIALOG_SYMBOL_FIELDS_TABLE_BASE : public DIALOG_SHIM
wxDataViewListCtrl* m_fieldsCtrl;
wxButton* m_addFieldButton;
wxButton* m_removeFieldButton;
wxButton* m_renameFieldButton;
wxPanel* m_rightPanel;
wxSearchCtrl* m_filter;
BITMAP_BUTTON* m_separator1;
@ -70,6 +71,7 @@ class DIALOG_SYMBOL_FIELDS_TABLE_BASE : public DIALOG_SHIM
virtual void OnSizeFieldList( wxSizeEvent& event ) { event.Skip(); }
virtual void OnAddField( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRemoveField( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRenameField( wxCommandEvent& event ) { event.Skip(); }
virtual void OnFilterMouseMoved( wxMouseEvent& event ) { event.Skip(); }
virtual void OnFilterText( wxCommandEvent& event ) { event.Skip(); }
virtual void OnGroupSymbolsToggled( wxCommandEvent& event ) { event.Skip(); }