KiCad PCB EDA Suite
LIB_TREE Class Reference

Widget displaying a tree of components with optional search text control and description panel. More...

#include <lib_tree.h>

Inheritance diagram for LIB_TREE:

Classes

struct  STATE
 Structure storing state of the component 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, LIB_TREE_MODEL_ADAPTER::PTR &aAdapter, WIDGETS aWidgets=ALL, wxHtmlWindow *aDetails=nullptr)
 Construct a component tree. More...
 
 ~LIB_TREE () override
 
LIB_ID GetSelectedLibId (int *aUnit=nullptr) const
 For multi-unit components, if the user selects the component 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 (preferrably 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)
 Regenerates the tree. More...
 
void RefreshLibTree ()
 Refreshes the tree (mainly to update highlighting and asterisking) More...
 
void SetFocus () override
 

Protected Member Functions

void toggleExpand (const wxDataViewItem &aTreeId)
 Expands or collapses 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 COMPONENT_SELECTED event to notify the selection handler that a part has been selected. More...
 
STATE getState () const
 Returns the component tree widget state. More...
 
void setState (const STATE &aState)
 Restores the component 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)
 

Protected Attributes

LIB_TABLEm_lib_table
 
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
 
wxTextCtrl * m_query_ctrl
 
wxDataViewCtrl * m_tree_ctrl
 
wxHtmlWindow * m_details_ctrl
 

Detailed Description

Widget displaying a tree of components with optional search text control and description panel.

Definition at line 42 of file lib_tree.h.

Member Enumeration Documentation

◆ WIDGETS

Flags to select extra widgets

Enumerator
NONE 
SEARCH 
DETAILS 
ALL 

Definition at line 46 of file lib_tree.h.

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

Constructor & Destructor Documentation

◆ LIB_TREE()

LIB_TREE::LIB_TREE ( wxWindow *  aParent,
LIB_TABLE aLibTable,
LIB_TREE_MODEL_ADAPTER::PTR aAdapter,
WIDGETS  aWidgets = ALL,
wxHtmlWindow *  aDetails = nullptr 
)

Construct a component 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 wxHtmlWindow to hold symbol details. If null this will be created inside the LIB_TREE.

Definition at line 34 of file lib_tree.cpp.

