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
329{
330 if( m_query_ctrl )
331 {
332 m_query_ctrl->SetFocus();
333 }
334}
335
336
337void LIB_TREE::toggleExpand( const wxDataViewItem& aTreeId )
338{
339 if( !aTreeId.IsOk() )
340 return;
341
342 if( m_tree_ctrl->IsExpanded( aTreeId ) )
343 m_tree_ctrl->Collapse( aTreeId );
344 else
345 m_tree_ctrl->Expand( aTreeId );
346}
347
348
349void LIB_TREE::selectIfValid( const wxDataViewItem& aTreeId )
350{
351 if( aTreeId.IsOk() )
352 {
353 m_tree_ctrl->EnsureVisible( aTreeId );
354 m_tree_ctrl->UnselectAll();
355 m_tree_ctrl->Select( aTreeId );
357 }
358}
359
360
361void LIB_TREE::centerIfValid( const wxDataViewItem& aTreeId )
362{
363 /*
364 * This doesn't actually center because the wxWidgets API is poorly suited to that (and
365 * it might be too noisy as well).
366 *
367 * It does try to keep the given item a bit off the top or bottom of the window.
368 */
369
370 if( aTreeId.IsOk() )
371 {
372 LIB_TREE_NODE* node = m_adapter->GetTreeNodeFor( aTreeId );
373 LIB_TREE_NODE* parent = node->m_Parent;
374 LIB_TREE_NODE* grandParent = parent ? parent->m_Parent : nullptr;
375
376 if( parent )
377 {
378 wxDataViewItemArray siblings;
379 m_adapter->GetChildren( wxDataViewItem( parent ), siblings );
380
381 int idx = siblings.Index( aTreeId );
382
383 if( idx + 5 < (int) siblings.GetCount() )
384 {
385 m_tree_ctrl->EnsureVisible( siblings.Item( idx + 5 ) );
386 }
387 else if( grandParent )
388 {
389 wxDataViewItemArray parentsSiblings;
390 m_adapter->GetChildren( wxDataViewItem( grandParent ), parentsSiblings );
391
392 int p_idx = parentsSiblings.Index( wxDataViewItem( parent ) );
393
394 if( p_idx + 1 < (int) parentsSiblings.GetCount() )
395 m_tree_ctrl->EnsureVisible( parentsSiblings.Item( p_idx + 1 ) );
396 }
397
398 if( idx - 5 >= 0 )
399 m_tree_ctrl->EnsureVisible( siblings.Item( idx - 5 ) );
400 else
401 m_tree_ctrl->EnsureVisible( wxDataViewItem( parent ) );
402 }
403
404 m_tree_ctrl->EnsureVisible( aTreeId );
405 }
406}
407
408
409void LIB_TREE::expandIfValid( const wxDataViewItem& aTreeId )
410{
411 if( aTreeId.IsOk() && !m_tree_ctrl->IsExpanded( aTreeId ) )
412 m_tree_ctrl->Expand( aTreeId );
413}
414
415
417{
418 wxCommandEvent event( SYMBOL_PRESELECTED );
419 wxPostEvent( this, event );
420}
421
422
424{
425 wxCommandEvent event( SYMBOL_SELECTED );
426 wxPostEvent( this, event );
427}
428
429
431{
432 STATE state;
433 wxDataViewItemArray items;
434 m_adapter->GetChildren( wxDataViewItem( nullptr ), items );
435
436 for( const wxDataViewItem& item : items )
437 {
438 if( m_tree_ctrl->IsExpanded( item ) )
439 state.expanded.push_back( item );
440 }
441
442 state.selection = GetSelectedLibId();
443
444 return state;
445}
446
447
448void LIB_TREE::setState( const STATE& aState )
449{
450 m_tree_ctrl->Freeze();
451
452 for( const wxDataViewItem& item : aState.expanded )
453 m_tree_ctrl->Expand( item );
454
455 // wxDataViewCtrl cannot be frozen when a selection
456 // command is issued, otherwise it selects a random item (Windows)
457 m_tree_ctrl->Thaw();
458
459 if( !aState.selection.GetLibItemName().empty() || !aState.selection.GetLibNickname().empty() )
460 SelectLibId( aState.selection );
461}
462
463
464void LIB_TREE::onQueryText( wxCommandEvent& aEvent )
465{
466 m_debounceTimer->StartOnce( 200 );
467
468 // Required to avoid interaction with SetHint()
469 // See documentation for wxTextEntry::SetHint
470 aEvent.Skip();
471}
472
473
474void LIB_TREE::onDebounceTimer( wxTimerEvent& aEvent )
475{
476 m_inTimerEvent = true;
477 Regenerate( false );
478 m_inTimerEvent = false;
479}
480
481
482void LIB_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke )
483{
484 const wxDataViewItem sel = m_tree_ctrl->GetSelection();
485 LIB_TREE_NODE::TYPE type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : LIB_TREE_NODE::INVALID;
486
487 switch( aKeyStroke.GetKeyCode() )
488 {
489 case WXK_UP:
492 break;
493
494 case WXK_DOWN:
497 break;
498
499 case WXK_ADD:
501
502 if( type == LIB_TREE_NODE::LIB )
503 m_tree_ctrl->Expand( sel );
504
505 break;
506
507 case WXK_SUBTRACT:
509
510 if( type == LIB_TREE_NODE::LIB )
511 m_tree_ctrl->Collapse( sel );
512
513 break;
514
515 case WXK_RETURN:
517
518 if( GetSelectedLibId().IsValid() )
520 else if( type == LIB_TREE_NODE::LIB )
521 toggleExpand( sel );
522
523 break;
524
525 default:
526 aKeyStroke.Skip(); // Any other key: pass on to search box directly.
527 break;
528 }
529}
530
531
532void LIB_TREE::onQueryMouseMoved( wxMouseEvent& aEvent )
533{
534 wxPoint pos = aEvent.GetPosition();
535 wxRect ctrlRect = m_query_ctrl->GetScreenRect();
536 int buttonWidth = ctrlRect.GetHeight(); // Presume buttons are square
537
538 if( m_query_ctrl->IsSearchButtonVisible() && pos.x < buttonWidth )
539 SetCursor( wxCURSOR_ARROW );
540 else if( m_query_ctrl->IsCancelButtonVisible() && pos.x > ctrlRect.GetWidth() - buttonWidth )
541 SetCursor( wxCURSOR_ARROW );
542 else
543 SetCursor( wxCURSOR_IBEAM );
544}
545
546
547void LIB_TREE::onTreeCharHook( wxKeyEvent& aKeyStroke )
548{
549 onQueryCharHook( aKeyStroke );
550
551 if( aKeyStroke.GetSkipped() )
552 {
553 if( TOOL_INTERACTIVE* tool = m_adapter->GetContextMenuTool() )
554 {
555 int hotkey = aKeyStroke.GetKeyCode();
556
557 if( aKeyStroke.ShiftDown() )
558 hotkey |= MD_SHIFT;
559
560 if( aKeyStroke.AltDown() )
561 hotkey |= MD_ALT;
562
563 if( aKeyStroke.ControlDown() )
564 hotkey |= MD_CTRL;
565
566 if( tool->GetManager()->GetActionManager()->RunHotKey( hotkey ) )
567 aKeyStroke.Skip( false );
568 }
569 }
570}
571
572
573void LIB_TREE::onTreeSelect( wxDataViewEvent& aEvent )
574{
575 if( !m_inTimerEvent )
577
578 if( !m_tree_ctrl->IsFrozen() )
580}
581
582
583void LIB_TREE::onTreeActivate( wxDataViewEvent& aEvent )
584{
585 if( !GetSelectedLibId().IsValid() )
586 toggleExpand( m_tree_ctrl->GetSelection() ); // Expand library/part units subtree
587 else
588 postSelectEvent(); // Open symbol/footprint
589}
590
591
592void LIB_TREE::onSize( wxSizeEvent& aEvent )
593{
594 m_adapter->OnSize( aEvent );
595}
596
597
598void LIB_TREE::onDetailsLink( wxHtmlLinkEvent& aEvent )
599{
600 const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
601 ::wxLaunchDefaultBrowser( info.GetHref() );
602}
603
604
605void LIB_TREE::onPreselect( wxCommandEvent& aEvent )
606{
607 if( m_details_ctrl )
608 {
609 int unit = 0;
610 LIB_ID id = GetSelectedLibId( &unit );
611
612 if( id.IsValid() )
613 m_details_ctrl->SetPage( m_adapter->GenerateInfo( id, unit ) );
614 else
615 m_details_ctrl->SetPage( wxEmptyString );
616 }
617
618 aEvent.Skip();
619}
620
621
622void LIB_TREE::onItemContextMenu( wxDataViewEvent& aEvent )
623{
625 {
626 m_skipNextRightClick = false;
627 return;
628 }
629
630 if( TOOL_INTERACTIVE* tool = m_adapter->GetContextMenuTool() )
631 {
632 if( !GetCurrentTreeNode() )
633 {
634 wxPoint pos = m_tree_ctrl->ScreenToClient( wxGetMousePosition() );
635
636 // What we actually want is the height of the column header, but wxWidgets gives us
637 // no way to get that, so we use the height of the search ctrl as a proxy. And it's
638 // not even a very good proxy on Mac....
639 int headerHeight = m_tree_ctrl->GetPosition().y;
640#ifdef __WXMAC__
641 headerHeight += 5;
642#endif
643
644 pos.y -= headerHeight;
645
646 wxDataViewItem item;
647 wxDataViewColumn* col;
648 m_tree_ctrl->HitTest( pos, item, col );
649
650 if( item.IsOk() )
651 {
652 m_tree_ctrl->SetFocus();
653 m_tree_ctrl->Select( item );
654 wxSafeYield();
655 }
656 }
657
658 tool->Activate();
659 tool->GetManager()->VetoContextMenuMouseWarp();
660 tool->GetToolMenu().ShowContextMenu();
661
663 tool->GetManager()->DispatchContextMenu( evt );
664 }
665 else
666 {
668
669 if( current && current->m_Type == LIB_TREE_NODE::LIB )
670 {
671 ACTION_MENU menu( true, nullptr );
672
673 if( current->m_Pinned )
674 {
676
677 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
678 m_adapter->UnpinLibrary( current );
679 }
680 else
681 {
682 menu.Add( ACTIONS::pinLibrary );
683
684 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
685 m_adapter->PinLibrary( current );
686 }
687 }
688 }
689}
690
691
692void LIB_TREE::onHeaderContextMenu( wxDataViewEvent& aEvent )
693{
694 ACTION_MENU menu( true, nullptr );
695
697
698 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
699 {
700 EDA_REORDERABLE_LIST_DIALOG dlg( m_parent, _( "Select Columns" ),
701 m_adapter->GetAvailableColumns(),
702 m_adapter->GetShownColumns() );
703
704 if( dlg.ShowModal() == wxID_OK )
705 m_adapter->SetShownColumns( dlg.EnabledList() );
706 }
707
708#if !wxCHECK_VERSION( 3, 1, 0 )
709 // wxGTK 3.0 sends item right click events for header right clicks
711#endif
712}
713
714
715wxDEFINE_EVENT( SYMBOL_PRESELECTED, wxCommandEvent );
716wxDEFINE_EVENT( SYMBOL_SELECTED, wxCommandEvent );
static TOOL_ACTION selectColumns
Definition: actions.h:176
static TOOL_ACTION pinLibrary
Definition: actions.h:113
static TOOL_ACTION unpinLibrary
Definition: actions.h:114
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:102
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:222
LIB_TREE_NODE * GetCurrentTreeNode() const
Definition: lib_tree.cpp:219
void onQueryMouseMoved(wxMouseEvent &aEvent)
Definition: lib_tree.cpp:532
HTML_WINDOW * m_details_ctrl
Definition: lib_tree.h:221
void onTreeActivate(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:583
wxString m_recentSearchesKey
Definition: lib_tree.h:226
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:220
void onQueryCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:482
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:423
wxWindow * GetFocusTarget()
Definition: lib_tree.cpp:319
void onSize(wxSizeEvent &aEvent)
Definition: lib_tree.cpp:592
void onItemContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:622
void onQueryText(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:464
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition: lib_tree.cpp:337
bool m_skipNextRightClick
Definition: lib_tree.h:228
bool m_inTimerEvent
Definition: lib_tree.h:223
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:349
void FocusSearchFieldIfExists()
Focus the search widget if it exists.
Definition: lib_tree.cpp:328
void expandIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:409
void onPreselect(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:605
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:573
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:416
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:242
void onTreeCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:547
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition: lib_tree.cpp:598
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:448
STATE getState() const
Return the symbol tree widget state.
Definition: lib_tree.cpp:430
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:219
void centerIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:361
void onDebounceTimer(wxTimerEvent &aEvent)
Definition: lib_tree.cpp:474
void onHeaderContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:692
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition: lib_tree.cpp:295
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:217
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:128
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:177
LIB_ID selection
Definition: lib_tree.h:183
std::vector< wxDataViewItem > expanded
< List of expanded nodes
Definition: lib_tree.h:179
@ 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.