From 1528f4700c6295418be7269302a689090801199c Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 4 Jun 2023 20:51:28 +0100 Subject: [PATCH] Treat canvas item as current when tree view contains no selection. Fixes https://gitlab.com/kicad/code/kicad/-/issues/12702 --- common/lib_tree_model_adapter.cpp | 6 ++++++ common/widgets/lib_tree.cpp | 6 +++++- eeschema/symbol_tree_synchronizing_adapter.cpp | 9 +++++++++ eeschema/symbol_tree_synchronizing_adapter.h | 2 ++ include/lib_tree_model_adapter.h | 2 ++ include/widgets/lib_tree.h | 1 - pcbnew/fp_tree_synchronizing_adapter.cpp | 6 ++++++ pcbnew/fp_tree_synchronizing_adapter.h | 2 ++ 8 files changed, 32 insertions(+), 2 deletions(-) diff --git a/common/lib_tree_model_adapter.cpp b/common/lib_tree_model_adapter.cpp index b624264d46..cd74688ada 100644 --- a/common/lib_tree_model_adapter.cpp +++ b/common/lib_tree_model_adapter.cpp @@ -417,6 +417,12 @@ wxDataViewItem LIB_TREE_MODEL_ADAPTER::FindItem( const LIB_ID& aLibId ) } +wxDataViewItem LIB_TREE_MODEL_ADAPTER::GetCurrentDataViewItem() +{ + return FindItem( m_preselect_lib_id ); +} + + unsigned int LIB_TREE_MODEL_ADAPTER::GetChildren( const wxDataViewItem& aItem, wxDataViewItemArray& aChildren ) const { diff --git a/common/widgets/lib_tree.cpp b/common/widgets/lib_tree.cpp index 02ebfeece9..b7046e354b 100644 --- a/common/widgets/lib_tree.cpp +++ b/common/widgets/lib_tree.cpp @@ -529,7 +529,11 @@ void LIB_TREE::onDebounceTimer( wxTimerEvent& aEvent ) void LIB_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke ) { - const wxDataViewItem sel = m_tree_ctrl->GetSelection(); + wxDataViewItem sel = m_tree_ctrl->GetSelection(); + + if( !sel.IsOk() ) + sel = m_adapter->GetCurrentDataViewItem(); + LIB_TREE_NODE::TYPE type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : LIB_TREE_NODE::INVALID; switch( aKeyStroke.GetKeyCode() ) diff --git a/eeschema/symbol_tree_synchronizing_adapter.cpp b/eeschema/symbol_tree_synchronizing_adapter.cpp index 0747733655..46f51bc286 100644 --- a/eeschema/symbol_tree_synchronizing_adapter.cpp +++ b/eeschema/symbol_tree_synchronizing_adapter.cpp @@ -208,6 +208,15 @@ SYMBOL_TREE_SYNCHRONIZING_ADAPTER::deleteLibrary( LIB_TREE_NODE::PTR_VECTOR::ite } +wxDataViewItem SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetCurrentDataViewItem() +{ + if( m_frame->GetCurSymbol() ) + return FindItem( m_frame->GetCurSymbol()->GetLibId() ); + + return wxDataViewItem(); +} + + void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewItem const& aItem, unsigned int aCol ) const { diff --git a/eeschema/symbol_tree_synchronizing_adapter.h b/eeschema/symbol_tree_synchronizing_adapter.h index 8aea7010d3..d79a035c2b 100644 --- a/eeschema/symbol_tree_synchronizing_adapter.h +++ b/eeschema/symbol_tree_synchronizing_adapter.h @@ -48,6 +48,8 @@ public: TOOL_INTERACTIVE* GetContextMenuTool() override; + wxDataViewItem GetCurrentDataViewItem() override; + protected: void updateLibrary( LIB_TREE_NODE_LIB& aLibNode ); diff --git a/include/lib_tree_model_adapter.h b/include/lib_tree_model_adapter.h index 96f99babf3..a91e8fdce0 100644 --- a/include/lib_tree_model_adapter.h +++ b/include/lib_tree_model_adapter.h @@ -283,6 +283,8 @@ public: */ wxDataViewItem FindItem( const LIB_ID& aLibId ); + virtual wxDataViewItem GetCurrentDataViewItem(); + /** * Populate a list of all the children of an item * diff --git a/include/widgets/lib_tree.h b/include/widgets/lib_tree.h index 08bfb614ee..0b6e72066e 100644 --- a/include/widgets/lib_tree.h +++ b/include/widgets/lib_tree.h @@ -230,7 +230,6 @@ protected: wxTimer* m_debounceTimer; bool m_inTimerEvent; - LIB_ID m_last_libid; wxString m_recentSearchesKey; bool m_skipNextRightClick; diff --git a/pcbnew/fp_tree_synchronizing_adapter.cpp b/pcbnew/fp_tree_synchronizing_adapter.cpp index a5d3d71639..e65f60fa96 100644 --- a/pcbnew/fp_tree_synchronizing_adapter.cpp +++ b/pcbnew/fp_tree_synchronizing_adapter.cpp @@ -169,6 +169,12 @@ FP_TREE_SYNCHRONIZING_ADAPTER::deleteLibrary( LIB_TREE_NODE::PTR_VECTOR::iterato } +wxDataViewItem FP_TREE_SYNCHRONIZING_ADAPTER::GetCurrentDataViewItem() +{ + return FindItem( m_frame->GetLoadedFPID() ); +} + + void FP_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewItem const& aItem, unsigned int aCol ) const { diff --git a/pcbnew/fp_tree_synchronizing_adapter.h b/pcbnew/fp_tree_synchronizing_adapter.h index a61f85e691..e369841b0e 100644 --- a/pcbnew/fp_tree_synchronizing_adapter.h +++ b/pcbnew/fp_tree_synchronizing_adapter.h @@ -44,6 +44,8 @@ public: TOOL_INTERACTIVE* GetContextMenuTool() override; + wxDataViewItem GetCurrentDataViewItem() override; + protected: FP_TREE_SYNCHRONIZING_ADAPTER( FOOTPRINT_EDIT_FRAME* aFrame, FP_LIB_TABLE* aLibs );