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, wxHtmlWindow *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)
 

Protected Attributes

LIB_TABLEm_lib_table
 
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTERm_adapter
 
wxTextCtrl * m_query_ctrl
 
wxDataViewCtrl * m_tree_ctrl
 
wxHtmlWindow * m_details_ctrl
 
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 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,
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > &  aAdapter,
WIDGETS  aWidgets = ALL,
wxHtmlWindow *  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 wxHtmlWindow to hold symbol details. If null this will be created inside the LIB_TREE.

Definition at line 37 of file lib_tree.cpp.

40  : wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
41  wxWANTS_CHARS | wxTAB_TRAVERSAL | wxNO_BORDER ),
42  m_lib_table( aLibTable ),
43  m_adapter( aAdapter ),
44  m_query_ctrl( nullptr ),
45  m_details_ctrl( nullptr )
46 {
47  auto sizer = new wxBoxSizer( wxVERTICAL );
48 
49  // Search text control
50  if( aWidgets & SEARCH )
51  {
52  auto search_sizer = new wxBoxSizer( wxHORIZONTAL );
53 
54  m_query_ctrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition,
55  wxDefaultSize, wxTE_PROCESS_ENTER );
56 
57 // Additional visual cue for GTK, which hides the placeholder text on focus
58 #ifdef __WXGTK__
59  auto bitmap = new wxStaticBitmap( this, wxID_ANY, wxArtProvider::GetBitmap( wxART_FIND, wxART_FRAME_ICON ) );
60 
61  search_sizer->Add( bitmap, 0, wxALIGN_CENTER | wxRIGHT, 5 );
62 #endif
63  search_sizer->Add( m_query_ctrl, 1, wxEXPAND, 5 );
64 
65  sizer->Add( search_sizer, 0, wxEXPAND, 5 );
66 
67  m_query_ctrl->Bind( wxEVT_TEXT, &LIB_TREE::onQueryText, this );
68  m_query_ctrl->Bind( wxEVT_TEXT_ENTER, &LIB_TREE::onQueryEnter, this );
69  m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &LIB_TREE::onQueryCharHook, this );
70  }
71 
72  // Tree control
73  m_tree_ctrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
74  wxDV_SINGLE );
75  m_adapter->AttachTo( m_tree_ctrl );
76 
77  if( aWidgets & DETAILS )
78  sizer->AddSpacer( 5 );
79 
80  sizer->Add( m_tree_ctrl, 5, wxRIGHT | wxBOTTOM | wxEXPAND, 1 );
81 
82  // Description panel
83  if( aWidgets & DETAILS )
84  {
85  if( !aDetails )
86  {
87  wxPoint html_size = ConvertDialogToPixels( wxPoint( 80, 80 ) );
88 
89  m_details_ctrl = new wxHtmlWindow( this, wxID_ANY, wxDefaultPosition,
90  wxSize( html_size.x, html_size.y ),
91  wxHW_SCROLLBAR_AUTO );
92 
93  sizer->Add( m_details_ctrl, 2, wxTOP | wxEXPAND, 5 );
94  }
95  else
96  {
97  m_details_ctrl = aDetails;
98  }
99 
100  m_details_ctrl->Bind( wxEVT_HTML_LINK_CLICKED, &LIB_TREE::onDetailsLink, this );
101  }
102 
103  SetSizer( sizer );
104 
105  m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &LIB_TREE::onTreeActivate, this );
106  m_tree_ctrl->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED, &LIB_TREE::onTreeSelect, this );
107  m_tree_ctrl->Bind( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &LIB_TREE::onContextMenu, this );
108 
109  Bind( SYMBOL_PRESELECTED, &LIB_TREE::onPreselect, this );
110 
111  // If wxTextCtrl::SetHint() is called before binding wxEVT_TEXT, the event
112  // handler will intermittently fire.
113  if( m_query_ctrl )
114  {
115  m_query_ctrl->SetHint( _( "Filter" ) );
116  m_query_ctrl->SetFocus();
117  m_query_ctrl->SetValue( wxEmptyString );
118 
119  // Force an update of the adapter with the empty text to ensure preselect is done
120  Regenerate( false );
121  }
122  else
123  {
124  // There may be a part preselected in the model. Make sure it is displayed.
125  // Regenerate does this in the other branch
127  }
128 
129  Layout();
130  sizer->Fit( this );
131 
132 #ifdef __WXGTK__
133  // Scrollbars must be always enabled to prevent an infinite event loop
134  // more details: http://trac.wxwidgets.org/ticket/18141
135  if( m_details_ctrl )
136  m_details_ctrl->ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
137 #endif /* __WXGTK__ */
138 }
void onQueryEnter(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:330
wxHtmlWindow * m_details_ctrl
Definition: lib_tree.h:176
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:172
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:175
void onPreselect(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:408
LIB_TABLE * m_lib_table
Definition: lib_tree.h:170
void onQueryCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:337
void onTreeActivate(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:387
void onQueryText(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:320
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition: lib_tree.cpp:202
void onTreeSelect(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:380
#define _(s)
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition: lib_tree.cpp:401
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:272
wxTextCtrl * m_query_ctrl
Definition: lib_tree.h:174
void onContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:435

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

◆ ~LIB_TREE()

LIB_TREE::~LIB_TREE ( )
override

Definition at line 141 of file lib_tree.cpp.

142 {
143  // Save the column widths to the config file
144  m_adapter->SaveColWidths();
145 
146  m_adapter->SavePinnedItems();
147 }
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:172

References m_adapter.

Member Function Documentation

◆ centerIfValid()

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

Definition at line 258 of file lib_tree.cpp.

259 {
260  if( aTreeId.IsOk() )
261  m_tree_ctrl->EnsureVisible( aTreeId );
262 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:175

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

186 {
187  centerIfValid( m_adapter->FindItem( aLibId ) );
188 }
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:172
void centerIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:258

References centerIfValid(), and m_adapter.

Referenced by 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 265 of file lib_tree.cpp.

266 {
267  if( aTreeId.IsOk() && !m_tree_ctrl->IsExpanded( aTreeId ) )
268  m_tree_ctrl->Expand( aTreeId );
269 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:175

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

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

References expandIfValid(), and m_adapter.

Referenced by SYMBOL_EDIT_FRAME::KiwayMailIn().

◆ GetCurrentTreeNode()

LIB_TREE_NODE * LIB_TREE::GetCurrentTreeNode ( ) const

Definition at line 168 of file lib_tree.cpp.

169 {
170  auto sel = m_tree_ctrl->GetSelection();
171 
172  if( !sel )
173  return nullptr;
174 
175  return m_adapter->GetTreeNodeFor( sel );
176 }
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:172
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:175

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

227 {
228  if( m_query_ctrl )
229  return m_query_ctrl;
230  else
231  return m_tree_ctrl;
232 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:175
wxTextCtrl * m_query_ctrl
Definition: lib_tree.h:174

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

151 {
152  auto sel = m_tree_ctrl->GetSelection();
153 
154  if( !sel )
155  {
156  LIB_ID emptyId;
157 
158  return emptyId;
159  }
160 
161  if( aUnit )
162  *aUnit = m_adapter->GetUnitFor( sel );
163 
164  return m_adapter->GetAliasFor( sel );
165 }
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:172
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:175
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 286 of file lib_tree.cpp.

287 {
288  STATE state;
289  wxDataViewItemArray items;
290  m_adapter->GetChildren( wxDataViewItem( nullptr ), items );
291 
292  for( const auto& item : items )
293  {
294  if( m_tree_ctrl->IsExpanded( item ) )
295  state.expanded.push_back( item );
296  }
297 
298  state.selection = GetSelectedLibId();
299 
300  return state;
301 }
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:172
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:175
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:150

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

436 {
437  TOOL_INTERACTIVE* tool = m_adapter->GetContextMenuTool();
438 
439  if( tool )
440  {
441  tool->Activate();
443  tool->GetToolMenu().ShowContextMenu();
444 
446  tool->GetManager()->DispatchContextMenu( evt );
447  }
448 }
void DispatchContextMenu(const TOOL_EVENT &aEvent)
Handle context menu related events.
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:172
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().

◆ onDetailsLink()

void LIB_TREE::onDetailsLink ( wxHtmlLinkEvent &  aEvent)
protected

Definition at line 401 of file lib_tree.cpp.

402 {
403  const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
404  ::wxLaunchDefaultBrowser( info.GetHref() );
405 }

References info.

Referenced by LIB_TREE().

◆ onPreselect()

void LIB_TREE::onPreselect ( wxCommandEvent &  aEvent)
protected

Definition at line 408 of file lib_tree.cpp.

409 {
410  if( m_details_ctrl )
411  {
412  int unit = 0;
413  LIB_ID id = GetSelectedLibId( &unit );
414 
415  wxString htmlColor = GetBackgroundColour().GetAsString( wxC2S_HTML_SYNTAX );
416  wxString textColor = GetForegroundColour().GetAsString( wxC2S_HTML_SYNTAX );
417  wxString linkColor = wxSystemSettings::GetColour( wxSYS_COLOUR_HOTLIGHT )
418  .GetAsString( wxC2S_HTML_SYNTAX );
419 
420  wxString html = wxString::Format( wxT( "<html><body bgcolor='%s' text='%s' link='%s'>" ),
421  htmlColor, textColor, linkColor );
422 
423  if( id.IsValid() )
424  html.Append( m_adapter->GenerateInfo( id, unit ) );
425 
426  html.Append( wxT( "</body></html>" ) );
427 
428  m_details_ctrl->SetPage( html );
429  }
430 
431  aEvent.Skip();
432 }
wxHtmlWindow * m_details_ctrl
Definition: lib_tree.h:176
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:172
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 symbols, if the user selects the symbol itself rather than picking an individual unit,...
Definition: lib_tree.cpp:150
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References Format(), GetSelectedLibId(), m_adapter, and m_details_ctrl.

Referenced by LIB_TREE().

◆ onQueryCharHook()

void LIB_TREE::onQueryCharHook ( wxKeyEvent &  aEvent)
protected

Definition at line 337 of file lib_tree.cpp.

338 {
339  auto const sel = m_tree_ctrl->GetSelection();
340  auto type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : LIB_TREE_NODE::INVALID;
341 
342  switch( aKeyStroke.GetKeyCode() )
343  {
344  case WXK_UP:
346  break;
347 
348  case WXK_DOWN:
350  break;
351 
352  case WXK_ADD:
353  if( type == LIB_TREE_NODE::LIB )
354  m_tree_ctrl->Expand( sel );
355 
356  break;
357 
358  case WXK_SUBTRACT:
359  if( type == LIB_TREE_NODE::LIB )
360  m_tree_ctrl->Collapse( sel );
361 
362  break;
363 
364  case WXK_RETURN:
365  if( type == LIB_TREE_NODE::LIB )
366  {
367  toggleExpand( sel );
368  break;
369  }
370  // Intentionally fall through, so the selected symbol will be treated as the selected one
372 
373  default:
374  aKeyStroke.Skip(); // Any other key: pass on to search box directly.
375  break;
376  }
377 }
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:247
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition: lib_tree.cpp:235
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:172
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:175
#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 330 of file lib_tree.cpp.

331 {
332  if( GetSelectedLibId().IsValid() )
333  postSelectEvent();
334 }
void postSelectEvent()
Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
Definition: lib_tree.cpp:279
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:150

References GetSelectedLibId(), and postSelectEvent().

Referenced by LIB_TREE().

◆ onQueryText()

void LIB_TREE::onQueryText ( wxCommandEvent &  aEvent)
protected

Definition at line 320 of file lib_tree.cpp.

321 {
322  Regenerate( false );
323 
324  // Required to avoid interaction with SetHint()
325  // See documentation for wxTextEntry::SetHint
326  aEvent.Skip();
327 }
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition: lib_tree.cpp:202

References Regenerate().

Referenced by LIB_TREE().

◆ onTreeActivate()

void LIB_TREE::onTreeActivate ( wxDataViewEvent &  aEvent)
protected

Definition at line 387 of file lib_tree.cpp.

388 {
389  if( !GetSelectedLibId().IsValid() )
390  {
391  // Expand library/part units subtree
392  toggleExpand( m_tree_ctrl->GetSelection() );
393  }
394  else
395  {
396  postSelectEvent();
397  }
398 }
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition: lib_tree.cpp:235
void postSelectEvent()
Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
Definition: lib_tree.cpp:279
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:175
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:150

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

Referenced by LIB_TREE().

◆ onTreeSelect()

void LIB_TREE::onTreeSelect ( wxDataViewEvent &  aEvent)
protected

Definition at line 380 of file lib_tree.cpp.

381 {
382  if( !m_tree_ctrl->IsFrozen() )
384 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:175
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:272

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

273 {
274  wxCommandEvent event( SYMBOL_PRESELECTED );
275  wxPostEvent( this, event );
276 }

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

280 {
281  wxCommandEvent event( SYMBOL_SELECTED );
282  wxPostEvent( this, event );
283 }

Referenced by onQueryEnter(), and onTreeActivate().

◆ RefreshLibTree()

void LIB_TREE::RefreshLibTree ( )

◆ Regenerate()

void LIB_TREE::Regenerate ( bool  aKeepState)

Regenerate the tree.

Definition at line 202 of file lib_tree.cpp.

203 {
204  STATE current;
205 
206  // Store the state
207  if( aKeepState )
208  current = getState();
209 
210  wxString filter = m_query_ctrl->GetValue();
211  m_adapter->UpdateSearchString( filter, aKeepState );
213 
214  // Restore the state
215  if( aKeepState )
216  setState( current );
217 }
STATE getState() const
Return the symbol tree widget state.
Definition: lib_tree.cpp:286
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:172
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:272
void setState(const STATE &aState)
Restore the symbol tree widget state from an object.
Definition: lib_tree.cpp:304
wxTextCtrl * m_query_ctrl
Definition: lib_tree.h:174

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

Referenced by LIB_TREE(), onQueryText(), 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 247 of file lib_tree.cpp.

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

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

180 {
181  selectIfValid( m_adapter->FindItem( aLibId ) );
182 }
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:247
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:172

References m_adapter, and selectIfValid().

Referenced by SYMBOL_EDIT_FRAME::DuplicateSymbol(), FOOTPRINT_EDIT_FRAME::FocusOnLibID(), SYMBOL_EDIT_FRAME::GetSymbolFromRedoList(), SYMBOL_EDIT_FRAME::GetSymbolFromUndoList(), SYMBOL_EDIT_FRAME::Revert(), SYMBOL_EDIT_FRAME::saveSymbolAs(), SYMBOL_EDIT_FRAME::SetCurSymbol(), setState(), SYMBOL_EDIT_FRAME::SyncLibraries(), FOOTPRINT_EDIT_FRAME::SyncLibraryTree(), and SYMBOL_EDIT_FRAME::UpdateAfterSymbolProperties().

◆ setState()

void LIB_TREE::setState ( const STATE aState)
protected

Restore the symbol tree widget state from an object.

Definition at line 304 of file lib_tree.cpp.

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

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

236 {
237  if( !aTreeId.IsOk() )
238  return;
239 
240  if( m_tree_ctrl->IsExpanded( aTreeId ) )
241  m_tree_ctrl->Collapse( aTreeId );
242  else
243  m_tree_ctrl->Expand( aTreeId );
244 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:175

References m_tree_ctrl.

Referenced by onQueryCharHook(), and onTreeActivate().

◆ Unselect()

void LIB_TREE::Unselect ( )

Member Data Documentation

◆ m_adapter

◆ m_details_ctrl

wxHtmlWindow* LIB_TREE::m_details_ctrl
protected

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

◆ m_lib_table

LIB_TABLE* LIB_TREE::m_lib_table
protected

Definition at line 170 of file lib_tree.h.

◆ m_query_ctrl

wxTextCtrl* LIB_TREE::m_query_ctrl
protected

Definition at line 174 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: