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_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...
 
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 SetMenu (LIB_TREE_NODE::TYPE aType, std::unique_ptr< wxMenu > aMenu)
 Associates a right click context menu for a specific node type. More...
 
bool IsMenuActive () const
 Returns the status of right-click context menu. More...
 
void Regenerate ()
 Regenerates the tree. 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 onUpdateUI (wxUpdateUIEvent &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
 
std::vector< std::unique_ptr< wxMenu > > m_menus
 

Right click context menus for each tree level

More...
 
bool m_menuActive
 

Flag indicating whether a right-click context menu is active

More...
 
bool m_filtering
 

Flag indicating whether the results are filtered using the search query

More...
 
STATE m_unfilteredState
 

State of the widget before any filters applied

More...
 

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

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

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

38  : wxPanel( aParent ),
39  m_lib_table( aLibTable ),
40  m_adapter( aAdapter ),
41  m_query_ctrl( nullptr ),
42  m_details_ctrl( nullptr ),
43  m_menuActive( false ),
44  m_filtering( false )
45 {
46  // create space for context menu pointers, INVALID is the max value
48 
49  auto sizer = new wxBoxSizer( wxVERTICAL );
50 
51  // Search text control
52  if( aWidgets & SEARCH )
53  {
54  auto search_sizer = new wxBoxSizer( wxHORIZONTAL );
55 
56  m_query_ctrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition,
57  wxDefaultSize, wxTE_PROCESS_ENTER );
58 
59 // Additional visual cue for GTK, which hides the placeholder text on focus
60 #ifdef __WXGTK__
61  auto bitmap = new wxStaticBitmap( this, wxID_ANY, wxArtProvider::GetBitmap( wxART_FIND, wxART_FRAME_ICON ) );
62 
63  if( aWidgets & DETAILS )
64  search_sizer->Add( bitmap, 0, wxALIGN_CENTER | wxALL, 5 );
65  else
66  search_sizer->Add( bitmap, 0, wxALIGN_CENTER | wxRIGHT, 5 );
67 #endif
68 
69  if( aWidgets & DETAILS )
70  search_sizer->Add( m_query_ctrl, 1, wxLEFT | wxTOP | wxRIGHT | wxEXPAND, 5 );
71  else
72  search_sizer->Add( m_query_ctrl, 1, wxEXPAND, 5 );
73  sizer->Add( search_sizer, 0, wxEXPAND, 5 );
74 
75  m_query_ctrl->Bind( wxEVT_TEXT, &LIB_TREE::onQueryText, this );
76  m_query_ctrl->Bind( wxEVT_TEXT_ENTER, &LIB_TREE::onQueryEnter, this );
77  m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &LIB_TREE::onQueryCharHook, this );
78  }
79 
80  // Tree control
81  m_tree_ctrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
82  wxDV_SINGLE | wxDV_NO_HEADER );
83  m_adapter->AttachTo( m_tree_ctrl );
84 
85  if( aWidgets & DETAILS )
86  sizer->Add( m_tree_ctrl, 5, wxLEFT | wxTOP | wxRIGHT | wxEXPAND, 5 );
87  else
88  sizer->Add( m_tree_ctrl, 5, wxRIGHT | wxBOTTOM | wxEXPAND, 1 );
89 
90  // Description panel
91  if( aWidgets & DETAILS )
92  {
93  if( !aDetails )
94  {
95  auto html_sz = ConvertDialogToPixels( wxPoint( 80, 80 ) );
96 
97  m_details_ctrl = new wxHtmlWindow(
98  this, wxID_ANY, wxDefaultPosition, wxSize( html_sz.x, html_sz.y ),
99  wxHW_SCROLLBAR_AUTO );
100 
101  sizer->Add( m_details_ctrl, 2, wxALL | wxEXPAND, 5 );
102  }
103  else
104  {
105  m_details_ctrl = aDetails;
106  }
107 
108  m_details_ctrl->Bind( wxEVT_HTML_LINK_CLICKED, &LIB_TREE::onDetailsLink, this );
109  }
110 
111  SetSizer( sizer );
112 
113  m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &LIB_TREE::onTreeActivate, this );
114  m_tree_ctrl->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED, &LIB_TREE::onTreeSelect, this );
115  m_tree_ctrl->Bind( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &LIB_TREE::onContextMenu, this );
116 
117  Bind( COMPONENT_PRESELECTED, &LIB_TREE::onPreselect, this );
118 
119  // If wxTextCtrl::SetHint() is called before binding wxEVT_TEXT, the event
120  // handler will intermittently fire.
121  if( m_query_ctrl )
122  {
123  m_query_ctrl->SetHint( _( "Filter" ) );
124  m_query_ctrl->SetFocus();
125  m_query_ctrl->SetValue( wxEmptyString ); // SetValue() is required here to kick off
126  // initial sorting and pre-selection.
127  }
128 
129  // There may be a part preselected in the model. Make sure it is displayed.
131 
132  Layout();
133  sizer->Fit( this );
134 
135 #ifdef __WXGTK__
136  // Scrollbars must be always enabled to prevent an infinite event loop
137  // more details: http://trac.wxwidgets.org/ticket/18141
138  if( m_details_ctrl )
139  m_details_ctrl->ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
140 #endif /* __WXGTK__ */
141 }
std::vector< std::unique_ptr< wxMenu > > m_menus
Right click context menus for each tree level
Definition: lib_tree.h:186
void onQueryEnter(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:308
wxHtmlWindow * m_details_ctrl
Definition: lib_tree.h:183
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:182
bool m_filtering
Flag indicating whether the results are filtered using the search query
Definition: lib_tree.h:192
void onPreselect(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:372
LIB_TABLE * m_lib_table
Definition: lib_tree.h:178
void onQueryCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:315
bool m_menuActive
Flag indicating whether a right-click context menu is active
Definition: lib_tree.h:189
void onTreeActivate(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:351
void onQueryText(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:298
void onTreeSelect(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:345
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition: lib_tree.cpp:365
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:250
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:179
BITMAP_DEF GetBitmap(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:70
wxTextCtrl * m_query_ctrl
Definition: lib_tree.h:181
void onContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:389

Member Function Documentation

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

Definition at line 236 of file lib_tree.cpp.

References m_tree_ctrl.

Referenced by CenterLibId(), and IsMenuActive().

237 {
238  if( aTreeId.IsOk() )
239  m_tree_ctrl->EnsureVisible( aTreeId );
240 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:182
void LIB_TREE::CenterLibId ( const LIB_ID aLibId)

Ensure that an item is visible (preferrably centered).

Definition at line 168 of file lib_tree.cpp.

References centerIfValid(), and m_adapter.

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

169 {
170  centerIfValid( m_adapter->FindItem( aLibId ) );
171 }
void centerIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:236
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:179
void LIB_TREE::expandIfValid ( const wxDataViewItem &  aTreeId)
protected

Definition at line 243 of file lib_tree.cpp.

References m_tree_ctrl.

Referenced by ExpandLibId(), and IsMenuActive().

244 {
245  if( aTreeId.IsOk() && !m_tree_ctrl->IsExpanded( aTreeId ) )
246  m_tree_ctrl->Expand( aTreeId );
247 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:182
void LIB_TREE::ExpandLibId ( const LIB_ID aLibId)

Expand and item i the tree widget.

Definition at line 179 of file lib_tree.cpp.

References expandIfValid(), and m_adapter.

Referenced by LIB_EDIT_FRAME::KiwayMailIn().

180 {
181  expandIfValid( m_adapter->FindItem( aLibId ) );
182 }
void expandIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:243
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:179
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 144 of file lib_tree.cpp.

References m_adapter, and m_tree_ctrl.

Referenced by DIALOG_CHOOSE_FOOTPRINT::GetSelectedLibId(), DIALOG_CHOOSE_COMPONENT::GetSelectedLibId(), getState(), FOOTPRINT_EDIT_FRAME::getTargetFPID(), LIB_EDIT_FRAME::getTargetLibId(), LIB_EDIT_FRAME::getTargetPart(), DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected(), DIALOG_CHOOSE_COMPONENT::OnComponentPreselected(), DIALOG_CHOOSE_FOOTPRINT::OnComponentSelected(), DIALOG_CHOOSE_COMPONENT::OnComponentSelected(), LIB_EDIT_FRAME::OnCopyCutPart(), LIB_EDIT_FRAME::OnEditPart(), LIB_EDIT_FRAME::OnPasteDuplicatePart(), onPreselect(), onQueryEnter(), onTreeActivate(), LIB_EDIT_FRAME::SyncLibraries(), and FOOTPRINT_EDIT_FRAME::SyncLibraryTree().

145 {
146  auto sel = m_tree_ctrl->GetSelection();
147 
148  if( !sel )
149  {
150  LIB_ID emptyId;
151 
152  return emptyId;
153  }
154 
155  if( aUnit )
156  *aUnit = m_adapter->GetUnitFor( sel );
157 
158  return m_adapter->GetAliasFor( sel );
159 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:182
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:179
LIB_TREE::STATE LIB_TREE::getState ( ) const
protected

Returns the component tree widget state.

Definition at line 264 of file lib_tree.cpp.

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

Referenced by Regenerate().

265 {
266  STATE state;
267  wxDataViewItemArray items;
268  m_adapter->GetChildren( wxDataViewItem( nullptr ), items );
269 
270  for( const auto& item : items )
271  {
272  if( m_tree_ctrl->IsExpanded( item ) )
273  state.expanded.push_back( item );
274  }
275 
276  state.selection = GetSelectedLibId();
277 
278  return state;
279 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:182
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:144
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:179
bool LIB_TREE::IsMenuActive ( ) const
inline

Returns the status of right-click context menu.

Returns
True in case a right-click context menu is active.

Definition at line 106 of file lib_tree.h.

References centerIfValid(), expandIfValid(), m_menuActive, postPreselectEvent(), postSelectEvent(), Regenerate(), selectIfValid(), SetFocus(), and toggleExpand().

Referenced by LIB_EDIT_FRAME::getTargetPart().

107  {
108  return m_menuActive;
109  }
bool m_menuActive
Flag indicating whether a right-click context menu is active
Definition: lib_tree.h:189
void LIB_TREE::onContextMenu ( wxDataViewEvent &  aEvent)
protected

Definition at line 389 of file lib_tree.cpp.

References LIB_TREE_NODE::INVALID, m_adapter, m_menuActive, m_menus, m_tree_ctrl, and wxDEFINE_EVENT().

Referenced by LIB_TREE().

390 {
391  auto const sel = m_tree_ctrl->GetSelection();
392  auto type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : LIB_TREE_NODE::INVALID;
393 
394  if( m_menus[type] )
395  {
396  m_menuActive = true;
397  PopupMenu( m_menus[type].get() );
398  m_menuActive = false;
399  }
400 }
std::vector< std::unique_ptr< wxMenu > > m_menus
Right click context menus for each tree level
Definition: lib_tree.h:186
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:182
bool m_menuActive
Flag indicating whether a right-click context menu is active
Definition: lib_tree.h:189
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:179
void LIB_TREE::onDetailsLink ( wxHtmlLinkEvent &  aEvent)
protected

Definition at line 365 of file lib_tree.cpp.

Referenced by LIB_TREE().

366 {
367  const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
368  ::wxLaunchDefaultBrowser( info.GetHref() );
369 }
void LIB_TREE::onPreselect ( wxCommandEvent &  aEvent)
protected

Definition at line 372 of file lib_tree.cpp.

References GetSelectedLibId(), m_adapter, and m_details_ctrl.

Referenced by LIB_TREE().

373 {
374  if( m_details_ctrl )
375  {
376  int unit = 0;
377  LIB_ID id = GetSelectedLibId( &unit );
378 
379  if( id.IsValid() )
380  m_details_ctrl->SetPage( m_adapter->GenerateInfo( id, unit ) );
381  else
382  m_details_ctrl->SetPage( wxEmptyString );
383  }
384 
385  aEvent.Skip();
386 }
wxHtmlWindow * m_details_ctrl
Definition: lib_tree.h:183
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:144
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:179
void LIB_TREE::onQueryCharHook ( wxKeyEvent &  aEvent)
protected

Definition at line 315 of file lib_tree.cpp.

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

Referenced by LIB_TREE().

316 {
317  auto const sel = m_tree_ctrl->GetSelection();
318  auto type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : LIB_TREE_NODE::INVALID;
319 
320  switch( aKeyStroke.GetKeyCode() )
321  {
322  case WXK_UP:
324  break;
325 
326  case WXK_DOWN:
328  break;
329 
330  case WXK_RETURN:
331  if( type == LIB_TREE_NODE::LIB )
332  {
333  toggleExpand( sel );
334  break;
335  }
336  /* fall through, so the selected component will be treated as the selected one */
337 
338  default:
339  aKeyStroke.Skip(); // Any other key: pass on to search box directly.
340  break;
341  }
342 }
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:225
void toggleExpand(const wxDataViewItem &aTreeId)
Expands or collapses a node, switching it to the opposite state.
Definition: lib_tree.cpp:213
wxDataViewItem GetPrevItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the previous item in list order.
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:182
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:179
void LIB_TREE::onQueryEnter ( wxCommandEvent &  aEvent)
protected

Definition at line 308 of file lib_tree.cpp.

References GetSelectedLibId(), and postSelectEvent().

Referenced by LIB_TREE().

309 {
310  if( GetSelectedLibId().IsValid() )
311  postSelectEvent();
312 }
void postSelectEvent()
Post COMPONENT_SELECTED event to notify the selection handler that a part has been selected...
Definition: lib_tree.cpp:257
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:144
void LIB_TREE::onQueryText ( wxCommandEvent &  aEvent)
protected

Definition at line 298 of file lib_tree.cpp.

References Regenerate().

Referenced by LIB_TREE().

299 {
300  Regenerate();
301 
302  // Required to avoid interaction with SetHint()
303  // See documentation for wxTextEntry::SetHint
304  aEvent.Skip();
305 }
void Regenerate()
Regenerates the tree.
Definition: lib_tree.cpp:185
void LIB_TREE::onTreeActivate ( wxDataViewEvent &  aEvent)
protected

Definition at line 351 of file lib_tree.cpp.

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

Referenced by LIB_TREE().

352 {
353  if( !GetSelectedLibId().IsValid() )
354  {
355  // Expand library/part units subtree
356  toggleExpand( m_tree_ctrl->GetSelection() );
357  }
358  else
359  {
360  postSelectEvent();
361  }
362 }
void toggleExpand(const wxDataViewItem &aTreeId)
Expands or collapses a node, switching it to the opposite state.
Definition: lib_tree.cpp:213
void postSelectEvent()
Post COMPONENT_SELECTED event to notify the selection handler that a part has been selected...
Definition: lib_tree.cpp:257
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:182
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:144
void LIB_TREE::onTreeSelect ( wxDataViewEvent &  aEvent)
protected

Definition at line 345 of file lib_tree.cpp.

References postPreselectEvent().

Referenced by LIB_TREE().

346 {
348 }
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:250
void LIB_TREE::onUpdateUI ( wxUpdateUIEvent &  aEvent)
protected
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 250 of file lib_tree.cpp.

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

251 {
252  wxCommandEvent event( COMPONENT_PRESELECTED );
253  wxPostEvent( this, event );
254 }
void LIB_TREE::postSelectEvent ( )
protected

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

Definition at line 257 of file lib_tree.cpp.

Referenced by IsMenuActive(), onQueryEnter(), and onTreeActivate().

258 {
259  wxCommandEvent event( COMPONENT_SELECTED );
260  wxPostEvent( this, event );
261 }
void LIB_TREE::Regenerate ( )

Regenerates the tree.

Definition at line 185 of file lib_tree.cpp.

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

Referenced by IsMenuActive(), onQueryText(), FOOTPRINT_TREE_PANE::Regenerate(), and SYMBOL_TREE_PANE::Regenerate().

186 {
187  STATE current;
188 
189  // Store the state
190  if( !m_filtering )
192 
193  wxString filter = m_query_ctrl->GetValue();
194  m_adapter->UpdateSearchString( filter );
195  m_filtering = !filter.IsEmpty();
197 
198  // Restore the state
199  if( !m_filtering )
201 }
STATE getState() const
Returns the component tree widget state.
Definition: lib_tree.cpp:264
bool m_filtering
Flag indicating whether the results are filtered using the search query
Definition: lib_tree.h:192
STATE m_unfilteredState
State of the widget before any filters applied
Definition: lib_tree.h:195
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:250
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:179
void setState(const STATE &aState)
Restores the component tree widget state from an object.
Definition: lib_tree.cpp:282
wxTextCtrl * m_query_ctrl
Definition: lib_tree.h:181
void LIB_TREE::selectIfValid ( const wxDataViewItem &  aTreeId)
protected

If a wxDataViewitem is valid, select it and post a selection event.

Definition at line 225 of file lib_tree.cpp.

References m_tree_ctrl, and postPreselectEvent().

Referenced by IsMenuActive(), onQueryCharHook(), and SelectLibId().

226 {
227  if( aTreeId.IsOk() )
228  {
229  m_tree_ctrl->EnsureVisible( aTreeId );
230  m_tree_ctrl->Select( aTreeId );
232  }
233 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:182
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:250
void LIB_TREE::SelectLibId ( const LIB_ID aLibId)

Select an item in the tree widget.

Definition at line 162 of file lib_tree.cpp.

References m_adapter, and selectIfValid().

Referenced by LIB_EDIT_FRAME::EditField(), LIB_EDIT_FRAME::GetComponentFromRedoList(), LIB_EDIT_FRAME::GetComponentFromUndoList(), LIB_EDIT_FRAME::OnPasteDuplicatePart(), LIB_EDIT_FRAME::OnRevert(), LIB_EDIT_FRAME::savePartAs(), LIB_EDIT_FRAME::SetCurPart(), setState(), LIB_EDIT_FRAME::SyncLibraries(), and FOOTPRINT_EDIT_FRAME::SyncLibraryTree().

163 {
164  selectIfValid( m_adapter->FindItem( aLibId ) );
165 }
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:225
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
Definition: lib_tree.h:179
void LIB_TREE::SetFocus ( )
override

Definition at line 204 of file lib_tree.cpp.

References m_query_ctrl, and m_tree_ctrl.

Referenced by IsMenuActive().

205 {
206  if( m_query_ctrl )
207  m_query_ctrl->SetFocus();
208  else
209  m_tree_ctrl->SetFocus();
210 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:182
wxTextCtrl * m_query_ctrl
Definition: lib_tree.h:181
void LIB_TREE::SetMenu ( LIB_TREE_NODE::TYPE  aType,
std::unique_ptr< wxMenu >  aMenu 
)
inline

Associates a right click context menu for a specific node type.

Parameters
aTypeis the node type to have a menu associated.
aMenuis the associated menu.

Definition at line 97 of file lib_tree.h.

References m_menus.

Referenced by FOOTPRINT_TREE_PANE::FOOTPRINT_TREE_PANE(), and SYMBOL_TREE_PANE::SYMBOL_TREE_PANE().

98  {
99  m_menus[aType] = std::move( aMenu );
100  }
std::vector< std::unique_ptr< wxMenu > > m_menus
Right click context menus for each tree level
Definition: lib_tree.h:186
void LIB_TREE::setState ( const STATE aState)
protected

Restores the component tree widget state from an object.

Definition at line 282 of file lib_tree.cpp.

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().

283 {
284  m_tree_ctrl->Freeze();
285 
286  for( const auto& item : aState.expanded )
287  m_tree_ctrl->Expand( item );
288 
289  // wxDataViewCtrl cannot be frozen when a selection
290  // command is issued, otherwise it selects a random item (Windows)
291  m_tree_ctrl->Thaw();
292 
293  if( !aState.selection.GetLibItemName().empty() || !aState.selection.GetLibNickname().empty() )
294  SelectLibId( aState.selection );
295 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:182
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:162
void LIB_TREE::toggleExpand ( const wxDataViewItem &  aTreeId)
protected

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

Definition at line 213 of file lib_tree.cpp.

References m_tree_ctrl.

Referenced by IsMenuActive(), onQueryCharHook(), and onTreeActivate().

214 {
215  if( !aTreeId.IsOk() )
216  return;
217 
218  if( m_tree_ctrl->IsExpanded( aTreeId ) )
219  m_tree_ctrl->Collapse( aTreeId );
220  else
221  m_tree_ctrl->Expand( aTreeId );
222 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:182
void LIB_TREE::Unselect ( )

Unselect currently selected item in wxDataViewCtrl.

Definition at line 174 of file lib_tree.cpp.

References m_tree_ctrl.

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

175 {
176  m_tree_ctrl->UnselectAll();
177 }
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:182

Member Data Documentation

wxHtmlWindow* LIB_TREE::m_details_ctrl
protected

Definition at line 183 of file lib_tree.h.

Referenced by LIB_TREE(), and onPreselect().

bool LIB_TREE::m_filtering
protected

Flag indicating whether the results are filtered using the search query

Definition at line 192 of file lib_tree.h.

Referenced by Regenerate().

LIB_TABLE* LIB_TREE::m_lib_table
protected

Definition at line 178 of file lib_tree.h.

bool LIB_TREE::m_menuActive
protected

Flag indicating whether a right-click context menu is active

Definition at line 189 of file lib_tree.h.

Referenced by IsMenuActive(), and onContextMenu().

std::vector<std::unique_ptr<wxMenu> > LIB_TREE::m_menus
protected

Right click context menus for each tree level

Definition at line 186 of file lib_tree.h.

Referenced by LIB_TREE(), onContextMenu(), and SetMenu().

wxTextCtrl* LIB_TREE::m_query_ctrl
protected

Definition at line 181 of file lib_tree.h.

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

STATE LIB_TREE::m_unfilteredState
protected

State of the widget before any filters applied

Definition at line 195 of file lib_tree.h.

Referenced by Regenerate().


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