KiCad PCB EDA Suite
lib_tree.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2014 Henner Zeller <[email protected]>
5 * Copyright (C) 2014-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <widgets/lib_tree.h>
26#include <core/kicad_algo.h>
27#include <macros.h>
29#include <wx/sizer.h>
32#include <tool/tool_manager.h>
33#include <tool/action_manager.h>
34#include <tool/actions.h>
35#include <wx/srchctrl.h>
36#include <wx/settings.h>
37#include <wx/timer.h>
38
39constexpr int RECENT_SEARCHES_MAX = 10;
40
41std::map<wxString, std::vector<wxString>> g_recentSearches;
42
43
44LIB_TREE::LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey, LIB_TABLE* aLibTable,
45 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter, int aFlags,
46 HTML_WINDOW* aDetails ) :
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 ),
53 m_skipNextRightClick( false )
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}
179
180
182{
183 // Stop the timer during destruction early to avoid potential race conditions (that do happen)
184 m_debounceTimer->Stop();
185}
186
187
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}
200
201
202int LIB_TREE::GetSelectedLibIds( std::vector<LIB_ID>& aSelection, std::vector<int>* aUnit ) const
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}
217
218
220{
221 wxDataViewItem sel = m_tree_ctrl->GetSelection();
222
223 if( !sel )
224 return nullptr;
225
226 return m_adapter->GetTreeNodeFor( sel );
227}
228
229
230void LIB_TREE::SelectLibId( const LIB_ID& aLibId )
231{
232 selectIfValid( m_adapter->FindItem( aLibId ) );
233}
234
235
236void LIB_TREE::CenterLibId( const LIB_ID& aLibId )
237{
238 centerIfValid( m_adapter->FindItem( aLibId ) );
239}
240
241
243{
244 m_tree_ctrl->UnselectAll();
245}
246
247
248void LIB_TREE::ExpandLibId( const LIB_ID& aLibId )
249{
250 expandIfValid( m_adapter->FindItem( aLibId ) );
251}
252
253
254void LIB_TREE::SetSearchString( const wxString& aSearchString )
255{
256 m_query_ctrl->ChangeValue( aSearchString );
257}
258
259
261{
262 return m_query_ctrl->GetValue();
263}
264
265
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}
293
294
295void LIB_TREE::Regenerate( bool aKeepState )
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}
311
312
314{
315 m_adapter->RefreshTree();
316}
317
318
320{
321 if( m_query_ctrl )
322 return m_query_ctrl;
323 else
324 return m_tree_ctrl;
325}
326
327
328void LIB_TREE::toggleExpand( const wxDataViewItem& aTreeId )
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}
338
339
340void LIB_TREE::selectIfValid( const wxDataViewItem& aTreeId )
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}
350
351
352void LIB_TREE::centerIfValid( const wxDataViewItem& aTreeId )
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}
398
399
400void LIB_TREE::expandIfValid( const wxDataViewItem& aTreeId )
401{
402 if( aTreeId.IsOk() && !m_tree_ctrl->IsExpanded( aTreeId ) )
403 m_tree_ctrl->Expand( aTreeId );
404}
405
406
408{
409 wxCommandEvent event( SYMBOL_PRESELECTED );
410 wxPostEvent( this, event );
411}
412
413
415{
416 wxCommandEvent event( SYMBOL_SELECTED );
417 wxPostEvent( this, event );
418}
419
420
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}
437
438
439void LIB_TREE::setState( const STATE& aState )
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}
453
454
455void LIB_TREE::onQueryText( wxCommandEvent& aEvent )
456{
457 m_debounceTimer->StartOnce( 200 );
458
459 // Required to avoid interaction with SetHint()
460 // See documentation for wxTextEntry::SetHint
461 aEvent.Skip();
462}
463
464
465void LIB_TREE::onDebounceTimer( wxTimerEvent& aEvent )
466{
467 m_inTimerEvent = true;
468 Regenerate( false );
469 m_inTimerEvent = false;
470}
471
472
473void LIB_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke )
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}
521
522
523void LIB_TREE::onQueryMouseMoved( wxMouseEvent& aEvent )
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}
536
537
538void LIB_TREE::onTreeCharHook( wxKeyEvent& aKeyStroke )
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}
562
563
564void LIB_TREE::onTreeSelect( wxDataViewEvent& aEvent )
565{
566 if( !m_inTimerEvent )
568
569 if( !m_tree_ctrl->IsFrozen() )
571}
572
573
574void LIB_TREE::onTreeActivate( wxDataViewEvent& aEvent )
575{
576 if( !GetSelectedLibId().IsValid() )
577 toggleExpand( m_tree_ctrl->GetSelection() ); // Expand library/part units subtree
578 else
579 postSelectEvent(); // Open symbol/footprint
580}
581
582
583void LIB_TREE::onSize( wxSizeEvent& aEvent )
584{
585 m_adapter->OnSize( aEvent );
586}
587
588
589void LIB_TREE::onDetailsLink( wxHtmlLinkEvent& aEvent )
590{
591 const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
592 ::wxLaunchDefaultBrowser( info.GetHref() );
593}
594
595
596void LIB_TREE::onPreselect( wxCommandEvent& aEvent )
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}
611
612
613void LIB_TREE::onItemContextMenu( wxDataViewEvent& aEvent )
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 {
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}
655
656
657void LIB_TREE::onHeaderContextMenu( wxDataViewEvent& aEvent )
658{
659 ACTION_MENU menu( true, nullptr );
660
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}
678
679
680wxDEFINE_EVENT( SYMBOL_PRESELECTED, wxCommandEvent );
681wxDEFINE_EVENT( SYMBOL_SELECTED, wxCommandEvent );
static TOOL_ACTION selectColumns
Definition: actions.h:175
static TOOL_ACTION pinLibrary
Definition: actions.h:112
static TOOL_ACTION unpinLibrary
Definition: actions.h:113
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
A dialog which allows selecting a list of items from a list of available items, and reordering those ...
const std::vector< wxString > & EnabledList()
Add dark theme support to wxHtmlWindow.
Definition: html_window.h:34
bool SetPage(const wxString &aSource) override
Definition: html_window.cpp:38
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
const UTF8 & GetLibItemName() const
Definition: lib_id.h:101
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
enum TYPE m_Type
LIB_TREE_NODE * m_Parent
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.
Definition: lib_tree.cpp:44
void RefreshLibTree()
Refreshes the tree (mainly to update highlighting and asterisking)
Definition: lib_tree.cpp:313
wxTimer * m_debounceTimer
Definition: lib_tree.h:217
LIB_TREE_NODE * GetCurrentTreeNode() const
Definition: lib_tree.cpp:219
void onQueryMouseMoved(wxMouseEvent &aEvent)
Definition: lib_tree.cpp:523
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 CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferably centered).
Definition: lib_tree.cpp:236
void postSelectEvent()
Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
Definition: lib_tree.cpp:414
wxWindow * GetFocusTarget()
Definition: lib_tree.cpp:319
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
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition: lib_tree.cpp:328
bool m_skipNextRightClick
Definition: lib_tree.h:223
bool m_inTimerEvent
Definition: lib_tree.h:218
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:340
void expandIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:400
void onPreselect(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:596
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:230
void updateRecentSearchMenu()
Definition: lib_tree.cpp:266
wxString GetSearchString() const
Definition: lib_tree.cpp:260
void onTreeSelect(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:564
int GetSelectedLibIds(std::vector< LIB_ID > &aSelection, std::vector< int > *aUnit=nullptr) const
Retrieves a list of selections for trees that allow multi-selection.
Definition: lib_tree.cpp:202
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 Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:242
void onTreeCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:538
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition: lib_tree.cpp:589
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
@ MULTISELECT
Definition: lib_tree.h:55
@ DETAILS
Definition: lib_tree.h:53
@ SEARCH
Definition: lib_tree.h:52
~LIB_TREE() override
Definition: lib_tree.cpp:181
void SetSearchString(const wxString &aSearchString)
Save/restore search string.
Definition: lib_tree.cpp:254
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
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
Definition: lib_tree.cpp:248
wxSearchCtrl * m_query_ctrl
Definition: lib_tree.h:214
void centerIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:352
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
Generic, UI-independent tool event.
Definition: tool_event.h:156
bool empty() const
Definition: utf8.h:103
#define _(s)
constexpr int RECENT_SEARCHES_MAX
Definition: lib_tree.cpp:39
wxDEFINE_EVENT(SYMBOL_PRESELECTED, wxCommandEvent)
std::map< wxString, std::vector< wxString > > g_recentSearches
Definition: lib_tree.cpp:41
This file contains miscellaneous commonly used macros and functions.
bool IsValid(const std::string &aString, SIM_VALUE::TYPE aValueType=SIM_VALUE::TYPE_FLOAT, NOTATION aNotation=NOTATION::SI)
Definition: sim_value.cpp:127
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
Structure storing state of the symbol tree widget.
Definition: lib_tree.h:172
LIB_ID selection
Definition: lib_tree.h:178
std::vector< wxDataViewItem > expanded
< List of expanded nodes
Definition: lib_tree.h:174
@ TA_MOUSE_CLICK
Definition: tool_event.h:62
@ TC_MOUSE
Definition: tool_event.h:50
@ MD_ALT
Definition: tool_event.h:140
@ MD_CTRL
Definition: tool_event.h:139
@ MD_SHIFT
Definition: tool_event.h:138
@ BUT_RIGHT
Definition: tool_event.h:128
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.
wxDataViewCtrl helper functions.