KiCad PCB EDA Suite
LIB_TREE Class Reference

Widget displaying a tree of symbols with optional search text control and description panel.Custom event sent when a new symbol is preselected. More...

#include <lib_tree.h>

Inheritance diagram for LIB_TREE:

Classes

struct  STATE
 Structure storing state of the symbol tree widget. More...
 

Public Types

enum  FLAGS {
  NONE = 0x00 , SEARCH = 0x01 , DETAILS = 0x02 , ALL_WIDGETS = 0x0F ,
  MULTISELECT = 0x10
}
 < Flags to select extra widgets and options More...
 

Public Member Functions

 LIB_TREE (wxWindow *aParent, const wxString &aRecentSearchesKey, LIB_TABLE *aLibTable, wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > &aAdapter, int aFlags=ALL_WIDGETS, HTML_WINDOW *aDetails=nullptr)
 Construct a symbol tree. More...
 
 ~LIB_TREE () override
 
LIB_ID GetSelectedLibId (int *aUnit=nullptr) const
 For multi-unit symbols, if the user selects the symbol itself rather than picking an individual unit, 0 will be returned in aUnit. More...
 
int GetSelectionCount () const
 
int GetSelectedLibIds (std::vector< LIB_ID > &aSelection, std::vector< int > *aUnit=nullptr) const
 Retrieves a list of selections for trees that allow multi-selection. More...
 
LIB_TREE_NODEGetCurrentTreeNode () const
 
void SelectLibId (const LIB_ID &aLibId)
 Select an item in the tree widget. More...
 
void CenterLibId (const LIB_ID &aLibId)
 Ensure that an item is visible (preferably centered). More...
 
void Unselect ()
 Unselect currently selected item in wxDataViewCtrl. More...
 
void ExpandLibId (const LIB_ID &aLibId)
 Expand and item i the tree widget. More...
 
void SetSearchString (const wxString &aSearchString)
 Save/restore search string. More...
 
wxString GetSearchString () const
 
void Regenerate (bool aKeepState)
 Regenerate the tree. More...
 
void RefreshLibTree ()
 Refreshes the tree (mainly to update highlighting and asterisking) More...
 
wxWindow * GetFocusTarget ()
 

Protected Member Functions

void toggleExpand (const wxDataViewItem &aTreeId)
 Expand or collapse a node, switching it to the opposite state. More...
 
void selectIfValid (const wxDataViewItem &aTreeId)
 If a wxDataViewitem is valid, select it and post a selection event. More...
 
void centerIfValid (const wxDataViewItem &aTreeId)
 
void expandIfValid (const wxDataViewItem &aTreeId)
 
void postPreselectEvent ()
 Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been preselected. More...
 
void postSelectEvent ()
 Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected. More...
 
STATE getState () const
 Return the symbol tree widget state. More...
 
void setState (const STATE &aState)
 Restore the symbol tree widget state from an object. More...
 
void updateRecentSearchMenu ()
 
void onQueryText (wxCommandEvent &aEvent)
 
void onQueryCharHook (wxKeyEvent &aEvent)
 
void onQueryMouseMoved (wxMouseEvent &aEvent)
 
void onTreeSelect (wxDataViewEvent &aEvent)
 
void onTreeActivate (wxDataViewEvent &aEvent)
 
void onTreeCharHook (wxKeyEvent &aEvent)
 
void onSize (wxSizeEvent &aEvent)
 
void onDetailsLink (wxHtmlLinkEvent &aEvent)
 
void onPreselect (wxCommandEvent &aEvent)
 
void onItemContextMenu (wxDataViewEvent &aEvent)
 
void onHeaderContextMenu (wxDataViewEvent &aEvent)
 
void onDebounceTimer (wxTimerEvent &aEvent)
 

Protected Attributes

LIB_TABLEm_lib_table
 
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTERm_adapter
 
wxSearchCtrl * m_query_ctrl
 
wxDataViewCtrl * m_tree_ctrl
 
HTML_WINDOWm_details_ctrl
 
wxTimer * m_debounceTimer
 
bool m_inTimerEvent
 
LIB_ID m_last_libid
 
wxString m_recentSearchesKey
 
bool m_skipNextRightClick
 

Detailed Description

Widget displaying a tree of symbols with optional search text control and description panel.Custom event sent when a new symbol is preselected.

Definition at line 45 of file lib_tree.h.

Member Enumeration Documentation

◆ FLAGS

< Flags to select extra widgets and options

Enumerator
NONE 
SEARCH 
DETAILS 
ALL_WIDGETS 
MULTISELECT 

Definition at line 49 of file lib_tree.h.

50 {
51 NONE = 0x00,
52 SEARCH = 0x01,
53 DETAILS = 0x02,
54 ALL_WIDGETS = 0x0F,
55 MULTISELECT = 0x10
56 };
@ NONE
Definition: lib_tree.h:51
@ MULTISELECT
Definition: lib_tree.h:55
@ DETAILS
Definition: lib_tree.h:53
@ ALL_WIDGETS
Definition: lib_tree.h:54
@ SEARCH
Definition: lib_tree.h:52

Constructor & Destructor Documentation

