From eb27a3f8b9e7c047a70acc2e7c2cbbba5eb6b302 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 9 Jul 2022 20:44:49 -0600 Subject: [PATCH] Added pinning support to various EDA_LIST_DIALOGs. Footprint Save As, Symbol Save As, etc. --- common/dialogs/eda_list_dialog.cpp | 23 +++++---- eeschema/symbol_editor/symbol_editor.cpp | 56 +++++++++++++++++----- include/eda_list_dialog.h | 4 +- pcbnew/footprint_libraries_utils.cpp | 59 ++++++++++++++++++------ 4 files changed, 108 insertions(+), 34 deletions(-) diff --git a/common/dialogs/eda_list_dialog.cpp b/common/dialogs/eda_list_dialog.cpp index a7fbc48e40..34997a8d6d 100644 --- a/common/dialogs/eda_list_dialog.cpp +++ b/common/dialogs/eda_list_dialog.cpp @@ -27,7 +27,7 @@ #include #include #include - +#include "lib_tree_model_adapter.h" // wxWidgets spends *far* too long calculating column widths (most of it, believe it or // not, in repeatedly creating/destroying a wxDC to do the measurement in). @@ -39,11 +39,11 @@ static int DEFAULT_COL_WIDTHS[] = { 200, 600 }; EDA_LIST_DIALOG::EDA_LIST_DIALOG( wxWindow* aParent, const wxString& aTitle, const wxArrayString& aItemHeaders, const std::vector& aItemList, - const wxString& aPreselectText ) : - EDA_LIST_DIALOG_BASE( aParent, wxID_ANY, aTitle ) + const wxString& aPreselectText, bool aSortList ) : + EDA_LIST_DIALOG_BASE( aParent, wxID_ANY, aTitle ), + m_itemsList( aItemList ), + m_sortList( aSortList ) { - m_itemsList = aItemList; - m_filterBox->SetHint( _( "Filter" ) ); initDialog( aItemHeaders, aPreselectText ); @@ -149,7 +149,8 @@ wxString EDA_LIST_DIALOG::GetTextSelection( int aColumn ) wxCHECK_MSG( unsigned( aColumn ) < unsigned( m_listBox->GetColumnCount() ), wxEmptyString, wxT( "Invalid list control column." ) ); - long item = m_listBox->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); + long item = m_listBox->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); + wxString text; if( item >= 0 ) // if something is selected. { @@ -160,10 +161,13 @@ wxString EDA_LIST_DIALOG::GetTextSelection( int aColumn ) info.m_col = aColumn; if( m_listBox->GetItem( info ) ) - return info.m_text; + text = info.m_text; + + if( text.StartsWith( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() ) ) + text = text.substr( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol().length() ); } - return wxEmptyString; + return text; } @@ -233,5 +237,6 @@ static int wxCALLBACK myCompareFunction( wxIntPtr aItem1, wxIntPtr aItem2, void EDA_LIST_DIALOG::sortList() { - m_listBox->SortItems( myCompareFunction, 0 ); + if( m_sortList ) + m_listBox->SortItems( myCompareFunction, 0 ); } diff --git a/eeschema/symbol_editor/symbol_editor.cpp b/eeschema/symbol_editor/symbol_editor.cpp index 22e030fc34..1277bf17fb 100644 --- a/eeschema/symbol_editor/symbol_editor.cpp +++ b/eeschema/symbol_editor/symbol_editor.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -118,22 +119,40 @@ wxString SYMBOL_EDIT_FRAME::SelectLibraryFromList() std::vector< wxArrayString > itemsToDisplay; std::vector< wxString > libNicknames = prj.SchSymbolLibTable()->GetLogicalLibs(); - // Conversion from wxArrayString to vector of ArrayString for( const wxString& name : libNicknames ) { - wxArrayString item; - // Exclude read only libraries. if( m_libMgr->IsLibraryReadOnly( name ) ) continue; - item.Add( name ); - itemsToDisplay.push_back( item ); + if( alg::contains( prj.GetProjectFile().m_PinnedSymbolLibs, name ) ) + { + wxArrayString item; + + item.Add( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() + name ); + itemsToDisplay.push_back( item ); + } + } + + for( const wxString& name : libNicknames ) + { + // Exclude read only libraries. + if( m_libMgr->IsLibraryReadOnly( name ) ) + continue; + + if( !alg::contains( prj.GetProjectFile().m_PinnedSymbolLibs, name ) ) + { + wxArrayString item; + + item.Add( name ); + itemsToDisplay.push_back( item ); + } } wxString oldLibName = prj.GetRString( PROJECT::SCH_LIB_SELECT ); - EDA_LIST_DIALOG dlg( this, _( "Select Symbol Library" ), headers, itemsToDisplay, oldLibName ); + EDA_LIST_DIALOG dlg( this, _( "Select Symbol Library" ), headers, itemsToDisplay, oldLibName, + false ); if( dlg.ShowModal() != wxID_OK ) return wxEmptyString; @@ -559,6 +578,7 @@ static int ID_MAKE_NEW_LIBRARY = 4173; EDA_LIST_DIALOG* SYMBOL_EDIT_FRAME::buildSaveAsDialog( const wxString& aSymbolName, const wxString& aLibraryPreselect ) { + PROJECT_FILE& project = Kiway().Prj().GetProjectFile(); SYMBOL_LIB_TABLE* tbl = Prj().SchSymbolLibTable(); std::vector libNicknames = tbl->GetLogicalLibs(); wxArrayString headers; @@ -569,14 +589,28 @@ EDA_LIST_DIALOG* SYMBOL_EDIT_FRAME::buildSaveAsDialog( const wxString& aSymbolNa for( const wxString& nickname : libNicknames ) { - wxArrayString item; - item.Add( nickname ); - item.Add( tbl->GetDescription( nickname ) ); - itemsToDisplay.push_back( item ); + if( alg::contains( project.m_PinnedSymbolLibs, nickname ) ) + { + wxArrayString item; + item.Add( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() + nickname ); + item.Add( tbl->GetDescription( nickname ) ); + itemsToDisplay.push_back( item ); + } + } + + for( const wxString& nickname : libNicknames ) + { + if( !alg::contains( project.m_PinnedSymbolLibs, nickname ) ) + { + wxArrayString item; + item.Add( nickname ); + item.Add( tbl->GetDescription( nickname ) ); + itemsToDisplay.push_back( item ); + } } EDA_LIST_DIALOG* dlg = new EDA_LIST_DIALOG( this, _( "Save Symbol As" ), headers, - itemsToDisplay, aLibraryPreselect ); + itemsToDisplay, aLibraryPreselect, false ); dlg->SetListLabel( _( "Save in library:" ) ); dlg->SetOKLabel( _( "Save" ) ); diff --git a/include/eda_list_dialog.h b/include/eda_list_dialog.h index cbc9d7b3fa..2298fa4f9f 100644 --- a/include/eda_list_dialog.h +++ b/include/eda_list_dialog.h @@ -52,7 +52,8 @@ public: */ EDA_LIST_DIALOG( wxWindow* aParent, const wxString& aTitle, const wxArrayString& aItemHeaders, const std::vector& aItemList, - const wxString& aPreselectText = wxEmptyString ); + const wxString& aPreselectText = wxEmptyString, + bool aSortList = true ); void SetListLabel( const wxString& aLabel ); void SetOKLabel( const wxString& aLabel ); @@ -81,6 +82,7 @@ private: private: // The list of items, locally stored std::vector m_itemsList; + bool m_sortList; }; diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index a1da565818..6e8da40de1 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include "footprint_viewer_frame.h" #include "tools/pad_tool.h" @@ -1015,6 +1016,7 @@ static int ID_MAKE_NEW_LIBRARY = 4173; EDA_LIST_DIALOG* FOOTPRINT_EDIT_FRAME::buildSaveAsDialog( const wxString& aFootprintName, const wxString& aLibraryPreselect ) { + PROJECT_FILE& project = Kiway().Prj().GetProjectFile(); FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs(); std::vector nicknames = tbl->GetLogicalLibs(); wxArrayString headers; @@ -1025,14 +1027,30 @@ EDA_LIST_DIALOG* FOOTPRINT_EDIT_FRAME::buildSaveAsDialog( const wxString& aFootp for( const wxString& nickname : nicknames ) { - wxArrayString item; - item.Add( nickname ); - item.Add( tbl->GetDescription( nickname ) ); - itemsToDisplay.push_back( item ); + if( alg::contains( project.m_PinnedFootprintLibs, nickname ) ) + { + wxArrayString item; + + item.Add( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() + nickname ); + item.Add( tbl->GetDescription( nickname ) ); + itemsToDisplay.push_back( item ); + } + } + + for( const wxString& nickname : nicknames ) + { + if( !alg::contains( project.m_PinnedFootprintLibs, nickname ) ) + { + wxArrayString item; + + item.Add( nickname ); + item.Add( tbl->GetDescription( nickname ) ); + itemsToDisplay.push_back( item ); + } } EDA_LIST_DIALOG* dlg = new EDA_LIST_DIALOG( this, _( "Save Footprint As" ), headers, - itemsToDisplay, aLibraryPreselect ); + itemsToDisplay, aLibraryPreselect, false ); dlg->SetListLabel( _( "Save in library:" ) ); dlg->SetOKLabel( _( "Save" ) ); @@ -1322,22 +1340,37 @@ wxString PCB_BASE_FRAME::SelectLibrary( const wxString& aNicknameExisting ) headers.Add( _( "Nickname" ) ); headers.Add( _( "Description" ) ); - FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs(); - + PROJECT_FILE& project = Kiway().Prj().GetProjectFile(); + FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs(); std::vector< wxArrayString > itemsToDisplay; std::vector< wxString > nicknames = fptbl->GetLogicalLibs(); for( const wxString& nickname : nicknames ) { - wxArrayString item; + if( alg::contains( project.m_PinnedFootprintLibs, nickname ) ) + { + wxArrayString item; - item.Add( nickname ); - item.Add( fptbl->GetDescription( nickname ) ); - - itemsToDisplay.push_back( item ); + item.Add( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() + nickname ); + item.Add( fptbl->GetDescription( nickname ) ); + itemsToDisplay.push_back( item ); + } } - EDA_LIST_DIALOG dlg( this, _( "Select Library" ), headers, itemsToDisplay, aNicknameExisting ); + for( const wxString& nickname : nicknames ) + { + if( !alg::contains( project.m_PinnedFootprintLibs, nickname ) ) + { + wxArrayString item; + + item.Add( nickname ); + item.Add( fptbl->GetDescription( nickname ) ); + itemsToDisplay.push_back( item ); + } + } + + EDA_LIST_DIALOG dlg( this, _( "Select Library" ), headers, itemsToDisplay, aNicknameExisting, + false ); if( dlg.ShowModal() != wxID_OK ) return wxEmptyString;