27#include <wx/tokenzr.h>
36wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
41 return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
54 auto width =
m_cfg.column_widths.find( wxT(
"Item" ) );
73 wxString libName = row->Nickname();
78 std::vector<LIB_TREE_ITEM*> designBlocks =
getDesignBlocks( aParent, libName );
82 DoAddLibrary( libName, row->Description(), designBlocks, pinned,
false );
105 const wxString& aLibName )
107 std::vector<LIB_TREE_ITEM*> libList;
115 LIB_ID id = block->GetLIB_ID();
117 block->SetLibId(
id );
118 libList.emplace_back( block );
131 "<hr><table border=0>"
135 static const wxString
DescFormat = wxS(
"<br>%s" );
136 static const wxString
KeywordsFormat = wxS(
"<br>" ) +
_(
"Keywords" ) + wxS(
": %s" );
140 " <td><b>__FIELD_NAME__</b></td>"
141 " <td>__FIELD_VALUE__</td>"
146 return wxEmptyString;
156 wxLogError(
_(
"Error loading design block %s from library '%s'." ) + wxS(
"\n%s" ),
159 return wxEmptyString;
175 esc_desc.Replace( wxS(
"\n" ), wxS(
"<br>" ) );
180 if( esc_desc.IsEmpty() )
181 html.Replace(
"__DESC__", wxEmptyString );
183 html.Replace(
"__DESC__", wxString::Format(
DescFormat, esc_desc ) );
185 if( keywords.IsEmpty() )
186 html.Replace(
"__KEY__", wxEmptyString );
192 for(
const auto& [key, value] : db->
GetFields() )
195 fieldRow.Replace( wxS(
"__FIELD_NAME__" ),
EscapeHTML( key ) );
196 fieldRow.Replace( wxS(
"__FIELD_VALUE__" ),
EscapeHTML( value ) );
197 fieldTable += fieldRow;
200 html.Replace(
"__FIELDS__", fieldTable );
207 html.Printf(
_(
"Error loading design block %s from library '%s'." ) + wxS(
"\n" ),
std::vector< DESIGN_BLOCK * > GetDesignBlocks(const wxString &aNickname)
std::vector< LIB_TREE_ITEM * > getDesignBlocks(EDA_BASE_FRAME *aParent, const wxString &aLibName)
DESIGN_BLOCK_LIBRARY_ADAPTER * m_libs
wxString GenerateInfo(LIB_ID const &aLibId, int aUnit) override
void AddLibraries(EDA_BASE_FRAME *aParent)
TOOL_INTERACTIVE * GetContextMenuTool() override
static wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > Create(EDA_BASE_FRAME *aParent, DESIGN_BLOCK_LIBRARY_ADAPTER *aLibs, APP_SETTINGS_BASE::LIB_TREE &aSettings, TOOL_INTERACTIVE *aContextMenuTool)
Factory function: create a model adapter in a reference-counting container.
TOOL_INTERACTIVE * m_contextMenuTool
DESIGN_BLOCK_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, DESIGN_BLOCK_LIBRARY_ADAPTER *aLibs, APP_SETTINGS_BASE::LIB_TREE &aSettings, TOOL_INTERACTIVE *aContextMenuTool)
Constructor; takes a set of libraries to be included in the search.
const wxString & GetKeywords() const
const wxString & GetLibDescription() const
const nlohmann::ordered_map< wxString, wxString > & GetFields() const
The base frame for deriving all KiCad main window classes.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
std::vector< LIBRARY_TABLE_ROW * > Rows(LIBRARY_TABLE_TYPE aType, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH, bool aIncludeInvalid=false) const
Returns a flattened list of libraries of the given type.
A logical library item identifier and consists of various portions much like a URI.
bool IsValid() const
Check if this LID_ID is valid.
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
LIB_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, const wxString &aPinnedKey, APP_SETTINGS_BASE::LIB_TREE &aSettingsStruct)
Create the adapter.
static bool IsValidColumnWidth(int aWidth)
APP_SETTINGS_BASE::LIB_TREE & m_cfg
LIB_TREE_NODE_ROOT m_tree
std::map< wxString, int > m_colWidths
LIB_TREE_NODE_LIBRARY & DoAddLibrary(const wxString &aNodeName, const wxString &aDesc, const std::vector< LIB_TREE_ITEM * > &aItemList, bool aPinned, bool aPresorted)
Add the given list of symbols by alias.
wxDataViewCtrl * m_widget
std::vector< wxString > m_shownColumns
virtual COMMON_SETTINGS * GetCommonSettings() const
virtual LIBRARY_MANAGER & GetLibraryManager() const
The backing store for a PROJECT, in JSON format.
virtual PROJECT_FILE & GetProjectFile() const
Base window classes and related definitions.
Abstract pattern-matching tool and implementations.
static const wxString KeywordsFormat
static const wxString DescriptionFormat
static const wxString DescFormat
static const wxString FieldFormat
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
PGM_BASE & Pgm()
The global program "get" accessor.
wxString EscapeHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
wxString UnescapeString(const wxString &aSource)
wxString LinkifyHTML(wxString aStr)
Wraps links in HTML tags.
std::vector< wxString > pinned_design_block_libs