From ef744219221669f83e8daa982101a7a1ea4e8f38 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 1 Oct 2021 22:45:49 +0100 Subject: [PATCH] Move centering of lib-tree item to idle event. Fixes https://gitlab.com/kicad/code/kicad/issues/9294 --- eeschema/symbol_editor/symbol_edit_frame.h | 4 ++++ eeschema/symbol_editor/symbol_editor.cpp | 21 ++++++++++++++++++++- pcbnew/footprint_edit_frame.h | 4 ++++ pcbnew/footprint_editor_utils.cpp | 13 ++++++++++++- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/eeschema/symbol_editor/symbol_edit_frame.h b/eeschema/symbol_editor/symbol_edit_frame.h index 00599c9cd3..ffbd9a55ad 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.h +++ b/eeschema/symbol_editor/symbol_edit_frame.h @@ -448,6 +448,8 @@ private: ///< the library that is currently modified. wxString getTargetLib() const; + void centerItemIdleHandler( wxIdleEvent& aEvent ); + /* * Return true when the operation has succeeded (all requested libraries have been saved * or none was selected and confirmed by OK). @@ -535,6 +537,8 @@ private: SYMBOL_LIBRARY_MANAGER* m_libMgr; // manager taking care of temporary modifications SYMBOL_EDITOR_SETTINGS* m_settings; // Handle to the settings + LIB_ID m_centerItemOnIdle; + // The unit number to edit and show int m_unit; diff --git a/eeschema/symbol_editor/symbol_editor.cpp b/eeschema/symbol_editor/symbol_editor.cpp index a19720bbb0..53e306a135 100644 --- a/eeschema/symbol_editor/symbol_editor.cpp +++ b/eeschema/symbol_editor/symbol_editor.cpp @@ -270,7 +270,26 @@ bool SYMBOL_EDIT_FRAME::LoadSymbol( const LIB_ID& aLibId, int aUnit, int aConver } SelectActiveLibrary( aLibId.GetLibNickname() ); - return LoadSymbolFromCurrentLib( aLibId.GetLibItemName(), aUnit, aConvert ); + + if( LoadSymbolFromCurrentLib( aLibId.GetLibItemName(), aUnit, aConvert ) ) + { + m_treePane->GetLibTree()->SelectLibId( aLibId ); + m_treePane->GetLibTree()->ExpandLibId( aLibId ); + + m_centerItemOnIdle = aLibId; + Bind( wxEVT_IDLE, &SYMBOL_EDIT_FRAME::centerItemIdleHandler, this ); + + return true; + } + + return false; +} + + +void SYMBOL_EDIT_FRAME::centerItemIdleHandler( wxIdleEvent& aEvent ) +{ + m_treePane->GetLibTree()->CenterLibId( m_centerItemOnIdle ); + Unbind( wxEVT_IDLE, &SYMBOL_EDIT_FRAME::centerItemIdleHandler, this ); } diff --git a/pcbnew/footprint_edit_frame.h b/pcbnew/footprint_edit_frame.h index 10fd87b7c4..f1a0db00eb 100644 --- a/pcbnew/footprint_edit_frame.h +++ b/pcbnew/footprint_edit_frame.h @@ -333,6 +333,8 @@ protected: void setupUIConditions() override; + void centerItemIdleHandler( wxIdleEvent& aEvent ); + protected: PCB_LAYER_BOX_SELECTOR* m_selLayerBox; // a combo box to display and select active layer FOOTPRINT_EDITOR_SETTINGS* m_editorSettings; @@ -341,6 +343,8 @@ private: friend struct PCB::IFACE; FOOTPRINT_TREE_PANE* m_treePane; + LIB_ID m_centerItemOnIdle; + wxObjectDataPtr m_adapter; diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp index a3f9218149..61956ae5fb 100644 --- a/pcbnew/footprint_editor_utils.cpp +++ b/pcbnew/footprint_editor_utils.cpp @@ -100,11 +100,22 @@ void FOOTPRINT_EDIT_FRAME::LoadFootprintFromLibrary( LIB_ID aFPID ) } m_treePane->GetLibTree()->ExpandLibId( aFPID ); - m_treePane->GetLibTree()->CenterLibId( aFPID ); + + m_centerItemOnIdle = aFPID; + Bind( wxEVT_IDLE, &FOOTPRINT_EDIT_FRAME::centerItemIdleHandler, this ); + m_treePane->GetLibTree()->RefreshLibTree(); // update highlighting } +void FOOTPRINT_EDIT_FRAME::centerItemIdleHandler( wxIdleEvent& aEvent ) +{ + m_treePane->GetLibTree()->CenterLibId( m_centerItemOnIdle ); + Unbind( wxEVT_IDLE, &FOOTPRINT_EDIT_FRAME::centerItemIdleHandler, this ); +} + + + void FOOTPRINT_EDIT_FRAME::SelectLayer( wxCommandEvent& event ) { SetActiveLayer( ToLAYER_ID( m_selLayerBox->GetLayerSelection() ) );