36  : wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
37  wxWANTS_CHARS | wxTAB_TRAVERSAL | wxNO_BORDER ),
38  m_lib_table( aLibTable ),
39  m_adapter( aAdapter ),
40  m_query_ctrl( nullptr ),
41  m_details_ctrl( nullptr )
42 {
43  auto sizer = new wxBoxSizer( wxVERTICAL );
44 
45  // Search text control
46  if( aWidgets & SEARCH )
47  {
48  auto search_sizer = new wxBoxSizer( wxHORIZONTAL );
49 
50  m_query_ctrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition,
51  wxDefaultSize, wxTE_PROCESS_ENTER );
52 
53 // Additional visual cue for GTK, which hides the placeholder text on focus
54 #ifdef __WXGTK__
55  auto bitmap = new wxStaticBitmap( this, wxID_ANY, wxArtProvider::GetBitmap( wxART_FIND, wxART_FRAME_ICON ) );
56 
57  if( aWidgets & DETAILS )
58  search_sizer->Add( bitmap, 0, wxALIGN_CENTER | wxALL, 5 );
59  else
60  search_sizer->Add( bitmap, 0, wxALIGN_CENTER | wxRIGHT, 5 );
61 #endif
62 
63  if( aWidgets & DETAILS )
64  search_sizer->Add( m_query_ctrl, 1, wxLEFT | wxTOP | wxRIGHT | wxEXPAND, 5 );
65  else
66  search_sizer->Add( m_query_ctrl, 1, wxEXPAND, 5 );
67  sizer->Add( search_sizer, 0, wxEXPAND, 5 );
68 
69  m_query_ctrl->Bind( wxEVT_TEXT, &LIB_TREE::onQueryText, this );
70  m_query_ctrl->Bind( wxEVT_TEXT_ENTER, &LIB_TREE::onQueryEnter, this );
71  m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &LIB_TREE::onQueryCharHook, this );
72  }
73 
74  // Tree control
75  m_tree_ctrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
76  wxDV_SINGLE );
77  m_adapter->AttachTo( m_tree_ctrl );
78 
79  if( aWidgets & DETAILS )
80  sizer->Add( m_tree_ctrl, 5, wxLEFT | wxTOP | wxRIGHT | wxEXPAND, 5 );
81  else
82  sizer->Add( m_tree_ctrl, 5, wxRIGHT | wxBOTTOM | wxEXPAND, 1 );
83 
84  // Description panel
85  if( aWidgets & DETAILS )
86  {
87  if( !aDetails )
88  {
89  auto html_sz = ConvertDialogToPixels( wxPoint( 80, 80 ) );
90 
91  m_details_ctrl = new wxHtmlWindow(
92  this, wxID_ANY, wxDefaultPosition, wxSize( html_sz.x, html_sz.y ),
93  wxHW_SCROLLBAR_AUTO );
94 
95  sizer->Add( m_details_ctrl, 2, wxALL | wxEXPAND, 5 );
96  }
97  else
98  {
99  m_details_ctrl = aDetails;
100  }
101 
102  m_details_ctrl->Bind( wxEVT_HTML_LINK_CLICKED, &LIB_TREE::onDetailsLink, this );
103  }
104 
105  SetSizer( sizer );
106 
107  m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &LIB_TREE::onTreeActivate, this );
108  m_tree_ctrl->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED, &LIB_TREE::onTreeSelect, this );
109  m_tree_ctrl->Bind( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &LIB_TREE::onContextMenu, this );
110 
111  Bind( COMPONENT_PRESELECTED, &LIB_TREE::onPreselect, this );
112 
113  // If wxTextCtrl::SetHint() is called before binding wxEVT_TEXT, the event
114  // handler will intermittently fire.
115  if( m_query_ctrl )
116  {
117  m_query_ctrl->SetHint( _( "Filter" ) );
118  m_query_ctrl->SetFocus();
119  m_query_ctrl->SetValue( wxEmptyString ); // SetValue() is required here to kick off
120  // initial sorting and pre-selection.
121  }
122 
123  // There may be a part preselected in the model. Make sure it is displayed.
125 
126  Layout();
127  sizer->Fit( this );
128 
129 #ifdef __WXGTK__
130  // Scrollbars must be always enabled to prevent an infinite event loop
131  // more details: http://trac.wxwidgets.org/ticket/18141
132  if( m_details_ctrl )
133  m_details_ctrl->ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
134 #endif /* __WXGTK__ */
135 }
void onQueryEnter(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:327
wxHtmlWindow * m_details_ctrl
Definition: lib_tree.h:174
BITMAP_DEF GetBitmap(GRAPHIC_PINSHAPE aShape)
Definition: pin_shape.cpp:68
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:173
void onPreselect(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:403
LIB_TABLE * m_lib_table
Definition: lib_tree.h:169
void onQueryCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:334
void onTreeActivate(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:382
void onQueryText(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:317
void onTreeSelect(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:376
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition: lib_tree.cpp:396
#define _(s)
Definition: 3d_actions.cpp: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:269
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:170
wxTextCtrl * m_query_ctrl
Definition: lib_tree.h:172
void onContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:420

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

◆ ~LIB_TREE()

LIB_TREE::~LIB_TREE ( )
override

Definition at line 138 of file lib_tree.cpp.

139 {
140  // Save the column widths to the config file
141  m_adapter->SaveColWidths();
142 
143  m_adapter->SavePinnedItems();
144 }
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:170

References m_adapter.

Member Function Documentation

◆ centerIfValid()

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

Definition at line 255 of file lib_tree.cpp.

256 {
257  if( aTreeId.IsOk() )
258  m_tree_ctrl->EnsureVisible( aTreeId );
259 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:173

References m_tree_ctrl.

Referenced by CenterLibId().

◆ CenterLibId()

void LIB_TREE::CenterLibId ( const LIB_ID aLibId)

Ensure that an item is visible (preferrably centered).

Definition at line 182 of file lib_tree.cpp.

183 {
184  centerIfValid( m_adapter->FindItem( aLibId ) );
185 }
void centerIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:255
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:170

References centerIfValid(), and m_adapter.

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

◆ expandIfValid()

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

Definition at line 262 of file lib_tree.cpp.

263 {
264  if( aTreeId.IsOk() && !m_tree_ctrl->IsExpanded( aTreeId ) )
265  m_tree_ctrl->Expand( aTreeId );
266 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:173

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

194 {
195  expandIfValid( m_adapter->FindItem( aLibId ) );
196 }
void expandIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:262
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:170

References expandIfValid(), and m_adapter.

Referenced by LIB_EDIT_FRAME::KiwayMailIn().

◆ GetCurrentTreeNode()

LIB_TREE_NODE * LIB_TREE::GetCurrentTreeNode ( ) const

Definition at line 165 of file lib_tree.cpp.

166 {
167  auto sel = m_tree_ctrl->GetSelection();
168 
169  if( !sel )
170  return nullptr;
171 
172  return m_adapter->GetTreeNodeFor( sel );
173 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:173
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:170

References m_adapter, and m_tree_ctrl.

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

◆ GetSelectedLibId()

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

For multi-unit components, if the user selects the component 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 147 of file lib_tree.cpp.

148 {
149  auto sel = m_tree_ctrl->GetSelection();
150 
151  if( !sel )
152  {
153  LIB_ID emptyId;
154 
155  return emptyId;
156  }
157 
158  if( aUnit )
159  *aUnit = m_adapter->GetUnitFor( sel );
160 
161  return m_adapter->GetAliasFor( sel );
162 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:173
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:170

References m_adapter, and m_tree_ctrl.

Referenced by LIB_EDIT_FRAME::CopyPartToClipboard(), LIB_EDIT_FRAME::DuplicatePart(), DIALOG_CHOOSE_FOOTPRINT::GetSelectedLibId(), DIALOG_CHOOSE_COMPONENT::GetSelectedLibId(), getState(), FOOTPRINT_EDIT_FRAME::GetTreeFPID(), LIB_EDIT_FRAME::GetTreeLIBID(), DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected(), DIALOG_CHOOSE_COMPONENT::OnComponentPreselected(), DIALOG_CHOOSE_FOOTPRINT::OnComponentSelected(), DIALOG_CHOOSE_COMPONENT::OnComponentSelected(), onPreselect(), onQueryEnter(), onTreeActivate(), LIB_EDIT_FRAME::SyncLibraries(), and FOOTPRINT_EDIT_FRAME::SyncLibraryTree().

◆ getState()

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

Returns the component tree widget state.

Definition at line 283 of file lib_tree.cpp.

284 {
285  STATE state;
286  wxDataViewItemArray items;
287  m_adapter->GetChildren( wxDataViewItem( nullptr ), items );
288 
289  for( const auto& item : items )
290  {
291  if( m_tree_ctrl->IsExpanded( item ) )
292  state.expanded.push_back( item );
293  }
294 
295  state.selection = GetSelectedLibId();
296 
297  return state;
298 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:173
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit components, if the user selects the component itself rather than picking an individual...
Definition: lib_tree.cpp:147
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:170

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

421 {
422  TOOL_INTERACTIVE* tool = m_adapter->GetContextMenuTool();
423 
424  if( tool )
425  {
426  tool->Activate();
428  tool->GetToolMenu().ShowContextMenu();
429 
431  tool->GetManager()->DispatchContextMenu( evt );
432  }
433 }
void DispatchContextMenu(const TOOL_EVENT &aEvent)
Function DispatchContextMenu() Handles context menu related events.
TOOL_MENU & GetToolMenu()
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:142
TOOL_EVENT.
Definition: tool_event.h:171
void VetoContextMenuMouseWarp()
Disables mouse warping after the current context menu is closed.
Definition: tool_manager.h:414
void Activate()
Function Activate() Runs the tool.
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:170
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
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().

◆ onDetailsLink()

void LIB_TREE::onDetailsLink ( wxHtmlLinkEvent &  aEvent)
protected

Definition at line 396 of file lib_tree.cpp.

397 {
398  const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
399  ::wxLaunchDefaultBrowser( info.GetHref() );
400 }

Referenced by LIB_TREE().

◆ onPreselect()

void LIB_TREE::onPreselect ( wxCommandEvent &  aEvent)
protected

Definition at line 403 of file lib_tree.cpp.

404 {
405  if( m_details_ctrl )
406  {
407  int unit = 0;
408  LIB_ID id = GetSelectedLibId( &unit );
409 
410  if( id.IsValid() )
411  m_details_ctrl->SetPage( m_adapter->GenerateInfo( id, unit ) );
412  else
413  m_details_ctrl->SetPage( wxEmptyString );
414  }
415 
416  aEvent.Skip();
417 }
wxHtmlWindow * m_details_ctrl
Definition: lib_tree.h:174
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit components, if the user selects the component itself rather than picking an individual...
Definition: lib_tree.cpp:147
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:170

References GetSelectedLibId(), m_adapter, and m_details_ctrl.

Referenced by LIB_TREE().

◆ onQueryCharHook()

void LIB_TREE::onQueryCharHook ( wxKeyEvent &  aEvent)
protected

Definition at line 334 of file lib_tree.cpp.

335 {
336  auto const sel = m_tree_ctrl->GetSelection();
337  auto type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : LIB_TREE_NODE::INVALID;
338 
339  switch( aKeyStroke.GetKeyCode() )
340  {
341  case WXK_UP:
343  break;
344 
345  case WXK_DOWN:
347  break;
348 
349  case WXK_ADD:
350  if( type == LIB_TREE_NODE::LIB )
351  m_tree_ctrl->Expand( sel );
352 
353  break;
354 
355  case WXK_SUBTRACT:
356  if( type == LIB_TREE_NODE::LIB )
357  m_tree_ctrl->Collapse( sel );
358 
359  break;
360 
361  case WXK_RETURN:
362  if( type == LIB_TREE_NODE::LIB )
363  {
364  toggleExpand( sel );
365  break;
366  }
367  // Intentionally fall through, so the selected component will be treated as the selected one
368 
369  default:
370  aKeyStroke.Skip(); // Any other key: pass on to search box directly.
371  break;
372  }
373 }
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:244
void toggleExpand(const wxDataViewItem &aTreeId)
Expands or collapses a node, switching it to the opposite state.
Definition: lib_tree.cpp:232
wxDataViewItem GetPrevItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the previous item in list order.
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:173
wxDataViewItem GetNextItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the next item in list order.
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:170

References GetNextItem(), GetPrevItem(), LIB_TREE_NODE::INVALID, 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 327 of file lib_tree.cpp.

328 {
329  if( GetSelectedLibId().IsValid() )
330  postSelectEvent();
331 }
void postSelectEvent()
Post COMPONENT_SELECTED event to notify the selection handler that a part has been selected.
Definition: lib_tree.cpp:276
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit components, if the user selects the component itself rather than picking an individual...
Definition: lib_tree.cpp:147

References GetSelectedLibId(), and postSelectEvent().

Referenced by LIB_TREE().

◆ onQueryText()

void LIB_TREE::onQueryText ( wxCommandEvent &  aEvent)
protected

Definition at line 317 of file lib_tree.cpp.

318 {
319  Regenerate( false );
320 
321  // Required to avoid interaction with SetHint()
322  // See documentation for wxTextEntry::SetHint
323  aEvent.Skip();
324 }
void Regenerate(bool aKeepState)
Regenerates the tree.
Definition: lib_tree.cpp:199

References Regenerate().

Referenced by LIB_TREE().

◆ onTreeActivate()

void LIB_TREE::onTreeActivate ( wxDataViewEvent &  aEvent)
protected

Definition at line 382 of file lib_tree.cpp.

383 {
384  if( !GetSelectedLibId().IsValid() )
385  {
386  // Expand library/part units subtree
387  toggleExpand( m_tree_ctrl->GetSelection() );
388  }
389  else
390  {
391  postSelectEvent();
392  }
393 }
void toggleExpand(const wxDataViewItem &aTreeId)
Expands or collapses a node, switching it to the opposite state.
Definition: lib_tree.cpp:232
void postSelectEvent()
Post COMPONENT_SELECTED event to notify the selection handler that a part has been selected.
Definition: lib_tree.cpp:276
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:173
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit components, if the user selects the component itself rather than picking an individual...
Definition: lib_tree.cpp:147

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

Referenced by LIB_TREE().

◆ onTreeSelect()

void LIB_TREE::onTreeSelect ( wxDataViewEvent &  aEvent)
protected

Definition at line 376 of file lib_tree.cpp.

377 {
379 }
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:269

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

270 {
271  wxCommandEvent event( COMPONENT_PRESELECTED );
272  wxPostEvent( this, event );
273 }

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

◆ postSelectEvent()

void LIB_TREE::postSelectEvent ( )
protected

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

Definition at line 276 of file lib_tree.cpp.

277 {
278  wxCommandEvent event( COMPONENT_SELECTED );
279  wxPostEvent( this, event );
280 }

Referenced by onQueryEnter(), and onTreeActivate().

◆ RefreshLibTree()

void LIB_TREE::RefreshLibTree ( )

Refreshes the tree (mainly to update highlighting and asterisking)

Definition at line 217 of file lib_tree.cpp.

218 {
219  m_adapter->RefreshTree();
220 }
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:170

References m_adapter.

Referenced by LIB_EDIT_FRAME::DeletePartFromLibrary(), SYMBOL_TREE_PANE::onComponentSelected(), FOOTPRINT_EDIT_FRAME::OnModify(), LIB_EDIT_FRAME::OnModify(), LIB_EDIT_FRAME::Save(), LIB_EDIT_FRAME::SaveAll(), and LIB_EDIT_FRAME::SaveAs().

◆ Regenerate()

void LIB_TREE::Regenerate ( bool  aKeepState)

Regenerates the tree.

Definition at line 199 of file lib_tree.cpp.

200 {
201  STATE current;
202 
203  // Store the state
204  if( aKeepState )
205  current = getState();
206 
207  wxString filter = m_query_ctrl->GetValue();
208  m_adapter->UpdateSearchString( filter );
210 
211  // Restore the state
212  if( aKeepState )
213  setState( current );
214 }
STATE getState() const
Returns the component tree widget state.
Definition: lib_tree.cpp:283
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:269
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:170
void setState(const STATE &aState)
Restores the component tree widget state from an object.
Definition: lib_tree.cpp:301
wxTextCtrl * m_query_ctrl
Definition: lib_tree.h:172

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

Referenced by onQueryText(), FOOTPRINT_EDIT_FRAME::RegenerateLibraryTree(), LIB_EDIT_FRAME::RegenerateLibraryTree(), LIB_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 244 of file lib_tree.cpp.

245 {
246  if( aTreeId.IsOk() )
247  {
248  m_tree_ctrl->EnsureVisible( aTreeId );
249  m_tree_ctrl->Select( aTreeId );
251  }
252 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:173
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:269

References m_tree_ctrl, and postPreselectEvent().

Referenced by onQueryCharHook(), and SelectLibId().

◆ SelectLibId()

void LIB_TREE::SelectLibId ( const LIB_ID aLibId)

Select an item in the tree widget.

Definition at line 176 of file lib_tree.cpp.

177 {
178  selectIfValid( m_adapter->FindItem( aLibId ) );
179 }
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:244
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:170

References m_adapter, and selectIfValid().

Referenced by LIB_EDIT_FRAME::DuplicatePart(), FOOTPRINT_EDIT_FRAME::FocusOnLibID(), LIB_EDIT_FRAME::GetComponentFromRedoList(), LIB_EDIT_FRAME::GetComponentFromUndoList(), LIB_EDIT_FRAME::Revert(), LIB_EDIT_FRAME::savePartAs(), LIB_EDIT_FRAME::SetCurPart(), setState(), LIB_EDIT_FRAME::SyncLibraries(), FOOTPRINT_EDIT_FRAME::SyncLibraryTree(), and LIB_EDIT_FRAME::UpdateAfterSymbolProperties().

◆ SetFocus()

void LIB_TREE::SetFocus ( )
override

Definition at line 223 of file lib_tree.cpp.

224 {
225  if( m_query_ctrl )
226  m_query_ctrl->SetFocus();
227  else
228  m_tree_ctrl->SetFocus();
229 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:173
wxTextCtrl * m_query_ctrl
Definition: lib_tree.h:172

References m_query_ctrl, and m_tree_ctrl.

◆ setState()

void LIB_TREE::setState ( const STATE aState)
protected

Restores the component tree widget state from an object.

Definition at line 301 of file lib_tree.cpp.

302 {
303  m_tree_ctrl->Freeze();
304 
305  for( const auto& item : aState.expanded )
306  m_tree_ctrl->Expand( item );
307 
308  // wxDataViewCtrl cannot be frozen when a selection
309  // command is issued, otherwise it selects a random item (Windows)
310  m_tree_ctrl->Thaw();
311 
312  if( !aState.selection.GetLibItemName().empty() || !aState.selection.GetLibNickname().empty() )
313  SelectLibId( aState.selection );
314 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:173
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:176

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

Expands or collapses a node, switching it to the opposite state.

Definition at line 232 of file lib_tree.cpp.

233 {
234  if( !aTreeId.IsOk() )
235  return;
236 
237  if( m_tree_ctrl->IsExpanded( aTreeId ) )
238  m_tree_ctrl->Collapse( aTreeId );
239  else
240  m_tree_ctrl->Expand( aTreeId );
241 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:173

References m_tree_ctrl.

Referenced by onQueryCharHook(), and onTreeActivate().

◆ Unselect()

void LIB_TREE::Unselect ( )

Unselect currently selected item in wxDataViewCtrl.

Definition at line 188 of file lib_tree.cpp.

189 {
190  m_tree_ctrl->UnselectAll();
191 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:173

References m_tree_ctrl.

Referenced by LIB_EDIT_FRAME::emptyScreen(), FOOTPRINT_TREE_PANE::onComponentSelected(), SYMBOL_TREE_PANE::onComponentSelected(), FOOTPRINT_TREE_PANE::onUpdateUI(), LIB_EDIT_FRAME::SyncLibraries(), and FOOTPRINT_EDIT_FRAME::SyncLibraryTree().

Member Data Documentation

◆ m_adapter

◆ m_details_ctrl

wxHtmlWindow* LIB_TREE::m_details_ctrl
protected

Definition at line 174 of file lib_tree.h.

Referenced by LIB_TREE(), and onPreselect().

◆ m_lib_table

LIB_TABLE* LIB_TREE::m_lib_table
protected

Definition at line 169 of file lib_tree.h.

◆ m_query_ctrl

wxTextCtrl* LIB_TREE::m_query_ctrl
protected

Definition at line 172 of file lib_tree.h.

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

◆ m_tree_ctrl


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