Move centering of lib-tree item to idle event.

Fixes https://gitlab.com/kicad/code/kicad/issues/9294
This commit is contained in:
Jeff Young 2021-10-01 22:45:49 +01:00
parent 5f5ee7335d
commit ef74421922
4 changed files with 40 additions and 2 deletions

View File

@ -448,6 +448,8 @@ private:
///< the library that is currently modified. ///< the library that is currently modified.
wxString getTargetLib() const; wxString getTargetLib() const;
void centerItemIdleHandler( wxIdleEvent& aEvent );
/* /*
* Return true when the operation has succeeded (all requested libraries have been saved * Return true when the operation has succeeded (all requested libraries have been saved
* or none was selected and confirmed by OK). * 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_LIBRARY_MANAGER* m_libMgr; // manager taking care of temporary modifications
SYMBOL_EDITOR_SETTINGS* m_settings; // Handle to the settings SYMBOL_EDITOR_SETTINGS* m_settings; // Handle to the settings
LIB_ID m_centerItemOnIdle;
// The unit number to edit and show // The unit number to edit and show
int m_unit; int m_unit;

View File

@ -270,7 +270,26 @@ bool SYMBOL_EDIT_FRAME::LoadSymbol( const LIB_ID& aLibId, int aUnit, int aConver
} }
SelectActiveLibrary( aLibId.GetLibNickname() ); 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 );
} }

View File

@ -333,6 +333,8 @@ protected:
void setupUIConditions() override; void setupUIConditions() override;
void centerItemIdleHandler( wxIdleEvent& aEvent );
protected: protected:
PCB_LAYER_BOX_SELECTOR* m_selLayerBox; // a combo box to display and select active layer PCB_LAYER_BOX_SELECTOR* m_selLayerBox; // a combo box to display and select active layer
FOOTPRINT_EDITOR_SETTINGS* m_editorSettings; FOOTPRINT_EDITOR_SETTINGS* m_editorSettings;
@ -341,6 +343,8 @@ private:
friend struct PCB::IFACE; friend struct PCB::IFACE;
FOOTPRINT_TREE_PANE* m_treePane; FOOTPRINT_TREE_PANE* m_treePane;
LIB_ID m_centerItemOnIdle;
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter; wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;

View File

@ -100,11 +100,22 @@ void FOOTPRINT_EDIT_FRAME::LoadFootprintFromLibrary( LIB_ID aFPID )
} }
m_treePane->GetLibTree()->ExpandLibId( 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 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 ) void FOOTPRINT_EDIT_FRAME::SelectLayer( wxCommandEvent& event )
{ {
SetActiveLayer( ToLAYER_ID( m_selLayerBox->GetLayerSelection() ) ); SetActiveLayer( ToLAYER_ID( m_selLayerBox->GetLayerSelection() ) );