Symbol/Footprint Chooser: remember open libraries

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/16383
This commit is contained in:
Mike Williams 2023-12-21 09:06:28 -05:00
parent ecb7ac1da3
commit 1700cad83b
10 changed files with 79 additions and 2 deletions

View File

@ -155,6 +155,38 @@ LIB_TREE_MODEL_ADAPTER::~LIB_TREE_MODEL_ADAPTER()
{}
std::vector<wxString> LIB_TREE_MODEL_ADAPTER::GetOpenLibs() const
{
std::vector<wxString> openLibs;
wxDataViewItem rootItem( nullptr );
wxDataViewItemArray children;
GetChildren( rootItem, children );
for( const wxDataViewItem& child : children )
{
if( m_widget->IsExpanded( child ) )
openLibs.emplace_back( ToNode( child )->m_LibId.GetLibNickname() );
}
return openLibs;
}
void LIB_TREE_MODEL_ADAPTER::OpenLibs( const std::vector<wxString>& aLibs )
{
wxWindowUpdateLocker updateLock( m_widget );
for( const wxString& lib : aLibs )
{
wxDataViewItem item = FindItem( LIB_ID( lib, wxEmptyString ) );
if( item.IsOk() )
m_widget->Expand( item );
}
}
void LIB_TREE_MODEL_ADAPTER::SaveSettings()
{
if( m_widget )
@ -166,6 +198,8 @@ void LIB_TREE_MODEL_ADAPTER::SaveSettings()
for( const std::pair<const wxString, wxDataViewColumn*>& pair : m_colNameMap )
cfg->m_LibTree.column_widths[pair.first] = pair.second->GetWidth();
cfg->m_LibTree.open_libs = GetOpenLibs();
}
}

View File

@ -109,6 +109,9 @@ APP_SETTINGS_BASE::APP_SETTINGS_BASE( const std::string& aFilename, int aSchemaV
},
{} ) );
m_params.emplace_back(
new PARAM_LIST<wxString>( "lib_tree.open_libs", &m_LibTree.open_libs, {} ) );
m_params.emplace_back( new PARAM<bool>( "printing.background",
&m_Printing.background, false ) );

View File

