KiCad PCB EDA Suite
Loading...
Searching...
No Matches
lib_tree.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2014 Henner Zeller <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef LIB_TREE_H
22#define LIB_TREE_H
23
24#include <wx/panel.h>
25#include <wx/sizer.h>
27#include <widgets/html_window.h>
30
31class wxTextCtrl;
32class wxHtmlLinkEvent;
33class wxSearchCtrl;
34class wxPopupWindow;
35class BITMAP_BUTTON;
37class ACTION_MENU;
38class LIB_ID;
39
43class LIB_TREE : public wxPanel
44{
45public:
47 enum FLAGS
48 {
49 FLAGS_NONE = 0x00,
50 SEARCH = 0x01,
51 FILTERS = 0x02,
52 DETAILS = 0x04,
55 };
56
68 LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey,
69 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter, int aFlags = ALL_WIDGETS,
70 HTML_WINDOW* aDetails = nullptr );
71
72 ~LIB_TREE() override;
73
83 LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
84
86 {
87 return m_tree_ctrl->GetSelectedItemsCount();
88 }
89
98 int GetSelectedLibIds( std::vector<LIB_ID>& aSelection,
99 std::vector<int>* aUnit = nullptr ) const;
100
107
114 int GetSelectedTreeNodes( std::vector<LIB_TREE_NODE*>& aSelection ) const;
115
119 void SelectLibId( const LIB_ID& aLibId );
120
124 void CenterLibId( const LIB_ID& aLibId );
125
129 void Unselect();
130
134 void ExpandLibId( const LIB_ID& aLibId );
135
136 std::vector<LIB_ID> GetExpandedLibraries() const;
137
138 void ExpandAll();
139 void CollapseAll();
140
144 void SetSearchString( const wxString& aSearchString );
145 wxString GetSearchString() const;
146
150 void SetSortMode( LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode ) { m_adapter->SetSortMode( aMode ); }
151 LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const { return m_adapter->GetSortMode(); }
152
156 void Regenerate( bool aKeepState );
157
161 void RefreshLibTree();
162
163 wxWindow* GetFocusTarget();
164
165 wxSizer* GetFiltersSizer() { return m_filtersSizer; }
166
171
172 void ShowChangedLanguage();
173
174 void BlockPreview( bool aBlock )
175 {
176 m_previewDisabled = aBlock;
177 }
178
179 void ShutdownPreviews();
180
181protected:
185 void toggleExpand( const wxDataViewItem& aTreeId );
186
190 void selectIfValid( const wxDataViewItem& aTreeId );
191
192 void centerIfValid( const wxDataViewItem& aTreeId );
193
194 void expandIfValid( const wxDataViewItem& aTreeId );
195
200 void postPreselectEvent();
201
205 void postSelectEvent();
206
210 struct STATE
211 {
213 std::vector<wxDataViewItem> expanded;
214
217
219 };
220
224 STATE getState() const;
225
227 bool isShown( const wxDataViewItem& aTreeId ) const;
228
232 void setState( const STATE& aState );
233
235
236 void showPreview( wxDataViewItem aItem );
237 void hidePreview();
238
239 void onQueryText( wxCommandEvent& aEvent );
240 void onQueryCharHook( wxKeyEvent& aEvent );
241 void onQueryMouseMoved( wxMouseEvent& aEvent );
242
243 void onTreeSelect( wxDataViewEvent& aEvent );
244 void onTreeActivate( wxDataViewEvent& aEvent );
245 void onTreeCharHook( wxKeyEvent& aEvent );
246
247 void onIdle( wxIdleEvent& aEvent );
248
249 void onDetailsLink( wxHtmlLinkEvent& aEvent );
250 void onPreselect( wxCommandEvent& aEvent );
251 void onItemContextMenu( wxDataViewEvent& aEvent );
252 void onHeaderContextMenu( wxDataViewEvent& aEvent );
253
255 void onQueryDebounce();
256
258 void onHoverPreview();
259
260protected:
261 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
262
263 wxSearchCtrl* m_query_ctrl;
268
270
271 wxBoxSizer* m_filtersSizer;
272
274
275 wxPoint m_hoverPos;
276 wxDataViewItem m_hoverItem;
278
281
284
285 wxDataViewItem m_previewItem;
287 wxPopupWindow* m_previewWindow;
289};
290
292wxDECLARE_EVENT( EVT_LIBITEM_SELECTED, wxCommandEvent );
293
295wxDECLARE_EVENT( EVT_LIBITEM_CHOSEN, wxCommandEvent );
296
297#endif /* LIB_TREE_H */
Define the structure of a menu based on ACTIONs.
Definition action_menu.h:43
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Add dark theme support to wxHtmlWindow.
Definition html_window.h:31
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
wxRect m_previewItemRect
Definition lib_tree.h:286
void onHoverPreview()
Show the hovered item's preview once the mouse stops moving.
Definition lib_tree.cpp:883
void RefreshLibTree()
Refresh the tree (mainly to update highlighting and asterisking)
Definition lib_tree.cpp:492
bool isShown(const wxDataViewItem &aTreeId) const
True when aTreeId has a row the filter shows.
Definition lib_tree.cpp:498
wxPoint m_hoverPos
Definition lib_tree.h:275
LIB_TREE_NODE * GetCurrentTreeNode() const
Retrieve the tree node for the first selected item.
Definition lib_tree.cpp:346
void onQueryMouseMoved(wxMouseEvent &aEvent)
Definition lib_tree.cpp:775
wxDataViewItem m_previewItem
Definition lib_tree.h:285
WX_DEBOUNCED_ACTION m_queryDebounce
Debounces the query typed in the search control.
Definition lib_tree.h:280
HTML_WINDOW * m_details_ctrl
Definition lib_tree.h:266
void onTreeActivate(wxDataViewEvent &aEvent)
Definition lib_tree.cpp:987
wxString m_recentSearchesKey
Definition lib_tree.h:269
LIB_TREE(wxWindow *aParent, const wxString &aRecentSearchesKey, wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > &aAdapter, int aFlags=ALL_WIDGETS, HTML_WINDOW *aDetails=nullptr)
Construct a symbol tree.
Definition lib_tree.cpp:50
void onQueryCharHook(wxKeyEvent &aEvent)
Definition lib_tree.cpp:674
void CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferably centered).
Definition lib_tree.cpp:382
void postSelectEvent()
Post EVT_LIBITEM_CHOSEN event to notify the selection handler that a part has been selected.
Definition lib_tree.cpp:607
wxWindow * GetFocusTarget()
Definition lib_tree.cpp:505
int GetSelectionCount() const
Definition lib_tree.h:85
void ShutdownPreviews()
Definition lib_tree.cpp:282
void onQueryDebounce()
Regenerate the tree from the search text once typing pauses.
Definition lib_tree.cpp:666
void onItemContextMenu(wxDataViewEvent &aEvent)
void ShowChangedLanguage()
Definition lib_tree.cpp:299
WX_DATAVIEWCTRL * m_tree_ctrl
Definition lib_tree.h:265
void onQueryText(wxCommandEvent &aEvent)
Definition lib_tree.cpp:656
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition lib_tree.cpp:521
int GetSelectedTreeNodes(std::vector< LIB_TREE_NODE * > &aSelection) const
Retrieve a list of pointers to selected tree nodes for trees that allow multi-selection.
Definition lib_tree.cpp:356
wxSizer * GetFiltersSizer()
Definition lib_tree.h:165
bool m_skipNextRightClick
Definition lib_tree.h:273
bool m_inTimerEvent
Definition lib_tree.h:267
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition lib_tree.cpp:533
void onIdle(wxIdleEvent &aEvent)
Definition lib_tree.cpp:828
void FocusSearchFieldIfExists()
Focus the search widget if it exists.
Definition lib_tree.cpp:514
std::vector< LIB_ID > GetExpandedLibraries() const
Definition lib_tree.cpp:402
void expandIfValid(const wxDataViewItem &aTreeId)
Definition lib_tree.cpp:593
void onPreselect(wxCommandEvent &aEvent)
wxPopupWindow * m_previewWindow
Definition lib_tree.h:287
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition lib_tree.cpp:370
void updateRecentSearchMenu()
Definition lib_tree.cpp:445
void hidePreview()
Definition lib_tree.cpp:819
LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const
Definition lib_tree.h:151
void showPreview(wxDataViewItem aItem)
Definition lib_tree.cpp:795
wxString GetSearchString() const
Definition lib_tree.cpp:439
void onTreeSelect(wxDataViewEvent &aEvent)
Definition lib_tree.cpp:975
int GetSelectedLibIds(std::vector< LIB_ID > &aSelection, std::vector< int > *aUnit=nullptr) const
Retrieve a list of selections for trees that allow multi-selection.
Definition lib_tree.cpp:329
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition lib_tree.cpp:600
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition lib_tree.cpp:388
BITMAP_BUTTON * m_sort_ctrl
Definition lib_tree.h:264
void onTreeCharHook(wxKeyEvent &aEvent)
Definition lib_tree.cpp:908
void onDetailsLink(wxHtmlLinkEvent &aEvent)
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:309
FLAGS
Flags to select extra widgets and options.
Definition lib_tree.h:48
@ MULTISELECT
Definition lib_tree.h:54
@ FILTERS
Definition lib_tree.h:51
@ DETAILS
Definition lib_tree.h:52
@ ALL_WIDGETS
Definition lib_tree.h:53
@ FLAGS_NONE
Definition lib_tree.h:49
void ExpandAll()
Definition lib_tree.cpp:421
wxBoxSizer * m_filtersSizer
Definition lib_tree.h:271
wxDataViewItem m_hoverItem
Definition lib_tree.h:276
~LIB_TREE() override
Definition lib_tree.cpp:252
void SetSearchString(const wxString &aSearchString)
Save/restore search string.
Definition lib_tree.cpp:433
void setState(const STATE &aState)
Restore the symbol tree widget state from an object.
Definition lib_tree.cpp:637
STATE getState() const
Return the symbol tree widget state.
Definition lib_tree.cpp:614
bool m_previewDisabled
Definition lib_tree.h:288
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
Definition lib_tree.cpp:396
void BlockPreview(bool aBlock)
Definition lib_tree.h:174
wxSearchCtrl * m_query_ctrl
Definition lib_tree.h:263
void CollapseAll()
Definition lib_tree.cpp:427
void centerIfValid(const wxDataViewItem &aTreeId)
Definition lib_tree.cpp:545
wxRect m_hoverItemRect
Definition lib_tree.h:277
WX_DEBOUNCED_ACTION m_hoverDebounce
Debounces the item preview shown on hover.
Definition lib_tree.h:283
void onHeaderContextMenu(wxDataViewEvent &aEvent)
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition lib_tree.cpp:474
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition lib_tree.h:261
void SetSortMode(LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode)
Save/restore the sorting mode.
Definition lib_tree.h:150
A bitmap button widget that behaves like a standard dialog button except with an icon.
Extension of the wxDataViewCtrl to include some helper functions for working with items.
Debounces an action: runs it only after a quiet period following the last trigger.
wxDECLARE_EVENT(EVT_LIBITEM_SELECTED, wxCommandEvent)
Custom event sent when an item is selected in the list.
Structure storing state of the symbol tree widget.
Definition lib_tree.h:211
LIB_ID selection
Current selection, might be not valid if nothing was selected.
Definition lib_tree.h:216
VECTOR2I scrollpos
Definition lib_tree.h:218
std::vector< wxDataViewItem > expanded
List of expanded nodes.
Definition lib_tree.h:213
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708