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 (C) 2014-2023 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef LIB_TREE_H
26#define LIB_TREE_H
27
28#include <wx/panel.h>
29#include <wx/timer.h>
31#include <widgets/html_window.h>
33
34class wxTextCtrl;
35class wxHtmlLinkEvent;
36class wxSearchCtrl;
37class wxTimer;
38class wxTimerEvent;
39class wxPopupWindow;
41class ACTION_MENU;
42class LIB_ID;
43class LIB_TABLE;
44
48class LIB_TREE : public wxPanel
49{
50public:
52 enum FLAGS
53 {
54 NONE = 0x00,
55 SEARCH = 0x01,
56 FILTERS = 0x02,
57 DETAILS = 0x04,
59 MULTISELECT = 0x10
60 };
61
74 LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey, LIB_TABLE* aLibTable,
75 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter, int aFlags = ALL_WIDGETS,
76 HTML_WINDOW* aDetails = nullptr );
77
78 ~LIB_TREE() override;
79
89 LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
90
92 {
93 return m_tree_ctrl->GetSelectedItemsCount();
94 }
95
103 int GetSelectedLibIds( std::vector<LIB_ID>& aSelection,
104 std::vector<int>* aUnit = nullptr ) const;
105
107
111 void SelectLibId( const LIB_ID& aLibId );
112
116 void CenterLibId( const LIB_ID& aLibId );
117
121 void Unselect();
122
126 void ExpandLibId( const LIB_ID& aLibId );
127
128 void ExpandAll();
129 void CollapseAll();
130
134 void SetSearchString( const wxString& aSearchString );
135 wxString GetSearchString() const;
136
140 void SetSortMode( LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode ) { m_adapter->SetSortMode( aMode ); }
141 LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const { return m_adapter->GetSortMode(); }
142
146 void Regenerate( bool aKeepState );
147
151 void RefreshLibTree();
152
153 wxWindow* GetFocusTarget();
154
155 wxSizer* GetFiltersSizer() { return m_filtersSizer; }
156
161
162 void ShowChangedLanguage();
163
164protected:
168 void toggleExpand( const wxDataViewItem& aTreeId );
169
173 void selectIfValid( const wxDataViewItem& aTreeId );
174
175 void centerIfValid( const wxDataViewItem& aTreeId );
176
177 void expandIfValid( const wxDataViewItem& aTreeId );
178
183 void postPreselectEvent();
184
188 void postSelectEvent();
189
193 struct STATE
194 {
196 std::vector<wxDataViewItem> expanded;
197
200 };
201
205 STATE getState() const;
206
210 void setState( const STATE& aState );
211
213
214 void showPreview( wxDataViewItem aItem );
215 void hidePreview();
216 void destroyPreview();
217
218 void onQueryText( wxCommandEvent& aEvent );
219 void onQueryCharHook( wxKeyEvent& aEvent );
220 void onQueryMouseMoved( wxMouseEvent& aEvent );
221
222 void onTreeSelect( wxDataViewEvent& aEvent );
223 void onTreeActivate( wxDataViewEvent& aEvent );
224 void onTreeCharHook( wxKeyEvent& aEvent );
225
226 void onIdle( wxIdleEvent& aEvent );
227 void onHoverTimer( wxTimerEvent& aEvent );
228
229 void onDetailsLink( wxHtmlLinkEvent& aEvent );
230 void onPreselect( wxCommandEvent& aEvent );
231 void onItemContextMenu( wxDataViewEvent& aEvent );
232 void onHeaderContextMenu( wxDataViewEvent& aEvent );
233
234 void onDebounceTimer( wxTimerEvent& aEvent );
235
236protected:
237 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
238
239 wxSearchCtrl* m_query_ctrl;
245
247
248 wxBoxSizer* m_filtersSizer;
249
251
252 wxPoint m_hoverPos;
253 wxDataViewItem m_hoverItem;
256 wxDataViewItem m_previewItem;
258 wxPopupWindow* m_previewWindow;
260};
261
263wxDECLARE_EVENT( EVT_LIBITEM_SELECTED, wxCommandEvent );
264
266wxDECLARE_EVENT( EVT_LIBITEM_CHOSEN, wxCommandEvent );
267
268#endif /* LIB_TREE_H */
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
Add dark theme support to wxHtmlWindow.
Definition: html_window.h:34
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
Widget displaying a tree of symbols with optional search text control and description panel....
Definition: lib_tree.h:49
wxRect m_previewItemRect
Definition: lib_tree.h:257
void RefreshLibTree()
Refreshes the tree (mainly to update highlighting and asterisking)
Definition: lib_tree.cpp:438
wxPoint m_hoverPos
Definition: lib_tree.h:252
wxTimer * m_debounceTimer
Definition: lib_tree.h:243
void onHoverTimer(wxTimerEvent &aEvent)
Definition: lib_tree.cpp:819
LIB_TREE_NODE * GetCurrentTreeNode() const
Definition: lib_tree.cpp:332
void onQueryMouseMoved(wxMouseEvent &aEvent)
Definition: lib_tree.cpp:684
wxDataViewItem m_previewItem
Definition: lib_tree.h:256
HTML_WINDOW * m_details_ctrl
Definition: lib_tree.h:242
void onTreeActivate(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:885
wxString m_recentSearchesKey
Definition: lib_tree.h:246
void onQueryCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:605
void CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferably centered).
Definition: lib_tree.cpp:349
void postSelectEvent()
Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
Definition: lib_tree.cpp:546
wxWindow * GetFocusTarget()
Definition: lib_tree.cpp:444
int GetSelectionCount() const
Definition: lib_tree.h:91
void onItemContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:928
void destroyPreview()
Definition: lib_tree.cpp:740
void ShowChangedLanguage()
Definition: lib_tree.cpp:291
WX_DATAVIEWCTRL * m_tree_ctrl
Definition: lib_tree.h:241
void onQueryText(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:587
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition: lib_tree.cpp:460
wxSizer * GetFiltersSizer()
Definition: lib_tree.h:155
bool m_skipNextRightClick
Definition: lib_tree.h:250
bool m_inTimerEvent
Definition: lib_tree.h:244
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:472
void onIdle(wxIdleEvent &aEvent)
Definition: lib_tree.cpp:752
void FocusSearchFieldIfExists()
Focus the search widget if it exists.
Definition: lib_tree.cpp:453
void expandIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:532
void onPreselect(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:909
wxPopupWindow * m_previewWindow
Definition: lib_tree.h:258
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:343
void updateRecentSearchMenu()
Definition: lib_tree.cpp:391
void hidePreview()
Definition: lib_tree.cpp:729
LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const
Definition: lib_tree.h:141
void showPreview(wxDataViewItem aItem)
Definition: lib_tree.cpp:705
wxString GetSearchString() const
Definition: lib_tree.cpp:385
void onTreeSelect(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:873
int GetSelectedLibIds(std::vector< LIB_ID > &aSelection, std::vector< int > *aUnit=nullptr) const
Retrieves a list of selections for trees that allow multi-selection.
Definition: lib_tree.cpp:315
wxTimer m_hoverTimer
Definition: lib_tree.h:255
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:539
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:355
void onTreeCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:847
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition: lib_tree.cpp:899
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:301
FLAGS
< Flags to select extra widgets and options
Definition: lib_tree.h:53
@ NONE
Definition: lib_tree.h:54
@ MULTISELECT
Definition: lib_tree.h:59
@ FILTERS
Definition: lib_tree.h:56
@ DETAILS
Definition: lib_tree.h:57
@ ALL_WIDGETS
Definition: lib_tree.h:58
@ SEARCH
Definition: lib_tree.h:55
void ExpandAll()
Definition: lib_tree.cpp:367
wxBoxSizer * m_filtersSizer
Definition: lib_tree.h:248
wxDataViewItem m_hoverItem
Definition: lib_tree.h:253
~LIB_TREE() override
Definition: lib_tree.cpp:253
void SetSearchString(const wxString &aSearchString)
Save/restore search string.
Definition: lib_tree.cpp:379
void setState(const STATE &aState)
Restore the symbol tree widget state from an object.
Definition: lib_tree.cpp:571
STATE getState() const
Return the symbol tree widget state.
Definition: lib_tree.cpp:553
bool m_previewDisabled
Definition: lib_tree.h:259
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
Definition: lib_tree.cpp:361
wxSearchCtrl * m_query_ctrl
Definition: lib_tree.h:239
void CollapseAll()
Definition: lib_tree.cpp:373
void centerIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:484
void onDebounceTimer(wxTimerEvent &aEvent)
Definition: lib_tree.cpp:597
wxRect m_hoverItemRect
Definition: lib_tree.h:254
STD_BITMAP_BUTTON * m_sort_ctrl
Definition: lib_tree.h:240
void onHeaderContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:994
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition: lib_tree.cpp:420
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:237
void SetSortMode(LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode)
Save/restore the sorting mode.
Definition: lib_tree.h:140
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.
wxDECLARE_EVENT(EVT_LIBITEM_SELECTED, wxCommandEvent)
Custom event sent when an item is chosen (double-clicked)
Structure storing state of the symbol tree widget.
Definition: lib_tree.h:194
LIB_ID selection
Definition: lib_tree.h:199
std::vector< wxDataViewItem > expanded
< List of expanded nodes
Definition: lib_tree.h:196