@ -253,12 +253,14 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP
m_hsplitter->SplitVertically( treePanel, constructRightPanel( m_hsplitter ) );
m_dbl_click_timer = new wxTimer( this );
m_open_libs_timer = new wxTimer( this );
SetSizer( sizer );
Layout();
Bind( wxEVT_TIMER, &PANEL_SYMBOL_CHOOSER::onCloseTimer, this, m_dbl_click_timer->GetId() );
Bind( wxEVT_TIMER, &PANEL_SYMBOL_CHOOSER::onOpenLibsTimer, this, m_open_libs_timer->GetId() );
Bind( EVT_LIBITEM_SELECTED, &PANEL_SYMBOL_CHOOSER::onSymbolSelected, this );
Bind( EVT_LIBITEM_CHOSEN, &PANEL_SYMBOL_CHOOSER::onSymbolChosen, this );
Bind( wxEVT_CHAR_HOOK, &PANEL_SYMBOL_CHOOSER::OnChar, this );
@ -275,6 +277,11 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP
wxKeyEventHandler( PANEL_SYMBOL_CHOOSER::OnDetailsCharHook ),
nullptr, this );
}
// Open the user's previously opened libraries on timer expiration.
// This is done on a timer because we need a gross hack to keep GTK from garbling the
// display. Must be longer than the search debounce timer.
m_open_libs_timer->StartOnce( 300 );
}
@ -287,7 +294,9 @@ PANEL_SYMBOL_CHOOSER::~PANEL_SYMBOL_CHOOSER()
// Stop the timer during destruction early to avoid potential race conditions (that do happen)
m_dbl_click_timer->Stop();
m_open_libs_timer->Stop();
delete m_dbl_click_timer;
delete m_open_libs_timer;
if( m_showPower )
g_powerSearchString = m_tree->GetSearchString();
@ -506,6 +515,13 @@ void PANEL_SYMBOL_CHOOSER::onCloseTimer( wxTimerEvent& aEvent )
}
void PANEL_SYMBOL_CHOOSER::onOpenLibsTimer( wxTimerEvent& aEvent )
{
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
m_adapter->OpenLibs( cfg->m_LibTree.open_libs );
}
void PANEL_SYMBOL_CHOOSER::showFootprintFor( LIB_ID const& aLibId )
{
if( !m_fp_preview || !m_fp_preview->IsInitialized() )

View File

@ -105,6 +105,7 @@ protected:
void OnDetailsCharHook( wxKeyEvent& aEvt );
void onCloseTimer( wxTimerEvent& aEvent );
void onOpenLibsTimer( wxTimerEvent& aEvent );
void onFootprintSelected( wxCommandEvent& aEvent );
void onSymbolSelected( wxCommandEvent& aEvent );
@ -142,6 +143,7 @@ protected:
static wxString g_powerSearchString;
wxTimer* m_dbl_click_timer;
wxTimer* m_open_libs_timer;
SYMBOL_PREVIEW_WIDGET* m_symbol_preview;
wxSplitterWindow* m_hsplitter;
wxSplitterWindow* m_vsplitter;

View File

@ -185,6 +185,9 @@ public:
std::vector<wxString> GetShownColumns() const { return m_shownColumns; }
std::vector<wxString> GetOpenLibs() const;
void OpenLibs( const std::vector<wxString>& aLibs );
/**
* Sets which columns are shown in the widget. Invalid column names are discarded.
* @param aColumnNames is an ordered list of column names to show

View File

@ -120,6 +120,7 @@ public:
{
std::vector<wxString> columns; ///< Ordered list of visible columns in the tree
std::map<wxString, int> column_widths; ///< Column widths, keyed by header name
std::vector<wxString> open_libs; ///< list of libraries the user has open in the tree
};
struct PRINTING

View File

@ -188,7 +188,6 @@ protected:
{
///< List of expanded nodes
std::vector<wxDataViewItem> expanded;
std::vector<wxString> pinned;
///< Current selection, might be not valid if nothing was selected
LIB_ID selection;

View File

@ -41,6 +41,7 @@
#include <widgets/wx_progress_reporters.h>
#include <footprint_info_impl.h>
#include <project_pcb.h>
#include <kiface_base.h>
PANEL_FOOTPRINT_CHOOSER::PANEL_FOOTPRINT_CHOOSER( PCB_BASE_FRAME* aFrame, wxTopLevelWindow* aParent,
@ -147,12 +148,14 @@ PANEL_FOOTPRINT_CHOOSER::PANEL_FOOTPRINT_CHOOSER( PCB_BASE_FRAME* aFrame, wxTopL
m_hsplitter->SplitVertically( m_tree, rightPanel );
m_dbl_click_timer = new wxTimer( this );
m_open_libs_timer = new wxTimer( this );
SetSizer( sizer );
m_adapter->FinishTreeInitialization();
Bind( wxEVT_TIMER, &PANEL_FOOTPRINT_CHOOSER::onCloseTimer, this, m_dbl_click_timer->GetId() );
Bind( wxEVT_TIMER, &PANEL_FOOTPRINT_CHOOSER::onOpenLibsTimer, this, m_open_libs_timer->GetId() );
Bind( EVT_LIBITEM_SELECTED, &PANEL_FOOTPRINT_CHOOSER::onFootprintSelected, this );
Bind( EVT_LIBITEM_CHOSEN, &PANEL_FOOTPRINT_CHOOSER::onFootprintChosen, this );
@ -192,6 +195,11 @@ PANEL_FOOTPRINT_CHOOSER::PANEL_FOOTPRINT_CHOOSER( PCB_BASE_FRAME* aFrame, wxTopL
} );
Layout();
// Open the user's previously opened libraries on timer expiration.
// This is done on a timer because we need a gross hack to keep GTK from garbling the
// display. Must be longer than the search debounce timer.
m_open_libs_timer->StartOnce( 300 );
}
@ -207,7 +215,9 @@ PANEL_FOOTPRINT_CHOOSER::~PANEL_FOOTPRINT_CHOOSER()
// I am not sure the following two lines are necessary, but they will not hurt anyone
m_dbl_click_timer->Stop();
m_open_libs_timer->Stop();
delete m_dbl_click_timer;
delete m_open_libs_timer;
PCBNEW_SETTINGS* cfg = nullptr;
try
@ -305,6 +315,13 @@ void PANEL_FOOTPRINT_CHOOSER::onCloseTimer( wxTimerEvent& aEvent )
}
void PANEL_FOOTPRINT_CHOOSER::onOpenLibsTimer( wxTimerEvent& aEvent )
{
if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
m_adapter->OpenLibs( cfg->m_LibTree.open_libs );
}
void PANEL_FOOTPRINT_CHOOSER::onFootprintSelected( wxCommandEvent& aEvent )
{
if( !m_preview_ctrl || !m_preview_ctrl->IsInitialized() )

View File

@ -76,6 +76,7 @@ protected:
void OnDetailsCharHook( wxKeyEvent& aEvt );
void onCloseTimer( wxTimerEvent& aEvent );
void onOpenLibsTimer( wxTimerEvent& aEvent );
void onFootprintSelected( wxCommandEvent& aEvent );
@ -89,6 +90,7 @@ protected:
protected:
wxTimer* m_dbl_click_timer;
wxTimer* m_open_libs_timer;
wxSplitterWindow* m_hsplitter;
wxSplitterWindow* m_vsplitter;