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  WIDGETS { NONE = 0x00, SEARCH = 0x01, DETAILS = 0x02, ALL = 0xFF }
 < Flags to select extra widgets More...
 

Public Member Functions

 LIB_TREE (wxWindow *aParent, LIB_TABLE *aLibTable, wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > &aAdapter, WIDGETS aWidgets=ALL, 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...
 
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 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 onQueryText (wxCommandEvent &aEvent)
 
void onQueryEnter (wxCommandEvent &aEvent)
 
void onQueryCharHook (wxKeyEvent &aEvent)
 
void onTreeSelect (wxDataViewEvent &aEvent)
 
void onTreeActivate (wxDataViewEvent &aEvent)
 
void onDetailsLink (wxHtmlLinkEvent &aEvent)
 
void onPreselect (wxCommandEvent &aEvent)
 
void onContextMenu (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
 
LIB_ID m_last_libid
 

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

◆ WIDGETS

< Flags to select extra widgets

Enumerator
NONE 
SEARCH 
DETAILS 
ALL 

Definition at line 49 of file lib_tree.h.

49 { NONE = 0x00, SEARCH = 0x01, DETAILS = 0x02, ALL = 0xFF };

Constructor & Destructor Documentation

◆ LIB_TREE()

LIB_TREE::LIB_TREE ( wxWindow *  aParent,
LIB_TABLE aLibTable,
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > &  aAdapter,
WIDGETS  aWidgets = ALL,
HTML_WINDOW aDetails = nullptr 
)

Construct a symbol tree.

Parameters
aParentparent window containing this tree widget
aLibTabletable containing libraries and items to display
aAdaptera LIB_TREE_MODEL_ADAPTER instance to use
aWidgetsselection of sub-widgets to include
aDetailsif not null, a custom HTML_WINDOW to hold symbol details. If null this will be created inside the LIB_TREE.

Definition at line 38 of file lib_tree.cpp.

40  :
41  wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
42  wxWANTS_CHARS | wxTAB_TRAVERSAL | wxNO_BORDER ),
43  m_lib_table( aLibTable ), m_adapter( aAdapter ), m_query_ctrl( nullptr ),
44  m_details_ctrl( nullptr )
45 {
46  wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
47 
48  // Search text control
49  if( aWidgets & SEARCH )
50  {
51  wxBoxSizer* search_sizer = new wxBoxSizer( wxHORIZONTAL );
52 
53  m_query_ctrl = new wxSearchCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition,
54  wxDefaultSize );
55 
56  m_query_ctrl->ShowCancelButton( true );
57 
58 #ifdef __WXGTK__
59  // wxSearchCtrl vertical height is not calculated correctly on some GTK setups
60  // See https://gitlab.com/kicad/code/kicad/-/issues/9019
61  m_query_ctrl->SetMinSize( wxSize( -1, GetTextExtent( wxT( "qb" ) ).y + 10 ) );
62 #endif
63 
64  m_debounceTimer = new wxTimer( this );
65 
66  search_sizer->Add( m_query_ctrl, 1, wxEXPAND, 5 );
67 
68  sizer->Add( search_sizer, 0, wxEXPAND, 5 );
69 
70  m_query_ctrl->Bind( wxEVT_TEXT, &LIB_TREE::onQueryText, this );
71 
72 #if wxCHECK_VERSION( 3, 1, 1 )
73  m_query_ctrl->Bind( wxEVT_SEARCH, &LIB_TREE::onQueryEnter, this );
74 #else
75  m_query_ctrl->Bind( wxEVT_TEXT_ENTER, &LIB_TREE::onQueryEnter, this );
76 #endif
77 
78  m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &LIB_TREE::onQueryCharHook, this );
79 
80 
81  Bind( wxEVT_TIMER, &LIB_TREE::onDebounceTimer, this, m_debounceTimer->GetId() );
82  }
83 
84  // Tree control
85  m_tree_ctrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
86  wxDV_SINGLE );
87  m_adapter->AttachTo( m_tree_ctrl );
88 
89  if( aWidgets & DETAILS )
90  sizer->AddSpacer( 5 );
91 
92  sizer->Add( m_tree_ctrl, 5, wxRIGHT | wxBOTTOM | wxEXPAND, 1 );
93 
94  // Description panel
95  if( aWidgets & DETAILS )
96  {
97  if( !aDetails )
98  {
99  wxPoint html_size = ConvertDialogToPixels( wxPoint( 80, 80 ) );
100 
101  m_details_ctrl = new HTML_WINDOW( this, wxID_ANY, wxDefaultPosition,
102  wxSize( html_size.x, html_size.y ),
103  wxHW_SCROLLBAR_AUTO );
104 
105  sizer->Add( m_details_ctrl, 2, wxTOP | wxEXPAND, 5 );
106  }
107  else
108  {
109  m_details_ctrl = aDetails;
110  }
111 
112  m_details_ctrl->Bind( wxEVT_HTML_LINK_CLICKED, &LIB_TREE::onDetailsLink, this );
113  }
114 
115  SetSizer( sizer );
116 
117  m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &LIB_TREE::onTreeActivate, this );
118  m_tree_ctrl->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED, &LIB_TREE::onTreeSelect, this );
119  m_tree_ctrl->Bind( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &LIB_TREE::onContextMenu, this );
120 
121  Bind( SYMBOL_PRESELECTED, &LIB_TREE::onPreselect, this );
122 
123  // If wxTextCtrl::SetHint() is called before binding wxEVT_TEXT, the event
124  // handler will intermittently fire.
125  if( m_query_ctrl )
126  {
127  m_query_ctrl->SetDescriptiveText( _( "Filter" ) );
128  m_query_ctrl->SetFocus();
129  m_query_ctrl->SetValue( wxEmptyString );
130 
131  // Force an update of the adapter with the empty text to ensure preselect is done
132  Regenerate( false );
133  }
134  else
135  {
136  // There may be a part preselected in the model. Make sure it is displayed.
137  // Regenerate does this in the other branch
139  }
140 
141  Layout();
142  sizer->Fit( this );
143 
144 #ifdef __WXGTK__
145  // Scrollbars must be always enabled to prevent an infinite event loop
146  // more details: http://trac.wxwidgets.org/ticket/18141
147  if( m_details_ctrl )
148  m_details_ctrl->ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
149 #endif /* __WXGTK__ */
150 }
wxSearchCtrl * m_query_ctrl
Definition: lib_tree.h:179
void onQueryEnter(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:382
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:177
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:180
void onPreselect(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:466
LIB_TABLE * m_lib_table
Definition: lib_tree.h:175
void onQueryCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:395
HTML_WINDOW * m_details_ctrl
Definition: lib_tree.h:181
void onTreeActivate(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:445
void onQueryText(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:372
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition: lib_tree.cpp:213
void onTreeSelect(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:438
#define _(s)
wxTimer * m_debounceTimer
Definition: lib_tree.h:182
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition: lib_tree.cpp:459
void onDebounceTimer(wxTimerEvent &aEvent)
Definition: lib_tree.cpp:389
Add dark theme support to wxHtmlWindow.
Definition: html_window.h:33
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:324
void onContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:483

References _, DETAILS, m_adapter, m_debounceTimer, m_details_ctrl, m_query_ctrl, m_tree_ctrl, onContextMenu(), onDebounceTimer(), onDetailsLink(), onPreselect(), onQueryCharHook(), onQueryEnter(), onQueryText(), onTreeActivate(), onTreeSelect(), postPreselectEvent(), Regenerate(), and SEARCH.

◆ ~LIB_TREE()

LIB_TREE::~LIB_TREE ( )
override

Definition at line 153 of file lib_tree.cpp.

154 {
155  // Stop the timer during destruction early to avoid potential race conditions (that do happen)
156  m_debounceTimer->Stop();
157 
158  // Save the column widths to the config file
159  m_adapter->SaveColWidths();
160 
161  m_adapter->SavePinnedItems();
162 }
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:177
wxTimer * m_debounceTimer
Definition: lib_tree.h:182

References m_adapter, and m_debounceTimer.

Member Function Documentation

◆ centerIfValid()

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

Definition at line 269 of file lib_tree.cpp.

270 {
271  /*
272  * This doesn't actually center because the wxWidgets API is poorly suited to that (and
273  * it might be too noisy as well).
274  *
275  * It does try to keep the given item a bit off the top or bottom of the window.
276  */
277 
278  if( aTreeId.IsOk() )
279  {
280  LIB_TREE_NODE* node = m_adapter->GetTreeNodeFor( aTreeId );
281  LIB_TREE_NODE* parent = node->m_Parent;
282  LIB_TREE_NODE* grandParent = parent ? parent->m_Parent : nullptr;
283 
284  if( parent )
285  {
286  wxDataViewItemArray siblings;
287  m_adapter->GetChildren( wxDataViewItem( parent ), siblings );
288 
289  int idx = siblings.Index( aTreeId );
290 
291  if( idx + 5 < (int) siblings.GetCount() )
292  {
293  m_tree_ctrl->EnsureVisible( siblings.Item( idx + 5 ) );
294  }
295  else if( grandParent )
296  {
297  wxDataViewItemArray parentsSiblings;
298  m_adapter->GetChildren( wxDataViewItem( grandParent ), parentsSiblings );
299 
300  int p_idx = parentsSiblings.Index( wxDataViewItem( parent ) );
301 
302  if( p_idx + 1 < (int) parentsSiblings.GetCount() )
303  m_tree_ctrl->EnsureVisible( parentsSiblings.Item( p_idx + 1 ) );
304  }
305 
306  if( idx - 5 >= 0 )
307  m_tree_ctrl->EnsureVisible( siblings.Item( idx - 5 ) );
308  else
309  m_tree_ctrl->EnsureVisible( wxDataViewItem( parent ) );
310  }
311 
312  m_tree_ctrl->EnsureVisible( aTreeId );
313  }
314 }
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:177
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:180
LIB_TREE_NODE * m_Parent
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.

References m_adapter, LIB_TREE_NODE::m_Parent, and m_tree_ctrl.

Referenced by CenterLibId().

◆ CenterLibId()

void LIB_TREE::CenterLibId ( const LIB_ID aLibId)

Ensure that an item is visible (preferably centered).

Definition at line 196 of file lib_tree.cpp.

197 {
198  centerIfValid( m_adapter->FindItem( aLibId ) );
199 }
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:177
void centerIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:269

References centerIfValid(), and m_adapter.

Referenced by SYMBOL_EDIT_FRAME::centerItemIdleHandler(), SYMBOL_EDIT_FRAME::KiwayMailIn(), FOOTPRINT_EDIT_FRAME::RegenerateLibraryTree(), SYMBOL_EDIT_FRAME::RegenerateLibraryTree(), SYMBOL_EDIT_FRAME::SyncLibraries(), and FOOTPRINT_EDIT_FRAME::SyncLibraryTree().

◆ expandIfValid()

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

Definition at line 317 of file lib_tree.cpp.

318 {
319  if( aTreeId.IsOk() && !m_tree_ctrl->IsExpanded( aTreeId ) )
320  m_tree_ctrl->Expand( aTreeId );
321 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:180

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 207 of file lib_tree.cpp.

208 {
209  expandIfValid( m_adapter->FindItem( aLibId ) );
210 }
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:177
void expandIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:317

References expandIfValid(), and m_adapter.

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

◆ GetCurrentTreeNode()

LIB_TREE_NODE * LIB_TREE::GetCurrentTreeNode ( ) const

Definition at line 179 of file lib_tree.cpp.

180 {
181  wxDataViewItem sel = m_tree_ctrl->GetSelection();
182 
183  if( !sel )
184  return nullptr;
185 
186  return m_adapter->GetTreeNodeFor( sel );
187 }
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:177
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:180

References m_adapter, and m_tree_ctrl.

Referenced by SYMBOL_EDIT_FRAME::GetCurrentTreeNode(), and FOOTPRINT_EDIT_FRAME::GetCurrentTreeNode().

◆ GetFocusTarget()

wxWindow * LIB_TREE::GetFocusTarget ( )

Definition at line 237 of file lib_tree.cpp.

238 {
239  if( m_query_ctrl )
240  return m_query_ctrl;
241  else
242  return m_tree_ctrl;
243 }
wxSearchCtrl * m_query_ctrl
Definition: lib_tree.h:179
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:180

References m_query_ctrl, and m_tree_ctrl.

Referenced by DIALOG_CHOOSE_FOOTPRINT::DIALOG_CHOOSE_FOOTPRINT(), 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 165 of file lib_tree.cpp.

166 {
167  wxDataViewItem sel = m_tree_ctrl->GetSelection();
168 
169  if( !sel )
170  return LIB_ID();
171 
172  if( aUnit )
173  *aUnit = m_adapter->GetUnitFor( sel );
174 
175  return m_adapter->GetAliasFor( sel );
176 }
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:177
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:180
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51

References m_adapter, and m_tree_ctrl.

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

◆ getState()

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

Return the symbol tree widget state.

Definition at line 338 of file lib_tree.cpp.

339 {
340  STATE state;
341  wxDataViewItemArray items;
342  m_adapter->GetChildren( wxDataViewItem( nullptr ), items );
343 
344  for( const wxDataViewItem& item : items )
345  {
346  if( m_tree_ctrl->IsExpanded( item ) )
347  state.expanded.push_back( item );
348  }
349 
350  state.selection = GetSelectedLibId();
351 
352  return state;
353 }
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:177
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:180
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:165

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

Referenced by Regenerate().

◆ onContextMenu()

void LIB_TREE::onContextMenu ( wxDataViewEvent &  aEvent)
protected

Definition at line 483 of file lib_tree.cpp.

484 {
485  TOOL_INTERACTIVE* tool = m_adapter->GetContextMenuTool();
486 
487  if( tool )
488  {
489  tool->Activate();
491  tool->GetToolMenu().ShowContextMenu();
492 
494  tool->GetManager()->DispatchContextMenu( evt );
495  }
496 }
void DispatchContextMenu(const TOOL_EVENT &aEvent)
Handle context menu related events.
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:177
TOOL_MENU & GetToolMenu()
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
Generic, UI-independent tool event.
Definition: tool_event.h:152
void VetoContextMenuMouseWarp()
Disable mouse warping after the current context menu is closed.
Definition: tool_manager.h:422
void Activate()
Run the tool.
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:59

References TOOL_INTERACTIVE::Activate(), BUT_RIGHT, TOOL_MANAGER::DispatchContextMenu(), TOOL_BASE::GetManager(), TOOL_INTERACTIVE::GetToolMenu(), m_adapter, TOOL_MENU::ShowContextMenu(), TA_MOUSE_CLICK, TC_MOUSE, and TOOL_MANAGER::VetoContextMenuMouseWarp().

Referenced by LIB_TREE().

◆ onDebounceTimer()

void LIB_TREE::onDebounceTimer ( wxTimerEvent &  aEvent)
protected

Definition at line 389 of file lib_tree.cpp.

390 {
391  Regenerate( false );
392 }
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition: lib_tree.cpp:213

References Regenerate().

Referenced by LIB_TREE().

◆ onDetailsLink()

void LIB_TREE::onDetailsLink ( wxHtmlLinkEvent &  aEvent)
protected

Definition at line 459 of file lib_tree.cpp.

460 {
461  const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
462  ::wxLaunchDefaultBrowser( info.GetHref() );
463 }

References info.

Referenced by LIB_TREE().

◆ onPreselect()

void LIB_TREE::onPreselect ( wxCommandEvent &  aEvent)
protected

Definition at line 466 of file lib_tree.cpp.

467 {
468  if( m_details_ctrl )
469  {
470  int unit = 0;
471  LIB_ID id = GetSelectedLibId( &unit );
472 
473  if( id.IsValid() )
474  m_details_ctrl->SetPage( m_adapter->GenerateInfo( id, unit ) );
475  else
476  m_details_ctrl->SetPage( wxEmptyString );
477  }
478 
479  aEvent.Skip();
480 }
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:177
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
HTML_WINDOW * m_details_ctrl
Definition: lib_tree.h:181
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:165
bool SetPage(const wxString &aSource) override
Definition: html_window.cpp:38

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

Referenced by LIB_TREE().

◆ onQueryCharHook()

void LIB_TREE::onQueryCharHook ( wxKeyEvent &  aEvent)
protected

Definition at line 395 of file lib_tree.cpp.

396 {
397  auto const sel = m_tree_ctrl->GetSelection();
398  auto type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : LIB_TREE_NODE::INVALID;
399 
400  switch( aKeyStroke.GetKeyCode() )
401  {
402  case WXK_UP:
404  break;
405 
406  case WXK_DOWN:
408  break;
409 
410  case WXK_ADD:
411  if( type == LIB_TREE_NODE::LIB )
412  m_tree_ctrl->Expand( sel );
413 
414  break;
415 
416  case WXK_SUBTRACT:
417  if( type == LIB_TREE_NODE::LIB )
418  m_tree_ctrl->Collapse( sel );
419 
420  break;
421 
422  case WXK_RETURN:
423  if( type == LIB_TREE_NODE::LIB )
424  {
425  toggleExpand( sel );
426  break;
427  }
428  // Intentionally fall through, so the selected symbol will be treated as the selected one
430 
431  default:
432  aKeyStroke.Skip(); // Any other key: pass on to search box directly.
433  break;
434  }
435 }
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:258
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition: lib_tree.cpp:246
wxDataViewItem GetPrevItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the previous item in list order.
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:177
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:180
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
wxDataViewItem GetNextItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the next item in list order.

References GetNextItem(), GetPrevItem(), LIB_TREE_NODE::INVALID, KI_FALLTHROUGH, LIB_TREE_NODE::LIB, m_adapter, m_tree_ctrl, selectIfValid(), and toggleExpand().

Referenced by LIB_TREE().

◆ onQueryEnter()

void LIB_TREE::onQueryEnter ( wxCommandEvent &  aEvent)
protected

Definition at line 382 of file lib_tree.cpp.

383 {
384  if( GetSelectedLibId().IsValid() )
385  postSelectEvent();
386 }
void postSelectEvent()
Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
Definition: lib_tree.cpp:331
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:165

References GetSelectedLibId(), and postSelectEvent().

Referenced by LIB_TREE().

◆ onQueryText()

void LIB_TREE::onQueryText ( wxCommandEvent &  aEvent)
protected

Definition at line 372 of file lib_tree.cpp.

373 {
374  m_debounceTimer->StartOnce( 200 );
375 
376  // Required to avoid interaction with SetHint()
377  // See documentation for wxTextEntry::SetHint
378  aEvent.Skip();
379 }
wxTimer * m_debounceTimer
Definition: lib_tree.h:182

References m_debounceTimer.

Referenced by LIB_TREE().

◆ onTreeActivate()

void LIB_TREE::onTreeActivate ( wxDataViewEvent &  aEvent)
protected

Definition at line 445 of file lib_tree.cpp.

446 {
447  if( !GetSelectedLibId().IsValid() )
448  {
449  // Expand library/part units subtree
450  toggleExpand( m_tree_ctrl->GetSelection() );
451  }
452  else
453  {
454  postSelectEvent();
455  }
456 }
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition: lib_tree.cpp:246
void postSelectEvent()
Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
Definition: lib_tree.cpp:331
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:180
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:165

References GetSelectedLibId(), m_tree_ctrl, postSelectEvent(), and toggleExpand().

Referenced by LIB_TREE().

◆ onTreeSelect()

void LIB_TREE::onTreeSelect ( wxDataViewEvent &  aEvent)
protected

Definition at line 438 of file lib_tree.cpp.

439 {
440  if( !m_tree_ctrl->IsFrozen() )
442 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:180
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:324

References m_tree_ctrl, and postPreselectEvent().

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 324 of file lib_tree.cpp.

325 {
326  wxCommandEvent event( SYMBOL_PRESELECTED );
327  wxPostEvent( this, event );
328 }

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 331 of file lib_tree.cpp.

332 {
333  wxCommandEvent event( SYMBOL_SELECTED );
334  wxPostEvent( this, event );
335 }

Referenced by onQueryEnter(), and onTreeActivate().

◆ RefreshLibTree()

void LIB_TREE::RefreshLibTree ( )

◆ Regenerate()

void LIB_TREE::Regenerate ( bool  aKeepState)

Regenerate the tree.

Definition at line 213 of file lib_tree.cpp.

214 {
215  STATE current;
216 
217  // Store the state
218  if( aKeepState )
219  current = getState();
220 
221  wxString filter = m_query_ctrl->GetValue();
222  m_adapter->UpdateSearchString( filter, aKeepState );
224 
225  // Restore the state
226  if( aKeepState )
227  setState( current );
228 }
wxSearchCtrl * m_query_ctrl
Definition: lib_tree.h:179
STATE getState() const
Return the symbol tree widget state.
Definition: lib_tree.cpp:338
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:177
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:324
void setState(const STATE &aState)
Restore the symbol tree widget state from an object.
Definition: lib_tree.cpp:356

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

Referenced by LIB_TREE(), onDebounceTimer(), FOOTPRINT_EDIT_FRAME::RegenerateLibraryTree(), SYMBOL_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 258 of file lib_tree.cpp.

259 {
260  if( aTreeId.IsOk() )
261  {
262  m_tree_ctrl->EnsureVisible( aTreeId );
263  m_tree_ctrl->Select( aTreeId );
265  }
266 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:180
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:324

References m_tree_ctrl, and postPreselectEvent().

Referenced by onQueryCharHook(), and SelectLibId().

◆ SelectLibId()

void LIB_TREE::SelectLibId ( const LIB_ID aLibId)

◆ setState()

void LIB_TREE::setState ( const STATE aState)
protected

Restore the symbol tree widget state from an object.

Definition at line 356 of file lib_tree.cpp.

357 {
358  m_tree_ctrl->Freeze();
359 
360  for( const wxDataViewItem& item : aState.expanded )
361  m_tree_ctrl->Expand( item );
362 
363  // wxDataViewCtrl cannot be frozen when a selection
364  // command is issued, otherwise it selects a random item (Windows)
365  m_tree_ctrl->Thaw();
366 
367  if( !aState.selection.GetLibItemName().empty() || !aState.selection.GetLibNickname().empty() )
368  SelectLibId( aState.selection );
369 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:180
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:190

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 246 of file lib_tree.cpp.

247 {
248  if( !aTreeId.IsOk() )
249  return;
250 
251  if( m_tree_ctrl->IsExpanded( aTreeId ) )
252  m_tree_ctrl->Collapse( aTreeId );
253  else
254  m_tree_ctrl->Expand( aTreeId );
255 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:180

References m_tree_ctrl.

Referenced by onQueryCharHook(), and onTreeActivate().

◆ Unselect()

void LIB_TREE::Unselect ( )

Member Data Documentation

◆ m_adapter

◆ m_debounceTimer

wxTimer* LIB_TREE::m_debounceTimer
protected

Definition at line 182 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 181 of file lib_tree.h.

Referenced by LIB_TREE(), and onPreselect().

◆ m_last_libid

LIB_ID LIB_TREE::m_last_libid
protected

Definition at line 184 of file lib_tree.h.

◆ m_lib_table

LIB_TABLE* LIB_TREE::m_lib_table
protected

Definition at line 175 of file lib_tree.h.

◆ m_query_ctrl

wxSearchCtrl* LIB_TREE::m_query_ctrl
protected

Definition at line 179 of file lib_tree.h.

Referenced by GetFocusTarget(), LIB_TREE(), and Regenerate().

◆ m_tree_ctrl


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