Split lib tree initialization into a two-pass affair.

This is under the supposition that we can't set the column widths
on some Mac instances because the host controls haven't yet been
created.  This is primarily conjecture based on looking at things
that have the *possibility* of going wrong.  Why this only happens
in some installs is beyond me.

Fixes https://gitlab.com/kicad/code/kicad/issues/5479
This commit is contained in:
Jeff Young 2021-04-01 10:49:05 +01:00
parent 655a696589
commit 0c4184f1a4
6 changed files with 26 additions and 23 deletions

View File

@ -281,23 +281,12 @@ void LIB_TREE_MODEL_ADAPTER::AttachTo( wxDataViewCtrl* aDataViewCtrl )
wxString descHead = _( "Description" ); wxString descHead = _( "Description" );
// The extent of the text doesn't take into account the space on either side // The extent of the text doesn't take into account the space on either side
// in the header, so artificially pad it by M // in the header, so artificially pad it
wxSize partHeadMinWidth = KIUI::GetTextSize( partHead + "M", aDataViewCtrl ); wxSize partHeadMinWidth = KIUI::GetTextSize( partHead + "MMM", aDataViewCtrl );
if( aDataViewCtrl->GetColumnCount() > 0 ) // Ensure the part column is wider than the smallest allowable width
{ if( m_colWidths[PART_COL] < partHeadMinWidth.x )
int partWidth = aDataViewCtrl->GetColumn( PART_COL )->GetWidth(); m_colWidths[PART_COL] = partHeadMinWidth.x;
int descWidth = aDataViewCtrl->GetColumn( DESC_COL )->GetWidth();
// Only use the widths read back if they are non-zero.
// GTK returns the displayed width of the column, which is not calculated immediately
// this leads to cases of 0 column width if the user types too fast in the filter
if( descWidth > 0 )
{
m_colWidths[PART_COL] = partWidth;
m_colWidths[DESC_COL] = descWidth;
}
}
m_widget = aDataViewCtrl; m_widget = aDataViewCtrl;
aDataViewCtrl->SetIndent( kDataViewIndent ); aDataViewCtrl->SetIndent( kDataViewIndent );
@ -309,13 +298,6 @@ void LIB_TREE_MODEL_ADAPTER::AttachTo( wxDataViewCtrl* aDataViewCtrl )
m_col_desc = aDataViewCtrl->AppendTextColumn( descHead, DESC_COL, wxDATAVIEW_CELL_INERT, m_col_desc = aDataViewCtrl->AppendTextColumn( descHead, DESC_COL, wxDATAVIEW_CELL_INERT,
m_colWidths[DESC_COL] ); m_colWidths[DESC_COL] );
// Ensure the part column is wider than the smallest allowable width
if( m_colWidths[PART_COL] < partHeadMinWidth.x )
{
m_colWidths[PART_COL] = partHeadMinWidth.x;
m_col_part->SetWidth( partHeadMinWidth.x );
}
m_col_part->SetMinWidth( partHeadMinWidth.x ); m_col_part->SetMinWidth( partHeadMinWidth.x );
} }
@ -401,6 +383,13 @@ unsigned int LIB_TREE_MODEL_ADAPTER::GetChildren( wxDataViewItem const& aItem,
} }
void LIB_TREE_MODEL_ADAPTER::FinishTreeInitialization()
{
m_col_part->SetWidth( m_colWidths[PART_COL] );
m_col_desc->SetWidth( m_colWidths[DESC_COL] );
}
void LIB_TREE_MODEL_ADAPTER::RefreshTree() void LIB_TREE_MODEL_ADAPTER::RefreshTree()
{ {
// Yes, this is an enormous hack. But it works on all platforms, it doesn't suffer // Yes, this is an enormous hack. But it works on all platforms, it doesn't suffer

View File

@ -125,6 +125,8 @@ DIALOG_CHOOSE_SYMBOL::DIALOG_CHOOSE_SYMBOL( SCH_BASE_FRAME* aParent, const wxStr
treePanel->Layout(); treePanel->Layout();
treeSizer->Fit( treePanel ); treeSizer->Fit( treePanel );
aAdapter->FinishTreeInitialization();
m_hsplitter->SetSashGravity( 0.8 ); m_hsplitter->SetSashGravity( 0.8 );
m_hsplitter->SetMinimumPaneSize( 20 ); m_hsplitter->SetMinimumPaneSize( 20 );
m_hsplitter->SplitVertically( treePanel, ConstructRightPanel( m_hsplitter ) ); m_hsplitter->SplitVertically( treePanel, ConstructRightPanel( m_hsplitter ) );

View File

@ -46,6 +46,8 @@ SYMBOL_TREE_PANE::SYMBOL_TREE_PANE( SYMBOL_EDIT_FRAME* aParent, SYMBOL_LIBRARY_M
Layout(); Layout();
boxSizer->Fit( this ); boxSizer->Fit( this );
m_libMgr->GetAdapter()->FinishTreeInitialization();
// Event handlers // Event handlers
Bind( COMPONENT_SELECTED, &SYMBOL_TREE_PANE::onComponentSelected, this ); Bind( COMPONENT_SELECTED, &SYMBOL_TREE_PANE::onComponentSelected, this );
m_tree->Bind( wxEVT_UPDATE_UI, &SYMBOL_TREE_PANE::onUpdateUI, this ); m_tree->Bind( wxEVT_UPDATE_UI, &SYMBOL_TREE_PANE::onUpdateUI, this );

View File

@ -191,6 +191,12 @@ public:
*/ */
void AttachTo( wxDataViewCtrl* aDataViewCtrl ); void AttachTo( wxDataViewCtrl* aDataViewCtrl );
/**
* A final-stage initialization to be called after the window hierarchy has been realized
* and the window sizes set.
*/
void FinishTreeInitialization();
/** /**
* Return the alias for the given item. * Return the alias for the given item.
* *

View File

@ -106,6 +106,8 @@ DIALOG_CHOOSE_FOOTPRINT::DIALOG_CHOOSE_FOOTPRINT( PCB_BASE_FRAME* aParent,
sizer->Add( buttonsSizer, 0, wxEXPAND | wxLEFT, 5 ); sizer->Add( buttonsSizer, 0, wxEXPAND | wxLEFT, 5 );
SetSizer( sizer ); SetSizer( sizer );
aAdapter->FinishTreeInitialization();
Bind( wxEVT_TIMER, &DIALOG_CHOOSE_FOOTPRINT::OnCloseTimer, this, m_dbl_click_timer->GetId() ); Bind( wxEVT_TIMER, &DIALOG_CHOOSE_FOOTPRINT::OnCloseTimer, this, m_dbl_click_timer->GetId() );
Bind( COMPONENT_PRESELECTED, &DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected, this ); Bind( COMPONENT_PRESELECTED, &DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected, this );
Bind( COMPONENT_SELECTED, &DIALOG_CHOOSE_FOOTPRINT::OnComponentSelected, this ); Bind( COMPONENT_SELECTED, &DIALOG_CHOOSE_FOOTPRINT::OnComponentSelected, this );

View File

@ -41,6 +41,8 @@ FOOTPRINT_TREE_PANE::FOOTPRINT_TREE_PANE( FOOTPRINT_EDIT_FRAME* aParent )
Layout(); Layout();
boxSizer->Fit( this ); boxSizer->Fit( this );
m_frame->GetLibTreeAdapter()->FinishTreeInitialization();
// Event handlers // Event handlers
Bind( COMPONENT_SELECTED, &FOOTPRINT_TREE_PANE::onComponentSelected, this ); Bind( COMPONENT_SELECTED, &FOOTPRINT_TREE_PANE::onComponentSelected, this );
m_tree->Bind( wxEVT_UPDATE_UI, &FOOTPRINT_TREE_PANE::onUpdateUI, this ); m_tree->Bind( wxEVT_UPDATE_UI, &FOOTPRINT_TREE_PANE::onUpdateUI, this );