KiCad PCB EDA Suite
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-2022 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>
30#include <html_window.h>
31
32class wxDataViewCtrl;
33class wxTextCtrl;
34class wxHtmlLinkEvent;
35class wxSearchCtrl;
36class wxTimer;
37class wxTimerEvent;
38class ACTION_MENU;
39class LIB_ID;
40class LIB_TABLE;
41
45class LIB_TREE : public wxPanel
46{
47public:
49 enum FLAGS
50 {
51 NONE = 0x00,
52 SEARCH = 0x01,
53 DETAILS = 0x02,
55 MULTISELECT = 0x10
56 };
57
70 LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey, LIB_TABLE* aLibTable,
71 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter, int aFlags = ALL_WIDGETS,
72 HTML_WINDOW* aDetails = nullptr );
73
74 ~LIB_TREE() override;
75
85 LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
86
88 {
89 return m_tree_ctrl->GetSelectedItemsCount();
90 }
91
99 int GetSelectedLibIds( std::vector<LIB_ID>& aSelection,
100 std::vector<int>* aUnit = nullptr ) const;
101
103
107 void SelectLibId( const LIB_ID& aLibId );
108
112 void CenterLibId( const LIB_ID& aLibId );
113
117 void Unselect();
118
122 void ExpandLibId( const LIB_ID& aLibId );
123
127 void SetSearchString( const wxString& aSearchString );
128 wxString GetSearchString() const;
129
133 void Regenerate( bool aKeepState );
134
138 void RefreshLibTree();
139
140 wxWindow* GetFocusTarget();
141
146
147protected:
151 void toggleExpand( const wxDataViewItem& aTreeId );
152
156 void selectIfValid( const wxDataViewItem& aTreeId );
157
158 void centerIfValid( const wxDataViewItem& aTreeId );
159
160 void expandIfValid( const wxDataViewItem& aTreeId );
161
166 void postPreselectEvent();
167
171 void postSelectEvent();
172
176 struct STATE
177 {
179 std::vector<wxDataViewItem> expanded;
180 std::vector<wxString> pinned;
181
184 };
185
189 STATE getState() const;
190
194 void setState( const STATE& aState );
195
197
198 void onQueryText( wxCommandEvent& aEvent );
199 void onQueryCharHook( wxKeyEvent& aEvent );
200 void onQueryMouseMoved( wxMouseEvent& aEvent );
201
202 void onTreeSelect( wxDataViewEvent& aEvent );
203 void onTreeActivate( wxDataViewEvent& aEvent );
204 void onTreeCharHook( wxKeyEvent& aEvent );
205 void onSize( wxSizeEvent& aEvent );
206
207 void onDetailsLink( wxHtmlLinkEvent& aEvent );
208 void onPreselect( wxCommandEvent& aEvent );
209 void onItemContextMenu( wxDataViewEvent& aEvent );
210 void onHeaderContextMenu( wxDataViewEvent& aEvent );
211
212 void onDebounceTimer( wxTimerEvent& aEvent );
213
214protected:
216
217 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
218
219 wxSearchCtrl* m_query_ctrl;
220 wxDataViewCtrl* m_tree_ctrl;
224
227
229};
230
232wxDECLARE_EVENT( SYMBOL_PRESELECTED, wxCommandEvent );
233
235wxDECLARE_EVENT( SYMBOL_SELECTED, wxCommandEvent );
236
237#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:46
LIB_TREE(wxWindow *aParent, const wxString &aRecentSearchesKey, LIB_TABLE *aLibTable, wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > &aAdapter, int aFlags=ALL_WIDGETS, HTML_WINDOW *aDetails=nullptr)
Construct a symbol tree.
Definition: lib_tree.cpp:44
void RefreshLibTree()
Refreshes the tree (mainly to update highlighting and asterisking)
Definition: lib_tree.cpp:313
wxTimer * m_debounceTimer
Definition: lib_tree.h:222
LIB_TREE_NODE * GetCurrentTreeNode() const
Definition: lib_tree.cpp:219
void onQueryMouseMoved(wxMouseEvent &aEvent)
Definition: lib_tree.cpp:532
LIB_TABLE * m_lib_table
Definition: lib_tree.h:215
HTML_WINDOW * m_details_ctrl
Definition: lib_tree.h:221
void onTreeActivate(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:583
wxString m_recentSearchesKey
Definition: lib_tree.h:226
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:220
void onQueryCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:482
void CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferably centered).
Definition: lib_tree.cpp:236
void postSelectEvent()
Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
Definition: lib_tree.cpp:423
wxWindow * GetFocusTarget()
Definition: lib_tree.cpp:319
int GetSelectionCount() const
Definition: lib_tree.h:87
void onSize(wxSizeEvent &aEvent)
Definition: lib_tree.cpp:592
void onItemContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:622
void onQueryText(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:464
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition: lib_tree.cpp:337
bool m_skipNextRightClick
Definition: lib_tree.h:228
bool m_inTimerEvent
Definition: lib_tree.h:223
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:349
void FocusSearchFieldIfExists()
Focus the search widget if it exists.
Definition: lib_tree.cpp:328
void expandIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:409
void onPreselect(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:605
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:230
void updateRecentSearchMenu()
Definition: lib_tree.cpp:266
wxString GetSearchString() const
Definition: lib_tree.cpp:260
void onTreeSelect(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:573
LIB_ID m_last_libid
Definition: lib_tree.h:225
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:202
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:416
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:242
void onTreeCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:547
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition: lib_tree.cpp:598
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:188
FLAGS
< Flags to select extra widgets and options
Definition: lib_tree.h:50
@ NONE
Definition: lib_tree.h:51
@ MULTISELECT
Definition: lib_tree.h:55
@ DETAILS
Definition: lib_tree.h:53
@ ALL_WIDGETS
Definition: lib_tree.h:54
@ SEARCH
Definition: lib_tree.h:52
~LIB_TREE() override
Definition: lib_tree.cpp:181
void SetSearchString(const wxString &aSearchString)
Save/restore search string.
Definition: lib_tree.cpp:254
void setState(const STATE &aState)
Restore the symbol tree widget state from an object.
Definition: lib_tree.cpp:448
STATE getState() const
Return the symbol tree widget state.
Definition: lib_tree.cpp:430
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
Definition: lib_tree.cpp:248
wxSearchCtrl * m_query_ctrl
Definition: lib_tree.h:219
void centerIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:361
void onDebounceTimer(wxTimerEvent &aEvent)
Definition: lib_tree.cpp:474
void onHeaderContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:692
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition: lib_tree.cpp:295
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:217
wxDECLARE_EVENT(SYMBOL_PRESELECTED, wxCommandEvent)
Custom event sent when a symbol is selected.
Structure storing state of the symbol tree widget.
Definition: lib_tree.h:177
LIB_ID selection
Definition: lib_tree.h:183
std::vector< wxString > pinned
Current selection, might be not valid if nothing was selected.
Definition: lib_tree.h:180
std::vector< wxDataViewItem > expanded
< List of expanded nodes
Definition: lib_tree.h:179