From 0c4184f1a4b8dc7c17b56f9052dfd62b7c9ee4ba Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 1 Apr 2021 10:49:05 +0100 Subject: [PATCH] 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 --- common/lib_tree_model_adapter.cpp | 35 ++++++++-------------- eeschema/dialogs/dialog_choose_symbol.cpp | 2 ++ eeschema/widgets/symbol_tree_pane.cpp | 2 ++ include/lib_tree_model_adapter.h | 6 ++++ pcbnew/dialogs/dialog_choose_footprint.cpp | 2 ++ pcbnew/footprint_tree_pane.cpp | 2 ++ 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/common/lib_tree_model_adapter.cpp b/common/lib_tree_model_adapter.cpp index b7d401b10c..c70d257c36 100644 --- a/common/lib_tree_model_adapter.cpp +++ b/common/lib_tree_model_adapter.cpp @@ -281,23 +281,12 @@ void LIB_TREE_MODEL_ADAPTER::AttachTo( wxDataViewCtrl* aDataViewCtrl ) wxString descHead = _( "Description" ); // The extent of the text doesn't take into account the space on either side - // in the header, so artificially pad it by M - wxSize partHeadMinWidth = KIUI::GetTextSize( partHead + "M", aDataViewCtrl ); + // in the header, so artificially pad it + wxSize partHeadMinWidth = KIUI::GetTextSize( partHead + "MMM", aDataViewCtrl ); - if( aDataViewCtrl->GetColumnCount() > 0 ) - { - int partWidth = aDataViewCtrl->GetColumn( PART_COL )->GetWidth(); - 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; - } - } + // 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_widget = aDataViewCtrl; 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_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 ); } @@ -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() { // Yes, this is an enormous hack. But it works on all platforms, it doesn't suffer diff --git a/eeschema/dialogs/dialog_choose_symbol.cpp b/eeschema/dialogs/dialog_choose_symbol.cpp index 7335246726..5ef47004f0 100644 --- a/eeschema/dialogs/dialog_choose_symbol.cpp +++ b/eeschema/dialogs/dialog_choose_symbol.cpp @@ -125,6 +125,8 @@ DIALOG_CHOOSE_SYMBOL::DIALOG_CHOOSE_SYMBOL( SCH_BASE_FRAME* aParent, const wxStr treePanel->Layout(); treeSizer->Fit( treePanel ); + aAdapter->FinishTreeInitialization(); + m_hsplitter->SetSashGravity( 0.8 ); m_hsplitter->SetMinimumPaneSize( 20 ); m_hsplitter->SplitVertically( treePanel, ConstructRightPanel( m_hsplitter ) ); diff --git a/eeschema/widgets/symbol_tree_pane.cpp b/eeschema/widgets/symbol_tree_pane.cpp index 79a3e44792..772a9048d2 100644 --- a/eeschema/widgets/symbol_tree_pane.cpp +++ b/eeschema/widgets/symbol_tree_pane.cpp @@ -46,6 +46,8 @@ SYMBOL_TREE_PANE::SYMBOL_TREE_PANE( SYMBOL_EDIT_FRAME* aParent, SYMBOL_LIBRARY_M Layout(); boxSizer->Fit( this ); + m_libMgr->GetAdapter()->FinishTreeInitialization(); + // Event handlers Bind( COMPONENT_SELECTED, &SYMBOL_TREE_PANE::onComponentSelected, this ); m_tree->Bind( wxEVT_UPDATE_UI, &SYMBOL_TREE_PANE::onUpdateUI, this ); diff --git a/include/lib_tree_model_adapter.h b/include/lib_tree_model_adapter.h index 9ef3ee7db9..dd7cc14d87 100644 --- a/include/lib_tree_model_adapter.h +++ b/include/lib_tree_model_adapter.h @@ -191,6 +191,12 @@ public: */ 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. * diff --git a/pcbnew/dialogs/dialog_choose_footprint.cpp b/pcbnew/dialogs/dialog_choose_footprint.cpp index d2fe4a6623..8eded32cda 100644 --- a/pcbnew/dialogs/dialog_choose_footprint.cpp +++ b/pcbnew/dialogs/dialog_choose_footprint.cpp @@ -106,6 +106,8 @@ DIALOG_CHOOSE_FOOTPRINT::DIALOG_CHOOSE_FOOTPRINT( PCB_BASE_FRAME* aParent, sizer->Add( buttonsSizer, 0, wxEXPAND | wxLEFT, 5 ); SetSizer( sizer ); + aAdapter->FinishTreeInitialization(); + Bind( wxEVT_TIMER, &DIALOG_CHOOSE_FOOTPRINT::OnCloseTimer, this, m_dbl_click_timer->GetId() ); Bind( COMPONENT_PRESELECTED, &DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected, this ); Bind( COMPONENT_SELECTED, &DIALOG_CHOOSE_FOOTPRINT::OnComponentSelected, this ); diff --git a/pcbnew/footprint_tree_pane.cpp b/pcbnew/footprint_tree_pane.cpp index 18ff19a708..7c47f12fa3 100644 --- a/pcbnew/footprint_tree_pane.cpp +++ b/pcbnew/footprint_tree_pane.cpp @@ -41,6 +41,8 @@ FOOTPRINT_TREE_PANE::FOOTPRINT_TREE_PANE( FOOTPRINT_EDIT_FRAME* aParent ) Layout(); boxSizer->Fit( this ); + m_frame->GetLibTreeAdapter()->FinishTreeInitialization(); + // Event handlers Bind( COMPONENT_SELECTED, &FOOTPRINT_TREE_PANE::onComponentSelected, this ); m_tree->Bind( wxEVT_UPDATE_UI, &FOOTPRINT_TREE_PANE::onUpdateUI, this );