◆ LIB_TREE()

LIB_TREE::LIB_TREE ( wxWindow *  aParent,
const wxString &  aRecentSearchesKey,
LIB_TABLE aLibTable,
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > &  aAdapter,
int  aFlags = ALL_WIDGETS,
HTML_WINDOW aDetails = nullptr 
)

Construct a symbol tree.

Parameters
aParentparent window containing this tree widget
aRecentSearchesKeya key into a global map storing recent searches (usually "power", "symbols", or "footprints", but could be further differentiated)
aLibTabletable containing libraries and items to display
aAdaptera LIB_TREE_MODEL_ADAPTER instance to use
aFlagsselection of sub-widgets to include and other options
aDetailsif not null, a custom HTML_WINDOW to hold symbol details. If null this will be created inside the LIB_TREE.

Definition at line 44 of file lib_tree.cpp.

46 :
47 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
48 wxWANTS_CHARS | wxTAB_TRAVERSAL | wxNO_BORDER ),
49 m_lib_table( aLibTable ), m_adapter( aAdapter ), m_query_ctrl( nullptr ),
50 m_details_ctrl( nullptr ),
51 m_inTimerEvent( false ),
52 m_recentSearchesKey( aRecentSearchesKey ),
54{
55 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
56
57 // Search text control
58 if( aFlags & SEARCH )
59 {
60 wxBoxSizer* search_sizer = new wxBoxSizer( wxHORIZONTAL );
61
62 m_query_ctrl = new wxSearchCtrl( this, wxID_ANY );
63
64 m_query_ctrl->ShowCancelButton( true );
65
66#ifdef __WXGTK__
67 // wxSearchCtrl vertical height is not calculated correctly on some GTK setups
68 // See https://gitlab.com/kicad/code/kicad/-/issues/9019
69 m_query_ctrl->SetMinSize( wxSize( -1, GetTextExtent( wxT( "qb" ) ).y + 10 ) );
70#endif
71
72 m_debounceTimer = new wxTimer( this );
73
74 search_sizer->Add( m_query_ctrl, 1, wxEXPAND, 5 );
75
76 sizer->Add( search_sizer, 0, wxEXPAND, 5 );
77
78 m_query_ctrl->Bind( wxEVT_TEXT, &LIB_TREE::onQueryText, this );
79
80#if wxCHECK_VERSION( 3, 1, 1 )
81 m_query_ctrl->Bind( wxEVT_SEARCH_CANCEL, &LIB_TREE::onQueryText, this );
82#else
83 m_query_ctrl->Bind( wxEVT_SEARCHCTRL_CANCEL_BTN, &LIB_TREE::onQueryText, this );
84#endif
85 m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &LIB_TREE::onQueryCharHook, this );
86 m_query_ctrl->Bind( wxEVT_MOTION, &LIB_TREE::onQueryMouseMoved, this );
87 m_query_ctrl->Bind( wxEVT_LEAVE_WINDOW,
88 [this] ( wxMouseEvent& aEvt )
89 {
90 SetCursor( wxCURSOR_ARROW );
91 } );
92
93 m_query_ctrl->Bind( wxEVT_MENU,
94 [this]( wxCommandEvent& aEvent )
95 {
96 wxString search;
97 size_t idx = aEvent.GetId() - 1;
98
99 if( idx < g_recentSearches[ m_recentSearchesKey ].size() )
101 },
103
104 Bind( wxEVT_TIMER, &LIB_TREE::onDebounceTimer, this, m_debounceTimer->GetId() );
105 }
106
107 // Tree control
108 int dvFlags = ( aFlags & MULTISELECT ) ? wxDV_MULTIPLE : wxDV_SINGLE;
109 m_tree_ctrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, dvFlags );
110 m_adapter->AttachTo( m_tree_ctrl );
111
112 if( aFlags & DETAILS )
113 sizer->AddSpacer( 5 );
114
115 sizer->Add( m_tree_ctrl, 5, wxRIGHT | wxBOTTOM | wxEXPAND, 1 );
116
117 // Description panel
118 if( aFlags & DETAILS )
119 {
120 if( !aDetails )
121 {
122 wxPoint html_size = ConvertDialogToPixels( wxPoint( 80, 80 ) );
123
124 m_details_ctrl = new HTML_WINDOW( this, wxID_ANY, wxDefaultPosition,
125 wxSize( html_size.x, html_size.y ),
126 wxHW_SCROLLBAR_AUTO );
127
128 sizer->Add( m_details_ctrl, 2, wxTOP | wxEXPAND, 5 );
129 }
130 else
131 {
132 m_details_ctrl = aDetails;
133 }
134
135 m_details_ctrl->Bind( wxEVT_HTML_LINK_CLICKED, &LIB_TREE::onDetailsLink, this );
136 }
137
138 SetSizer( sizer );
139
140 m_tree_ctrl->Bind( wxEVT_SIZE, &LIB_TREE::onSize, this );
141 m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &LIB_TREE::onTreeActivate, this );
142 m_tree_ctrl->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED, &LIB_TREE::onTreeSelect, this );
143 m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, &LIB_TREE::onItemContextMenu, this );
144 m_tree_ctrl->Bind( wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, &LIB_TREE::onHeaderContextMenu,
145 this );
146
147 // Process hotkeys when the tree control has focus:
148 m_tree_ctrl->Bind( wxEVT_CHAR_HOOK, &LIB_TREE::onTreeCharHook, this );
149
150 Bind( SYMBOL_PRESELECTED, &LIB_TREE::onPreselect, this );
151
152 if( m_query_ctrl )
153 {
154 m_query_ctrl->SetDescriptiveText( _( "Filter" ) );
155 m_query_ctrl->SetFocus();
156 m_query_ctrl->SetValue( wxEmptyString );
158
159 // Force an update of the adapter with the empty text to ensure preselect is done
160 Regenerate( false );
161 }
162 else
163 {
164 // There may be a part preselected in the model. Make sure it is displayed.
165 // Regenerate does this in the other branch
167 }
168
169 Layout();
170 sizer->Fit( this );
171
172#ifdef __WXGTK__
173 // Scrollbars must be always enabled to prevent an infinite event loop
174 // more details: http://trac.wxwidgets.org/ticket/18141
175 if( m_details_ctrl )
176 m_details_ctrl->ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
177#endif /* __WXGTK__ */
178}
Add dark theme support to wxHtmlWindow.
Definition: html_window.h:34
wxTimer * m_debounceTimer
Definition: lib_tree.h:217
void onQueryMouseMoved(wxMouseEvent &aEvent)
Definition: lib_tree.cpp:523
LIB_TABLE * m_lib_table
Definition: lib_tree.h:210
HTML_WINDOW * m_details_ctrl
Definition: lib_tree.h:216
void onTreeActivate(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:574
wxString m_recentSearchesKey
Definition: lib_tree.h:221
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:215
void onQueryCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:473
void onSize(wxSizeEvent &aEvent)
Definition: lib_tree.cpp:583
void onItemContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:613
void onQueryText(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:455
bool m_skipNextRightClick
Definition: lib_tree.h:223
bool m_inTimerEvent
Definition: lib_tree.h:218
void onPreselect(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:596
void updateRecentSearchMenu()
Definition: lib_tree.cpp:266
void onTreeSelect(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:564
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:407
void onTreeCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:538
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition: lib_tree.cpp:589
wxSearchCtrl * m_query_ctrl
Definition: lib_tree.h:214
void onDebounceTimer(wxTimerEvent &aEvent)
Definition: lib_tree.cpp:465
void onHeaderContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:657
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition: lib_tree.cpp:295
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:212
#define _(s)
constexpr int RECENT_SEARCHES_MAX
Definition: lib_tree.cpp:39
std::map< wxString, std::vector< wxString > > g_recentSearches
Definition: lib_tree.cpp:41

References _, DETAILS, g_recentSearches, m_adapter, m_debounceTimer, m_details_ctrl, m_query_ctrl, m_recentSearchesKey, m_tree_ctrl, MULTISELECT, onDebounceTimer(), onDetailsLink(), onHeaderContextMenu(), onItemContextMenu(), onPreselect(), onQueryCharHook(), onQueryMouseMoved(), onQueryText(), onSize(), onTreeActivate(), onTreeCharHook(), onTreeSelect(), postPreselectEvent(), RECENT_SEARCHES_MAX, Regenerate(), SEARCH, and updateRecentSearchMenu().

◆ ~LIB_TREE()

LIB_TREE::~LIB_TREE ( )
override

Definition at line 181 of file lib_tree.cpp.

182{
183 // Stop the timer during destruction early to avoid potential race conditions (that do happen)
184 m_debounceTimer->Stop();
185}

References m_debounceTimer.

Member Function Documentation

◆ centerIfValid()

void LIB_TREE::centerIfValid ( const wxDataViewItem &  aTreeId)
protected

Definition at line 352 of file lib_tree.cpp.

353{
354 /*
355 * This doesn't actually center because the wxWidgets API is poorly suited to that (and
356 * it might be too noisy as well).
357 *
358 * It does try to keep the given item a bit off the top or bottom of the window.
359 */
360
361 if( aTreeId.IsOk() )
362 {
363 LIB_TREE_NODE* node = m_adapter->GetTreeNodeFor( aTreeId );
364 LIB_TREE_NODE* parent = node->m_Parent;
365 LIB_TREE_NODE* grandParent = parent ? parent->m_Parent : nullptr;
366
367 if( parent )
368 {
369 wxDataViewItemArray siblings;
370 m_adapter->GetChildren( wxDataViewItem( parent ), siblings );
371
372 int idx = siblings.Index( aTreeId );
373
374 if( idx + 5 < (int) siblings.GetCount() )
375 {
376 m_tree_ctrl->EnsureVisible( siblings.Item( idx + 5 ) );
377 }
378 else if( grandParent )
379 {
380 wxDataViewItemArray parentsSiblings;
381 m_adapter->GetChildren( wxDataViewItem( grandParent ), parentsSiblings );
382
383 int p_idx = parentsSiblings.Index( wxDataViewItem( parent ) );
384
385 if( p_idx + 1 < (int) parentsSiblings.GetCount() )
386 m_tree_ctrl->EnsureVisible( parentsSiblings.Item( p_idx + 1 ) );
387 }
388
389 if( idx - 5 >= 0 )
390 m_tree_ctrl->EnsureVisible( siblings.Item( idx - 5 ) );
391 else
392 m_tree_ctrl->EnsureVisible( wxDataViewItem( parent ) );
393 }
394
395 m_tree_ctrl->EnsureVisible( aTreeId );
396 }
397}
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
LIB_TREE_NODE * m_Parent

References m_adapter, LIB_TREE_NODE::m_Parent, and m_tree_ctrl.

Referenced by CenterLibId().

◆ CenterLibId()

void LIB_TREE::CenterLibId ( const LIB_ID aLibId)

◆ expandIfValid()

void LIB_TREE::expandIfValid ( const wxDataViewItem &  aTreeId)
protected

Definition at line 400 of file lib_tree.cpp.

401{
402 if( aTreeId.IsOk() && !m_tree_ctrl->IsExpanded( aTreeId ) )
403 m_tree_ctrl->Expand( aTreeId );
404}

References m_tree_ctrl.

Referenced by ExpandLibId().

◆ ExpandLibId()

void LIB_TREE::ExpandLibId ( const LIB_ID aLibId)

Expand and item i the tree widget.

Definition at line 248 of file lib_tree.cpp.

249{
250 expandIfValid( m_adapter->FindItem( aLibId ) );
251}
void expandIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:400

References expandIfValid(), and m_adapter.

Referenced by SYMBOL_EDIT_FRAME::KiwayMailIn(), FOOTPRINT_EDIT_FRAME::LoadFootprintFromLibrary(), and SYMBOL_EDIT_FRAME::LoadSymbol().

◆ GetCurrentTreeNode()

LIB_TREE_NODE * LIB_TREE::GetCurrentTreeNode ( ) const

Definition at line 219 of file lib_tree.cpp.

220{
221 wxDataViewItem sel = m_tree_ctrl->GetSelection();
222
223 if( !sel )
224 return nullptr;
225
226 return m_adapter->GetTreeNodeFor( sel );
227}

References m_adapter, and m_tree_ctrl.

Referenced by SYMBOL_EDIT_FRAME::GetCurrentTreeNode(), FOOTPRINT_EDIT_FRAME::GetCurrentTreeNode(), DIALOG_CHOOSE_SYMBOL::OnComponentPreselected(), and onItemContextMenu().

◆ GetFocusTarget()

wxWindow * LIB_TREE::GetFocusTarget ( )

Definition at line 319 of file lib_tree.cpp.

320{
321 if( m_query_ctrl )
322 return m_query_ctrl;
323 else
324 return m_tree_ctrl;
325}

References m_query_ctrl, and m_tree_ctrl.

Referenced by DIALOG_CHOOSE_FOOTPRINT::DIALOG_CHOOSE_FOOTPRINT(), and DIALOG_CHOOSE_SYMBOL::DIALOG_CHOOSE_SYMBOL().

◆ GetSearchString()

wxString LIB_TREE::GetSearchString ( ) const

Definition at line 260 of file lib_tree.cpp.

261{
262 return m_query_ctrl->GetValue();
263}

References m_query_ctrl.

Referenced by updateRecentSearchMenu(), and DIALOG_CHOOSE_SYMBOL::~DIALOG_CHOOSE_SYMBOL().

◆ GetSelectedLibId()

LIB_ID LIB_TREE::GetSelectedLibId ( int *  aUnit = nullptr) const

For multi-unit symbols, if the user selects the symbol itself rather than picking an individual unit, 0 will be returned in aUnit.

Beware that this is an invalid unit number - this should be replaced with whatever default is desired (usually 1).

Parameters
aUnitif not NULL, the selected unit is filled in here.
Returns
the library id of the symbol that has been selected.

Definition at line 188 of file lib_tree.cpp.

189{
190 wxDataViewItem sel = m_tree_ctrl->GetSelection();
191
192 if( !sel )
193 return LIB_ID();
194
195 if( aUnit )
196 *aUnit = m_adapter->GetUnitFor( sel );
197
198 return m_adapter->GetAliasFor( sel );
199}
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49

References m_adapter, and m_tree_ctrl.

Referenced by DIALOG_CHOOSE_FOOTPRINT::GetSelectedLibId(), DIALOG_CHOOSE_SYMBOL::GetSelectedLibId(), getState(), FOOTPRINT_EDIT_FRAME::GetTreeFPID(), SYMBOL_EDIT_FRAME::GetTreeLIBID(), DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected(), DIALOG_CHOOSE_SYMBOL::OnComponentSelected(), DIALOG_CHOOSE_FOOTPRINT::OnComponentSelected(), onPreselect(), onQueryCharHook(), onTreeActivate(), SYMBOL_EDIT_FRAME::SyncLibraries(), and FOOTPRINT_EDIT_FRAME::SyncLibraryTree().

◆ GetSelectedLibIds()

int LIB_TREE::GetSelectedLibIds ( std::vector< LIB_ID > &  aSelection,
std::vector< int > *  aUnit = nullptr 
) const

Retrieves a list of selections for trees that allow multi-selection.

See also
GetSelectedLibId for details on how aUnit will be filled.
Parameters
aSelectionwill be filled with a list of selected LIB_IDs
aUnitis an optional pointer to a list to fill with unit numbers
Returns
the number of selected items

Definition at line 202 of file lib_tree.cpp.

203{
204 wxDataViewItemArray selection;
205 int count = m_tree_ctrl->GetSelections( selection );
206
207 for( const wxDataViewItem& item : selection )
208 {
209 aSelection.emplace_back( m_adapter->GetAliasFor( item ) );
210
211 if( aUnit )
212 aUnit->emplace_back( m_adapter->GetUnitFor( item ) );
213 }
214
215 return count;
216}

References m_adapter, and m_tree_ctrl.

Referenced by SYMBOL_EDIT_FRAME::GetTreeLIBIDs().

◆ GetSelectionCount()

int LIB_TREE::GetSelectionCount ( ) const
inline

Definition at line 87 of file lib_tree.h.

88 {
89 return m_tree_ctrl->GetSelectedItemsCount();
90 }

References m_tree_ctrl.

Referenced by SYMBOL_EDIT_FRAME::GetTreeSelectionCount().

◆ getState()

LIB_TREE::STATE LIB_TREE::getState ( ) const
protected

Return the symbol tree widget state.

Definition at line 421 of file lib_tree.cpp.

422{
423 STATE state;
424 wxDataViewItemArray items;
425 m_adapter->GetChildren( wxDataViewItem( nullptr ), items );
426
427 for( const wxDataViewItem& item : items )
428 {
429 if( m_tree_ctrl->IsExpanded( item ) )
430 state.expanded.push_back( item );
431 }
432
433 state.selection = GetSelectedLibId();
434
435 return state;
436}
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit symbols, if the user selects the symbol itself rather than picking an individual unit,...
Definition: lib_tree.cpp:188

References LIB_TREE::STATE::expanded, GetSelectedLibId(), m_adapter, m_tree_ctrl, and LIB_TREE::STATE::selection.

Referenced by Regenerate().

◆ onDebounceTimer()

void LIB_TREE::onDebounceTimer ( wxTimerEvent &  aEvent)
protected

Definition at line 465 of file lib_tree.cpp.

466{
467 m_inTimerEvent = true;
468 Regenerate( false );
469 m_inTimerEvent = false;
470}

References m_inTimerEvent, and Regenerate().

Referenced by LIB_TREE().

◆ onDetailsLink()

void LIB_TREE::onDetailsLink ( wxHtmlLinkEvent &  aEvent)
protected

Definition at line 589 of file lib_tree.cpp.

590{
591 const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
592 ::wxLaunchDefaultBrowser( info.GetHref() );
593}

References info.

Referenced by LIB_TREE().

◆ onHeaderContextMenu()

void LIB_TREE::onHeaderContextMenu ( wxDataViewEvent &  aEvent)
protected

Definition at line 657 of file lib_tree.cpp.

658{
659 ACTION_MENU menu( true, nullptr );
660
661 menu.Add( ACTIONS::selectColumns );
662
663 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
664 {
665 EDA_REORDERABLE_LIST_DIALOG dlg( m_parent, _( "Select Columns" ),
666 m_adapter->GetAvailableColumns(),
667 m_adapter->GetShownColumns() );
668
669 if( dlg.ShowModal() == wxID_OK )
670 m_adapter->SetShownColumns( dlg.EnabledList() );
671 }
672
673#if !wxCHECK_VERSION( 3, 1, 0 )
674 // wxGTK 3.0 sends item right click events for header right clicks
676#endif
677}
static TOOL_ACTION selectColumns
Definition: actions.h:175
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
A dialog which allows selecting a list of items from a list of available items, and reordering those ...

References _, ACTION_MENU::Add(), EDA_REORDERABLE_LIST_DIALOG::EnabledList(), m_adapter, m_skipNextRightClick, and ACTIONS::selectColumns.

Referenced by LIB_TREE().

◆ onItemContextMenu()

void LIB_TREE::onItemContextMenu ( wxDataViewEvent &  aEvent)
protected

Definition at line 613 of file lib_tree.cpp.

614{
616 {
617 m_skipNextRightClick = false;
618 return;
619 }
620
621 if( TOOL_INTERACTIVE* tool = m_adapter->GetContextMenuTool() )
622 {
623 tool->Activate();
624 tool->GetManager()->VetoContextMenuMouseWarp();
625 tool->GetToolMenu().ShowContextMenu();
626
628 tool->GetManager()->DispatchContextMenu( evt );
629 }
630 else
631 {
633
634 if( current && current->m_Type == LIB_TREE_NODE::LIB )
635 {
636 ACTION_MENU menu( true, nullptr );
637
638 if( current->m_Pinned )
639 {
640 menu.Add( ACTIONS::unpinLibrary );
641
642 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
643 m_adapter->UnpinLibrary( current );
644 }
645 else
646 {
647 menu.Add( ACTIONS::pinLibrary );
648
649 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
650 m_adapter->PinLibrary( current );
651 }
652 }
653 }
654}
static TOOL_ACTION pinLibrary
Definition: actions.h:112
static TOOL_ACTION unpinLibrary
Definition: actions.h:113
enum TYPE m_Type
LIB_TREE_NODE * GetCurrentTreeNode() const
Definition: lib_tree.cpp:219
Generic, UI-independent tool event.
Definition: tool_event.h:156
@ TA_MOUSE_CLICK
Definition: tool_event.h:62
@ TC_MOUSE
Definition: tool_event.h:50
@ BUT_RIGHT
Definition: tool_event.h:128

References ACTION_MENU::Add(), BUT_RIGHT, GetCurrentTreeNode(), LIB_TREE_NODE::LIB, m_adapter, LIB_TREE_NODE::m_Pinned, m_skipNextRightClick, LIB_TREE_NODE::m_Type, ACTIONS::pinLibrary, TA_MOUSE_CLICK, TC_MOUSE, and ACTIONS::unpinLibrary.

Referenced by LIB_TREE().

◆ onPreselect()

void LIB_TREE::onPreselect ( wxCommandEvent &  aEvent)
protected

Definition at line 596 of file lib_tree.cpp.

597{
598 if( m_details_ctrl )
599 {
600 int unit = 0;
601 LIB_ID id = GetSelectedLibId( &unit );
602
603 if( id.IsValid() )
604 m_details_ctrl->SetPage( m_adapter->GenerateInfo( id, unit ) );
605 else
606 m_details_ctrl->SetPage( wxEmptyString );
607 }
608
609 aEvent.Skip();
610}
bool SetPage(const wxString &aSource) override
Definition: html_window.cpp:38
bool IsValid(const std::string &aString, SIM_VALUE::TYPE aValueType=SIM_VALUE::TYPE_FLOAT, NOTATION aNotation=NOTATION::SI)
Definition: sim_value.cpp:127

References GetSelectedLibId(), SIM_VALUE_GRAMMAR::IsValid(), m_adapter, m_details_ctrl, and HTML_WINDOW::SetPage().

Referenced by LIB_TREE().

◆ onQueryCharHook()

void LIB_TREE::onQueryCharHook ( wxKeyEvent &  aEvent)
protected

Definition at line 473 of file lib_tree.cpp.

474{
475 const wxDataViewItem sel = m_tree_ctrl->GetSelection();
476 LIB_TREE_NODE::TYPE type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : LIB_TREE_NODE::INVALID;
477
478 switch( aKeyStroke.GetKeyCode() )
479 {
480 case WXK_UP:
483 break;
484
485 case WXK_DOWN:
488 break;
489
490 case WXK_ADD:
492
493 if( type == LIB_TREE_NODE::LIB )
494 m_tree_ctrl->Expand( sel );
495
496 break;
497
498 case WXK_SUBTRACT:
500
501 if( type == LIB_TREE_NODE::LIB )
502 m_tree_ctrl->Collapse( sel );
503
504 break;
505
506 case WXK_RETURN:
508
509 if( GetSelectedLibId().IsValid() )
511 else if( type == LIB_TREE_NODE::LIB )
512 toggleExpand( sel );
513
514 break;
515
516 default:
517 aKeyStroke.Skip(); // Any other key: pass on to search box directly.
518 break;
519 }
520}
void postSelectEvent()
Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
Definition: lib_tree.cpp:414
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition: lib_tree.cpp:328
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:340
wxDataViewItem GetPrevItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the previous item in list order.
wxDataViewItem GetNextItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the next item in list order.

References GetNextItem(), GetPrevItem(), GetSelectedLibId(), LIB_TREE_NODE::INVALID, SIM_VALUE_GRAMMAR::IsValid(), LIB_TREE_NODE::LIB, m_adapter, m_tree_ctrl, postSelectEvent(), selectIfValid(), toggleExpand(), and updateRecentSearchMenu().

Referenced by LIB_TREE(), and onTreeCharHook().

◆ onQueryMouseMoved()

void LIB_TREE::onQueryMouseMoved ( wxMouseEvent &  aEvent)
protected

Definition at line 523 of file lib_tree.cpp.

524{
525 wxPoint pos = aEvent.GetPosition();
526 wxRect ctrlRect = m_query_ctrl->GetScreenRect();
527 int buttonWidth = ctrlRect.GetHeight(); // Presume buttons are square
528
529 if( m_query_ctrl->IsSearchButtonVisible() && pos.x < buttonWidth )
530 SetCursor( wxCURSOR_ARROW );
531 else if( m_query_ctrl->IsCancelButtonVisible() && pos.x > ctrlRect.GetWidth() - buttonWidth )
532 SetCursor( wxCURSOR_ARROW );
533 else
534 SetCursor( wxCURSOR_IBEAM );
535}

References m_query_ctrl.

Referenced by LIB_TREE().

◆ onQueryText()

void LIB_TREE::onQueryText ( wxCommandEvent &  aEvent)
protected

Definition at line 455 of file lib_tree.cpp.

456{
457 m_debounceTimer->StartOnce( 200 );
458
459 // Required to avoid interaction with SetHint()
460 // See documentation for wxTextEntry::SetHint
461 aEvent.Skip();
462}

References m_debounceTimer.

Referenced by LIB_TREE().

◆ onSize()

void LIB_TREE::onSize ( wxSizeEvent &  aEvent)
protected

Definition at line 583 of file lib_tree.cpp.

584{
585 m_adapter->OnSize( aEvent );
586}

References m_adapter.

Referenced by LIB_TREE().

◆ onTreeActivate()

void LIB_TREE::onTreeActivate ( wxDataViewEvent &  aEvent)
protected

Definition at line 574 of file lib_tree.cpp.

575{
576 if( !GetSelectedLibId().IsValid() )
577 toggleExpand( m_tree_ctrl->GetSelection() ); // Expand library/part units subtree
578 else
579 postSelectEvent(); // Open symbol/footprint
580}

References GetSelectedLibId(), SIM_VALUE_GRAMMAR::IsValid(), m_tree_ctrl, postSelectEvent(), and toggleExpand().

Referenced by LIB_TREE().

◆ onTreeCharHook()

void LIB_TREE::onTreeCharHook ( wxKeyEvent &  aEvent)
protected

Definition at line 538 of file lib_tree.cpp.

539{
540 onQueryCharHook( aKeyStroke );
541
542 if( aKeyStroke.GetSkipped() )
543 {
544 if( TOOL_INTERACTIVE* tool = m_adapter->GetContextMenuTool() )
545 {
546 int hotkey = aKeyStroke.GetKeyCode();
547
548 if( aKeyStroke.ShiftDown() )
549 hotkey |= MD_SHIFT;
550
551 if( aKeyStroke.AltDown() )
552 hotkey |= MD_ALT;
553
554 if( aKeyStroke.ControlDown() )
555 hotkey |= MD_CTRL;
556
557 if( tool->GetManager()->GetActionManager()->RunHotKey( hotkey ) )
558 aKeyStroke.Skip( false );
559 }
560 }
561}
@ MD_ALT
Definition: tool_event.h:140
@ MD_CTRL
Definition: tool_event.h:139
@ MD_SHIFT
Definition: tool_event.h:138

References m_adapter, MD_ALT, MD_CTRL, MD_SHIFT, and onQueryCharHook().

Referenced by LIB_TREE().

◆ onTreeSelect()

void LIB_TREE::onTreeSelect ( wxDataViewEvent &  aEvent)
protected

Definition at line 564 of file lib_tree.cpp.

565{
566 if( !m_inTimerEvent )
568
569 if( !m_tree_ctrl->IsFrozen() )
571}

References m_inTimerEvent, m_tree_ctrl, postPreselectEvent(), and updateRecentSearchMenu().

Referenced by LIB_TREE().

◆ postPreselectEvent()

void LIB_TREE::postPreselectEvent ( )
protected

Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been preselected.

Definition at line 407 of file lib_tree.cpp.

408{
409 wxCommandEvent event( SYMBOL_PRESELECTED );
410 wxPostEvent( this, event );
411}

Referenced by LIB_TREE(), onTreeSelect(), Regenerate(), and selectIfValid().

◆ postSelectEvent()

void LIB_TREE::postSelectEvent ( )
protected

Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected.

Definition at line 414 of file lib_tree.cpp.

415{
416 wxCommandEvent event( SYMBOL_SELECTED );
417 wxPostEvent( this, event );
418}

Referenced by onQueryCharHook(), and onTreeActivate().

◆ RefreshLibTree()

◆ Regenerate()

void LIB_TREE::Regenerate ( bool  aKeepState)

Regenerate the tree.

Definition at line 295 of file lib_tree.cpp.

296{
297 STATE current;
298
299 // Store the state
300 if( aKeepState )
301 current = getState();
302
303 wxString filter = m_query_ctrl->GetValue();
304 m_adapter->UpdateSearchString( filter, aKeepState );
306
307 // Restore the state
308 if( aKeepState )
309 setState( current );
310}
void setState(const STATE &aState)
Restore the symbol tree widget state from an object.
Definition: lib_tree.cpp:439
STATE getState() const
Return the symbol tree widget state.
Definition: lib_tree.cpp:421

References filter, getState(), m_adapter, m_query_ctrl, postPreselectEvent(), and setState().

Referenced by LIB_TREE(), onDebounceTimer(), SYMBOL_EDIT_FRAME::RegenerateLibraryTree(), FOOTPRINT_EDIT_FRAME::RegenerateLibraryTree(), SYMBOL_EDIT_FRAME::SyncLibraries(), and FOOTPRINT_EDIT_FRAME::SyncLibraryTree().

◆ selectIfValid()

void LIB_TREE::selectIfValid ( const wxDataViewItem &  aTreeId)
protected

If a wxDataViewitem is valid, select it and post a selection event.

Definition at line 340 of file lib_tree.cpp.

341{
342 if( aTreeId.IsOk() )
343 {
344 m_tree_ctrl->EnsureVisible( aTreeId );
345 m_tree_ctrl->UnselectAll();
346 m_tree_ctrl->Select( aTreeId );
348 }
349}

References m_tree_ctrl, and postPreselectEvent().

Referenced by onQueryCharHook(), and SelectLibId().

◆ SelectLibId()

◆ SetSearchString()

void LIB_TREE::SetSearchString ( const wxString &  aSearchString)

Save/restore search string.

Definition at line 254 of file lib_tree.cpp.

255{
256 m_query_ctrl->ChangeValue( aSearchString );
257}

References m_query_ctrl.

Referenced by DIALOG_CHOOSE_SYMBOL::DIALOG_CHOOSE_SYMBOL().

◆ setState()

void LIB_TREE::setState ( const STATE aState)
protected

Restore the symbol tree widget state from an object.

Definition at line 439 of file lib_tree.cpp.

440{
441 m_tree_ctrl->Freeze();
442
443 for( const wxDataViewItem& item : aState.expanded )
444 m_tree_ctrl->Expand( item );
445
446 // wxDataViewCtrl cannot be frozen when a selection
447 // command is issued, otherwise it selects a random item (Windows)
448 m_tree_ctrl->Thaw();
449
450 if( !aState.selection.GetLibItemName().empty() || !aState.selection.GetLibNickname().empty() )
451 SelectLibId( aState.selection );
452}
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:230

References UTF8::empty(), LIB_TREE::STATE::expanded, LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), m_tree_ctrl, LIB_TREE::STATE::selection, and SelectLibId().

Referenced by Regenerate().

◆ toggleExpand()

void LIB_TREE::toggleExpand ( const wxDataViewItem &  aTreeId)
protected

Expand or collapse a node, switching it to the opposite state.

Definition at line 328 of file lib_tree.cpp.

329{
330 if( !aTreeId.IsOk() )
331 return;
332
333 if( m_tree_ctrl->IsExpanded( aTreeId ) )
334 m_tree_ctrl->Collapse( aTreeId );
335 else
336 m_tree_ctrl->Expand( aTreeId );
337}

References m_tree_ctrl.

Referenced by onQueryCharHook(), and onTreeActivate().

◆ Unselect()

◆ updateRecentSearchMenu()

void LIB_TREE::updateRecentSearchMenu ( )
protected

Definition at line 266 of file lib_tree.cpp.

267{
268 wxString newEntry = GetSearchString();
269
270 std::vector<wxString>& recents = g_recentSearches[ m_recentSearchesKey ];
271
272 if( !newEntry.IsEmpty() )
273 {
274 if( alg::contains( recents, newEntry ) )
275 alg::delete_matching( recents, newEntry );
276
277 if( recents.size() >= RECENT_SEARCHES_MAX )
278 recents.pop_back();
279
280 recents.insert( recents.begin(), newEntry );
281 }
282
283 wxMenu* menu = new wxMenu();
284
285 for( const wxString& recent : recents )
286 menu->Append( menu->GetMenuItemCount() + 1, recent );
287
288 if( recents.empty() )
289 menu->Append( wxID_ANY, _( "recent searches" ) );
290
291 m_query_ctrl->SetMenu( menu );
292}
wxString GetSearchString() const
Definition: lib_tree.cpp:260
void delete_matching(_Container &__c, _Value __value)
Covers for the horrifically named std::remove and std::remove_if (neither of which remove anything).
Definition: kicad_algo.h:164
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:99

References _, alg::contains(), alg::delete_matching(), g_recentSearches, GetSearchString(), m_query_ctrl, m_recentSearchesKey, recent, and RECENT_SEARCHES_MAX.

Referenced by LIB_TREE(), onQueryCharHook(), and onTreeSelect().

Member Data Documentation

◆ m_adapter

◆ m_debounceTimer

wxTimer* LIB_TREE::m_debounceTimer
protected

Definition at line 217 of file lib_tree.h.

Referenced by LIB_TREE(), onQueryText(), and ~LIB_TREE().

◆ m_details_ctrl

HTML_WINDOW* LIB_TREE::m_details_ctrl
protected

Definition at line 216 of file lib_tree.h.

Referenced by LIB_TREE(), and onPreselect().

◆ m_inTimerEvent

bool LIB_TREE::m_inTimerEvent
protected

Definition at line 218 of file lib_tree.h.

Referenced by onDebounceTimer(), and onTreeSelect().

◆ m_last_libid

LIB_ID LIB_TREE::m_last_libid
protected

Definition at line 220 of file lib_tree.h.

◆ m_lib_table

LIB_TABLE* LIB_TREE::m_lib_table
protected

Definition at line 210 of file lib_tree.h.

◆ m_query_ctrl

wxSearchCtrl* LIB_TREE::m_query_ctrl
protected

◆ m_recentSearchesKey

wxString LIB_TREE::m_recentSearchesKey
protected

Definition at line 221 of file lib_tree.h.

Referenced by LIB_TREE(), and updateRecentSearchMenu().

◆ m_skipNextRightClick

bool LIB_TREE::m_skipNextRightClick
protected

Definition at line 223 of file lib_tree.h.

Referenced by onHeaderContextMenu(), and onItemContextMenu().

◆ m_tree_ctrl


The documentation for this class was generated from the following files: