Highlight current row in Edit Symbol Fields, and save col widths.

Fixes https://gitlab.com/kicad/code/kicad/issues/4235
This commit is contained in:
Jeff Young 2020-04-21 16:15:04 +01:00
parent f113370e1e
commit 1916ea868b
7 changed files with 365 additions and 617 deletions

View File

@ -722,6 +722,9 @@ DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL( SCH_EDIT_FRAME* parent
m_grid->UseNativeColHeader( false );
m_grid->SetTable( m_dataModel, true );
// must be done after SetTable(), which appears to re-set it
m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
// sync m_grid's column visibilities to Show checkboxes in m_fieldsCtrl
for( int i = 0; i < m_fieldsCtrl->GetItemCount(); ++i )
{
@ -759,22 +762,34 @@ DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL( SCH_EDIT_FRAME* parent
m_grid->SetColFormatNumber( m_dataModel->GetColsCount() - 1 );
m_grid->AutoSizeColumns( false );
for( int col = 0; col < m_grid->GetNumberCols(); ++ col )
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 ) )
{
int textWidth = m_dataModel->GetDataWidth( col ) + COLUMN_MARGIN;
int maxWidth = defaultDlgSize.x / 3;
EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
wxString key = m_dataModel->GetColLabelValue( col );
if( col == m_grid->GetNumberCols() - 1 )
m_grid->SetColSize( col, std::min( std::max( 50, textWidth ), maxWidth ) );
if( cfg->m_FieldEditorPanel.column_widths.count( key ) )
{
int width = cfg->m_FieldEditorPanel.column_widths.at( key );
m_grid->SetColSize( col, width );
}
else
m_grid->SetColSize( col, std::min( std::max( 100, textWidth ), maxWidth ) );
{
int textWidth = m_dataModel->GetDataWidth( col ) + COLUMN_MARGIN;
int maxWidth = defaultDlgSize.x / 3;
if( col == m_grid->GetNumberCols() - 1 )
m_grid->SetColSize( col, std::min( std::max( 50, textWidth ), maxWidth ) );
else
m_grid->SetColSize( col, std::min( std::max( 100, textWidth ), maxWidth ) );
}
}
}
m_grid->SelectRow( 0 );
m_grid->SetGridCursor( 0, 1 );
SetInitialFocus( m_grid );
@ -884,31 +899,21 @@ void DIALOG_FIELDS_EDITOR_GLOBAL::AddField( const wxString& aName,
wxVector<wxVariant> fieldsCtrlRow;
auto cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
bool show = defaultShow;
bool sort_by = defaultSortBy;
EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
bool show = defaultShow;
bool sort_by = defaultSortBy;
std::string key( aName.ToUTF8() );
try
{
if( cfg->m_FieldEditorPanel.fields_show.count( key ) )
show = cfg->m_FieldEditorPanel.fields_show.at( key );
}
catch( std::out_of_range& )
{
}
try
{
show = cfg->m_FieldEditorPanel.fields_group_by.at( key );
}
catch( std::out_of_range& )
{
}
if( cfg->m_FieldEditorPanel.fields_group_by.count( key ) )
sort_by = cfg->m_FieldEditorPanel.fields_group_by.at( key );
fieldsCtrlRow.push_back( wxVariant( aName ) );
fieldsCtrlRow.push_back( wxVariant( show ) );
fieldsCtrlRow.push_back( wxVariant( sort_by ) );
fieldsCtrlRow.emplace_back( wxVariant( aName ) );
fieldsCtrlRow.emplace_back( wxVariant( show ) );
fieldsCtrlRow.emplace_back( wxVariant( sort_by ) );
m_fieldsCtrl->AppendItem( fieldsCtrlRow );
}
@ -1008,8 +1013,8 @@ void DIALOG_FIELDS_EDITOR_GLOBAL::OnAddField( wxCommandEvent& event )
void DIALOG_FIELDS_EDITOR_GLOBAL::OnColumnItemToggled( wxDataViewEvent& event )
{
auto cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
wxDataViewItem item = event.GetItem();
EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
wxDataViewItem item = event.GetItem();
int row = m_fieldsCtrl->ItemToRow( item );
int col = event.GetColumn();
@ -1083,13 +1088,26 @@ void DIALOG_FIELDS_EDITOR_GLOBAL::OnColSort( wxGridEvent& aEvent )
}
void DIALOG_FIELDS_EDITOR_GLOBAL::OnTableValueChanged( wxGridEvent& event )
void DIALOG_FIELDS_EDITOR_GLOBAL::OnTableValueChanged( wxGridEvent& aEvent )
{
m_grid->ForceRefresh();
}
void DIALOG_FIELDS_EDITOR_GLOBAL::OnRegroupComponents( wxCommandEvent& event )
void DIALOG_FIELDS_EDITOR_GLOBAL::OnTableColSize( wxGridSizeEvent& aEvent )
{
EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
int col = aEvent.GetRowOrCol();
wxString key = m_grid->GetColLabelValue( col );
if( m_grid->GetColSize( col ) )
cfg->m_FieldEditorPanel.column_widths[ key ] = m_grid->GetColSize( col );
aEvent.Skip();
}
void DIALOG_FIELDS_EDITOR_GLOBAL::OnRegroupComponents( wxCommandEvent& aEvent )
{
m_dataModel->RebuildRows( m_groupComponentsBox, m_fieldsCtrl );
m_dataModel->Sort( m_grid->GetSortingColumn(), m_grid->IsSortOrderAscending() );

View File

@ -62,6 +62,7 @@ private:
void OnTableValueChanged( wxGridEvent& event ) override;
void OnTableCellClick( wxGridEvent& event ) override;
void OnTableItemContextMenu( wxGridEvent& event ) override;
void OnTableColSize( wxGridSizeEvent& event ) override;
void OnSizeFieldList( wxSizeEvent& event ) override;
void OnAddField( wxCommandEvent& event ) override;
void OnSaveAndContinue( wxCommandEvent& aEvent ) override;

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 30 2017)
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -14,116 +14,116 @@
DIALOG_FIELDS_EDITOR_GLOBAL_BASE::DIALOG_FIELDS_EDITOR_GLOBAL_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxSize( -1,-1 ), wxDefaultSize );
wxBoxSizer* bMainSizer;
bMainSizer = new wxBoxSizer( wxVERTICAL );
m_splitter1 = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_LIVE_UPDATE );
m_splitter1->SetMinimumPaneSize( 200 );
m_leftPanel = new wxPanel( m_splitter1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxBoxSizer* bLeftSizer;
bLeftSizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bGroupSizer;
bGroupSizer = new wxBoxSizer( wxHORIZONTAL );
m_groupComponentsBox = new wxCheckBox( m_leftPanel, OPT_GROUP_COMPONENTS, _("Group symbols"), wxDefaultPosition, wxDefaultSize, 0 );
m_groupComponentsBox->SetValue(true);
m_groupComponentsBox->SetValue(true);
m_groupComponentsBox->SetToolTip( _("Group components together based on common properties") );
bGroupSizer->Add( m_groupComponentsBox, 0, wxALL|wxEXPAND, 5 );
bGroupSizer->Add( 0, 0, 1, wxEXPAND|wxRIGHT|wxLEFT, 10 );
m_bRefresh = new wxBitmapButton( m_leftPanel, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
m_bRefresh = new wxBitmapButton( m_leftPanel, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
m_bRefresh->SetMinSize( wxSize( 30,30 ) );
bGroupSizer->Add( m_bRefresh, 0, wxALIGN_CENTER_VERTICAL, 5 );
bLeftSizer->Add( bGroupSizer, 0, wxALL|wxBOTTOM|wxEXPAND|wxTOP, 2 );
m_fieldsCtrl = new wxDataViewListCtrl( m_leftPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
m_fieldsCtrl->SetMinSize( wxSize( -1,220 ) );
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();
bLeftSizer->Fit( m_leftPanel );
m_panel4 = new wxPanel( m_splitter1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxBoxSizer* bRightSizer;
bRightSizer = new wxBoxSizer( wxVERTICAL );
m_grid = new WX_GRID( m_panel4, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
// Grid
m_grid->CreateGrid( 5, 6 );
m_grid->CreateGrid( 5, 5 );
m_grid->EnableEditing( true );
m_grid->EnableGridLines( true );
m_grid->EnableDragGridSize( false );
m_grid->SetMargins( 0, 0 );
// Columns
m_grid->EnableDragColMove( true );
m_grid->EnableDragColSize( true );
m_grid->SetColLabelSize( 20 );
m_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
m_grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
// Rows
m_grid->EnableDragRowSize( false );
m_grid->SetRowLabelSize( 0 );
m_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
m_grid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
// Label Appearance
// Cell Defaults
m_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
m_grid->SetMinSize( wxSize( 400,240 ) );
bRightSizer->Add( m_grid, 1, wxALL|wxEXPAND, 5 );
m_panel4->SetSizer( bRightSizer );
m_panel4->Layout();
bRightSizer->Fit( m_panel4 );
m_splitter1->SplitVertically( m_leftPanel, m_panel4, -1 );
bMainSizer->Add( m_splitter1, 1, wxALL|wxEXPAND, 5 );
wxBoxSizer* bButtonsSizer;
bButtonsSizer = new wxBoxSizer( wxHORIZONTAL );
bButtonsSizer->Add( 0, 0, 1, wxEXPAND, 5 );
m_button1 = new wxButton( this, wxID_ANY, _("Apply, Save Schematic && Continue"), wxDefaultPosition, wxDefaultSize, 0 );
bButtonsSizer->Add( m_button1, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 );
m_sdbSizer1 = new wxStdDialogButtonSizer();
m_sdbSizer1OK = new wxButton( this, wxID_OK );
m_sdbSizer1->AddButton( m_sdbSizer1OK );
m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL );
m_sdbSizer1->AddButton( m_sdbSizer1Cancel );
m_sdbSizer1->Realize();
bButtonsSizer->Add( m_sdbSizer1, 0, wxBOTTOM|wxEXPAND|wxLEFT, 5 );
bMainSizer->Add( bButtonsSizer, 0, wxEXPAND, 5 );
this->SetSizer( bMainSizer );
this->Layout();
bMainSizer->Fit( this );
this->Centre( wxBOTH );
// Connect Events
this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnClose ) );
m_groupComponentsBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnGroupComponentsToggled ), NULL, this );
@ -135,6 +135,7 @@ DIALOG_FIELDS_EDITOR_GLOBAL_BASE::DIALOG_FIELDS_EDITOR_GLOBAL_BASE( wxWindow* pa
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 );
m_grid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnTableItemContextMenu ), NULL, this );
m_grid->Connect( wxEVT_GRID_COL_SIZE, wxGridSizeEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnTableColSize ), NULL, this );
m_button1->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnSaveAndContinue ), NULL, this );
m_sdbSizer1Cancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnCancel ), NULL, this );
}
@ -152,7 +153,8 @@ DIALOG_FIELDS_EDITOR_GLOBAL_BASE::~DIALOG_FIELDS_EDITOR_GLOBAL_BASE()
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 );
m_grid->Disconnect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnTableItemContextMenu ), NULL, this );
m_grid->Disconnect( wxEVT_GRID_COL_SIZE, wxGridSizeEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnTableColSize ), NULL, this );
m_button1->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnSaveAndContinue ), NULL, this );
m_sdbSizer1Cancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL_BASE::OnCancel ), NULL, this );
}

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,11 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 30 2017)
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __DIALOG_FIELDS_EDITOR_GLOBAL_BASE_H__
#define __DIALOG_FIELDS_EDITOR_GLOBAL_BASE_H__
#pragma once
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
@ -20,10 +19,10 @@ class WX_GRID;
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/bmpbuttn.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/bmpbuttn.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include <wx/dataview.h>
@ -42,7 +41,7 @@ class WX_GRID;
class DIALOG_FIELDS_EDITOR_GLOBAL_BASE : public DIALOG_SHIM
{
private:
protected:
wxSplitterWindow* m_splitter1;
wxPanel* m_leftPanel;
@ -56,7 +55,7 @@ class DIALOG_FIELDS_EDITOR_GLOBAL_BASE : public DIALOG_SHIM
wxStdDialogButtonSizer* m_sdbSizer1;
wxButton* m_sdbSizer1OK;
wxButton* m_sdbSizer1Cancel;
// Virtual event handlers, overide them in your derived class
virtual void OnClose( wxCloseEvent& event ) { event.Skip(); }
virtual void OnGroupComponentsToggled( wxCommandEvent& event ) { event.Skip(); }
@ -67,15 +66,15 @@ class DIALOG_FIELDS_EDITOR_GLOBAL_BASE : public DIALOG_SHIM
virtual void OnTableValueChanged( wxGridEvent& event ) { event.Skip(); }
virtual void OnTableCellClick( wxGridEvent& event ) { event.Skip(); }
virtual void OnTableItemContextMenu( wxGridEvent& event ) { event.Skip(); }
virtual void OnTableColSize( wxGridSizeEvent& event ) { event.Skip(); }
virtual void OnSaveAndContinue( wxCommandEvent& event ) { event.Skip(); }
virtual void OnCancel( wxCommandEvent& event ) { event.Skip(); }
public:
DIALOG_FIELDS_EDITOR_GLOBAL_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Symbol Fields"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxRESIZE_BORDER );
DIALOG_FIELDS_EDITOR_GLOBAL_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Symbol Fields"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxRESIZE_BORDER );
~DIALOG_FIELDS_EDITOR_GLOBAL_BASE();
};
#endif //__DIALOG_FIELDS_EDITOR_GLOBAL_BASE_H__

View File

@ -194,6 +194,9 @@ EESCHEMA_SETTINGS::EESCHEMA_SETTINGS() : APP_SETTINGS_BASE( "eeschema", eeschema
m_params.emplace_back( new PARAM_MAP<bool>( "field_editor.fields_group_by",
&m_FieldEditorPanel.fields_group_by, {} ) );
m_params.emplace_back( new PARAM_MAP<int>( "field_editor.column_widths",
&m_FieldEditorPanel.column_widths, {} ) );
m_params.emplace_back( new PARAM<bool>( "plot.background_color",
&m_PlotPanel.background_color, false ) );

View File

@ -120,6 +120,7 @@ public:
{
std::map<std::string, bool> fields_show;
std::map<std::string, bool> fields_group_by;
std::map<std::string, int> column_widths;
};
struct PANEL_LIB_VIEW