Symbol Fields Table: save current table properties
Fixes: https://gitlab.com/kicad/code/kicad/-/issues/5006
This commit is contained in:
parent
e53ee9df4b
commit
1982c1af80
|
@ -768,6 +768,7 @@ DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE( SCH_EDIT_FRAME* parent )
|
|||
DIALOG_SYMBOL_FIELDS_TABLE_BASE( parent ),
|
||||
m_parent( parent )
|
||||
{
|
||||
EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
||||
wxSize defaultDlgSize = ConvertDialogToPixels( wxSize( 600, 300 ) );
|
||||
int nameColWidthMargin = 44;
|
||||
|
||||
|
@ -803,6 +804,9 @@ DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE( SCH_EDIT_FRAME* parent )
|
|||
m_fieldsCtrl->SetIndent( 0 );
|
||||
|
||||
m_filter->SetDescriptiveText( _( "Filter" ) );
|
||||
m_filter->ChangeValue( cfg->m_FieldEditorPanel.filter_string );
|
||||
|
||||
m_groupSymbolsBox->SetValue( cfg->m_FieldEditorPanel.group_symbols );
|
||||
|
||||
m_dataModel = new FIELDS_EDITOR_GRID_DATA_MODEL( m_parent, m_symbolsList );
|
||||
|
||||
|
@ -831,7 +835,6 @@ DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE( SCH_EDIT_FRAME* parent )
|
|||
m_splitterMainWindow->SetSashPosition( fieldsMinWidth + 40 );
|
||||
|
||||
m_dataModel->RebuildRows( m_filter, m_groupSymbolsBox, m_fieldsCtrl );
|
||||
m_dataModel->Sort( 0, true );
|
||||
|
||||
m_grid->UseNativeColHeader( true );
|
||||
m_grid->SetTable( m_dataModel, true );
|
||||
|
@ -876,13 +879,16 @@ DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE( SCH_EDIT_FRAME* parent )
|
|||
m_grid->SetColFormatNumber( m_dataModel->GetColsCount() - 1 );
|
||||
m_grid->AutoSizeColumns( false );
|
||||
|
||||
// Restore column sorting order and widths
|
||||
int sortCol = 0;
|
||||
bool sortAscending = true;
|
||||
|
||||
for( int col = 0; col < m_grid->GetNumberCols(); ++col )
|
||||
{
|
||||
// Columns are hidden by setting their width to 0 so if we resize them they will
|
||||
// become unhidden.
|
||||
if( m_grid->IsColShown( col ) )
|
||||
{
|
||||
EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
||||
std::string key( m_dataModel->GetCanonicalColLabel( col ).ToUTF8() );
|
||||
|
||||
if( cfg->m_FieldEditorPanel.column_widths.count( key ) )
|
||||
|
@ -900,8 +906,28 @@ DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE( SCH_EDIT_FRAME* parent )
|
|||
else
|
||||
m_grid->SetColSize( col, Clamp( 100, textWidth, maxWidth ) );
|
||||
}
|
||||
|
||||
if( cfg->m_FieldEditorPanel.column_sorts.count( key ) )
|
||||
{
|
||||
sortCol = col;
|
||||
sortAscending = cfg->m_FieldEditorPanel.column_sorts[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_dataModel->Sort( sortCol, sortAscending );
|
||||
m_grid->SetSortingColumn( sortCol, sortAscending );
|
||||
|
||||
// Restore user column order
|
||||
for( int col = 0; col < (int) cfg->m_FieldEditorPanel.column_order.size(); col++ )
|
||||
{
|
||||
int pos = cfg->m_FieldEditorPanel.column_order[col];
|
||||
|
||||
if( col >= m_grid->GetNumberCols() || pos >= m_grid->GetNumberCols() )
|
||||
break;
|
||||
|
||||
m_grid->SetColPos( col, pos );
|
||||
}
|
||||
|
||||
m_grid->SelectRow( 0 );
|
||||
m_grid->SetGridCursor( 0, 1 );
|
||||
|
@ -916,6 +942,8 @@ DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE( SCH_EDIT_FRAME* parent )
|
|||
// Connect Events
|
||||
m_grid->Connect( wxEVT_GRID_COL_SORT,
|
||||
wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnColSort ), nullptr, this );
|
||||
m_grid->Connect( wxEVT_GRID_COL_MOVE,
|
||||
wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnColMove ), nullptr, this );
|
||||
}
|
||||
|
||||
|
||||
|
@ -925,6 +953,9 @@ DIALOG_SYMBOL_FIELDS_TABLE::~DIALOG_SYMBOL_FIELDS_TABLE()
|
|||
m_grid->Disconnect( wxEVT_GRID_COL_SORT,
|
||||
wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnColSort ), nullptr,
|
||||
this );
|
||||
m_grid->Disconnect( wxEVT_GRID_COL_SORT,
|
||||
wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnColMove ), nullptr,
|
||||
this );
|
||||
|
||||
// Delete the GRID_TRICKS.
|
||||
m_grid->PopEventHandler( true );
|
||||
|
@ -1237,6 +1268,9 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnRenameField( wxCommandEvent& event )
|
|||
|
||||
void DIALOG_SYMBOL_FIELDS_TABLE::OnFilterText( wxCommandEvent& aEvent )
|
||||
{
|
||||
EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
||||
|
||||
cfg->m_FieldEditorPanel.filter_string = m_filter->GetValue();
|
||||
m_dataModel->RebuildRows( m_filter, m_groupSymbolsBox, m_fieldsCtrl );
|
||||
m_dataModel->Sort( m_grid->GetSortingColumn(), m_grid->IsSortOrderAscending() );
|
||||
m_grid->ForceRefresh();
|
||||
|
@ -1327,6 +1361,9 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnColumnItemToggled( wxDataViewEvent& event )
|
|||
|
||||
void DIALOG_SYMBOL_FIELDS_TABLE::OnGroupSymbolsToggled( wxCommandEvent& event )
|
||||
{
|
||||
EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
||||
|
||||
cfg->m_FieldEditorPanel.group_symbols = m_groupSymbolsBox->GetValue();
|
||||
m_dataModel->RebuildRows( m_filter, m_groupSymbolsBox, m_fieldsCtrl );
|
||||
m_dataModel->Sort( m_grid->GetSortingColumn(), m_grid->IsSortOrderAscending() );
|
||||
m_grid->ForceRefresh();
|
||||
|
@ -1335,7 +1372,9 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnGroupSymbolsToggled( wxCommandEvent& event )
|
|||
|
||||
void DIALOG_SYMBOL_FIELDS_TABLE::OnColSort( wxGridEvent& aEvent )
|
||||
{
|
||||
EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
||||
int sortCol = aEvent.GetCol();
|
||||
std::string key( m_dataModel->GetCanonicalColLabel( sortCol ).ToUTF8() );
|
||||
bool ascending;
|
||||
|
||||
// This is bonkers, but wxWidgets doesn't tell us ascending/descending in the event, and
|
||||
|
@ -1351,11 +1390,30 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnColSort( wxGridEvent& aEvent )
|
|||
ascending = true;
|
||||
}
|
||||
|
||||
// We only support sorting on one column at this time
|
||||
cfg->m_FieldEditorPanel.column_sorts.clear();
|
||||
cfg->m_FieldEditorPanel.column_sorts[key] = ascending;
|
||||
|
||||
m_dataModel->Sort( sortCol, ascending );
|
||||
m_grid->ForceRefresh();
|
||||
}
|
||||
|
||||
|
||||
void DIALOG_SYMBOL_FIELDS_TABLE::OnColMove( wxGridEvent& aEvent )
|
||||
{
|
||||
CallAfter(
|
||||
[this]()
|
||||
{
|
||||
EESCHEMA_SETTINGS* cfg =
|
||||
static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
||||
cfg->m_FieldEditorPanel.column_order.clear();
|
||||
|
||||
for( int i = 0; i < m_grid->GetNumberCols(); i++ )
|
||||
cfg->m_FieldEditorPanel.column_order.emplace_back( m_grid->GetColPos( i ) );
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
void DIALOG_SYMBOL_FIELDS_TABLE::OnTableValueChanged( wxGridEvent& aEvent )
|
||||
{
|
||||
m_grid->ForceRefresh();
|
||||
|
|
|
@ -54,6 +54,7 @@ private:
|
|||
void LoadFieldNames();
|
||||
|
||||
void OnColSort( wxGridEvent& aEvent );
|
||||
void OnColMove( wxGridEvent& aEvent );
|
||||
|
||||
void OnColumnItemToggled( wxDataViewEvent& event ) override;
|
||||
void OnGroupSymbolsToggled( wxCommandEvent& event ) override;
|
||||
|
|
|
@ -365,6 +365,18 @@ EESCHEMA_SETTINGS::EESCHEMA_SETTINGS() :
|
|||
m_params.emplace_back( new PARAM_MAP<int>( "field_editor.column_widths",
|
||||
&m_FieldEditorPanel.column_widths, {} ) );
|
||||
|
||||
m_params.emplace_back( new PARAM_MAP<bool>( "field_editor.column_sorts",
|
||||
&m_FieldEditorPanel.column_sorts, {} ) );
|
||||
|
||||
m_params.emplace_back( new PARAM_LIST<int>( "field_editor.column_order",
|
||||
&m_FieldEditorPanel.column_order, {} ) );
|
||||
|
||||
m_params.emplace_back( new PARAM<wxString>( "field_editor.filter_string",
|
||||
&m_FieldEditorPanel.filter_string, {} ) );
|
||||
|
||||
m_params.emplace_back( new PARAM<bool>( "field_editor.group_symbols",
|
||||
&m_FieldEditorPanel.group_symbols, true ) );
|
||||
|
||||
m_params.emplace_back( new PARAM<bool>( "plot.background_color",
|
||||
&m_PlotPanel.background_color, false ) );
|
||||
|
||||
|
|
|
@ -197,6 +197,10 @@ public:
|
|||
std::map<std::string, bool> fields_show;
|
||||
std::map<std::string, bool> fields_group_by;
|
||||
std::map<std::string, int> column_widths;
|
||||
std::map<std::string, bool> column_sorts;
|
||||
std::vector<int> column_order;
|
||||
wxString filter_string;
|
||||
bool group_symbols;
|
||||
};
|
||||
|
||||
struct PANEL_LIB_VIEW
|
||||
|
|
Loading…
Reference in New Issue