From 676d862bee4d590efad15fd3e59e02cf15a7cce8 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 30 Mar 2021 20:58:35 +0100 Subject: [PATCH] Don't allow really narrow widths for tree control. Fixes https://gitlab.com/kicad/code/kicad/issues/5479 --- common/lib_tree_model_adapter.cpp | 18 +++++++++--------- common/settings/app_settings.cpp | 6 ++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/common/lib_tree_model_adapter.cpp b/common/lib_tree_model_adapter.cpp index b2b986c9ce..b7d401b10c 100644 --- a/common/lib_tree_model_adapter.cpp +++ b/common/lib_tree_model_adapter.cpp @@ -62,7 +62,7 @@ unsigned int LIB_TREE_MODEL_ADAPTER::IntoArray( LIB_TREE_NODE const& aNode, { unsigned int n = 0; - for( auto const& child: aNode.m_Children ) + for( std::unique_ptr const& child: aNode.m_Children ) { if( child->m_Score > 0 ) { @@ -91,7 +91,7 @@ LIB_TREE_MODEL_ADAPTER::LIB_TREE_MODEL_ADAPTER( EDA_BASE_FRAME* aParent, wxStrin m_colWidths[PART_COL] = 360; m_colWidths[DESC_COL] = 2000; - auto cfg = Kiface().KifaceSettings(); + APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings(); m_colWidths[PART_COL] = cfg->m_LibTree.column_width; // Read the pinned entries from the project config @@ -114,7 +114,7 @@ void LIB_TREE_MODEL_ADAPTER::SaveColWidths() { if( m_widget ) { - auto cfg = Kiface().KifaceSettings(); + APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings(); cfg->m_LibTree.column_width = m_widget->GetColumn( PART_COL )->GetWidth(); } } @@ -131,7 +131,7 @@ void LIB_TREE_MODEL_ADAPTER::SavePinnedItems() entries.clear(); m_pinnedLibs.clear(); - for( auto& child: m_tree.m_Children ) + for( std::unique_ptr& child: m_tree.m_Children ) { if( child->m_Pinned ) { @@ -252,7 +252,7 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( wxString const& aSearch, bool a if( bestMatch ) { - auto item = wxDataViewItem( bestMatch ); + wxDataViewItem item = wxDataViewItem( bestMatch ); m_widget->Select( item ); // Make sure the *parent* item is visible. The selected item is the @@ -366,7 +366,7 @@ int LIB_TREE_MODEL_ADAPTER::GetItemCount() const wxDataViewItem LIB_TREE_MODEL_ADAPTER::FindItem( const LIB_ID& aLibId ) { - for( auto& lib: m_tree.m_Children ) + for( std::unique_ptr& lib: m_tree.m_Children ) { if( lib->m_Name != aLibId.GetLibNickname() ) continue; @@ -375,7 +375,7 @@ wxDataViewItem LIB_TREE_MODEL_ADAPTER::FindItem( const LIB_ID& aLibId ) if( aLibId.GetLibItemName() == "" ) return ToItem( lib.get() ); - for( auto& alias: lib->m_Children ) + for( std::unique_ptr& alias: lib->m_Children ) { if( alias->m_Name == aLibId.GetLibItemName() ) return ToItem( alias.get() ); @@ -517,11 +517,11 @@ void LIB_TREE_MODEL_ADAPTER::FindAndExpand( LIB_TREE_NODE& aNode, std::function aFunc, LIB_TREE_NODE** aHighScore ) { - for( auto& node: aNode.m_Children ) + for( std::unique_ptr& node: aNode.m_Children ) { if( aFunc( &*node ) ) { - auto item = wxDataViewItem( &*node ); + wxDataViewItem item = wxDataViewItem( &*node ); m_widget->ExpandAncestors( item ); if( !(*aHighScore) || node->m_Score > (*aHighScore)->m_Score ) diff --git a/common/settings/app_settings.cpp b/common/settings/app_settings.cpp index 384a39effd..c909a6cb98 100644 --- a/common/settings/app_settings.cpp +++ b/common/settings/app_settings.cpp @@ -80,6 +80,12 @@ APP_SETTINGS_BASE::APP_SETTINGS_BASE( const std::string& aFilename, int aSchemaV m_params.emplace_back( new PARAM( "lib_tree.column_width", &m_LibTree.column_width, 360 ) ); + // Now that we allow hiding/showing of the tree control, it's never terribly useful to + // decrease the width to nothing, and wxWidgets appears to have some bugs where it sets it + // way too narrow. + if( m_LibTree.column_width < 360 ) + m_LibTree.column_width = 360; + m_params.emplace_back( new PARAM( "printing.background", &m_Printing.background, false ) );