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, 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 FLAGS_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
104 int GetSelectedLibIds( std::vector<LIB_ID>& aSelection,
105 std::vector<int>* aUnit = nullptr ) const;
106
108
112 void SelectLibId( const LIB_ID& aLibId );
113
117 void CenterLibId( const LIB_ID& aLibId );
118
122 void Unselect();
123
127 void ExpandLibId( const LIB_ID& aLibId );
128
129 void ExpandAll();
130 void CollapseAll();
131
135 void SetSearchString( const wxString& aSearchString );
136 wxString GetSearchString() const;
137
141 void SetSortMode( LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode ) { m_adapter->SetSortMode( aMode ); }
142 LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const { return m_adapter->GetSortMode(); }
143
147 void Regenerate( bool aKeepState );
148
152 void RefreshLibTree();
153
154 wxWindow* GetFocusTarget();
155
156 wxSizer* GetFiltersSizer() { return m_filtersSizer; }
157
162
163 void ShowChangedLanguage();
164
165 void BlockPreview( bool aBlock )
166 {
167 m_previewDisabled = aBlock;
168 }
169
170protected:
174 void toggleExpand( const wxDataViewItem& aTreeId );
175
179 void selectIfValid( const wxDataViewItem& aTreeId );
180
181 void centerIfValid( const wxDataViewItem& aTreeId );
182
183 void expandIfValid( const wxDataViewItem& aTreeId );
184
189 void postPreselectEvent();
190
194 void postSelectEvent();
195
199 struct STATE
200 {
202 std::vector<wxDataViewItem> expanded;
203
206 };
207
211 STATE getState() const;
212
216 void setState( const STATE& aState );
217
219
220 void showPreview( wxDataViewItem aItem );
221 void hidePreview();
222 void destroyPreview();
223
224 void onQueryText( wxCommandEvent& aEvent );
225 void onQueryCharHook( wxKeyEvent& aEvent );
226 void onQueryMouseMoved( wxMouseEvent& aEvent );
227
228 void onTreeSelect( wxDataViewEvent& aEvent );
229 void onTreeActivate( wxDataViewEvent& aEvent );
230 void onTreeCharHook( wxKeyEvent& aEvent );
231
232 void onIdle( wxIdleEvent& aEvent );
233 void onHoverTimer( wxTimerEvent& aEvent );
234
235 void onDetailsLink( wxHtmlLinkEvent& aEvent );
236 void onPreselect( wxCommandEvent& aEvent );
237 void onItemContextMenu( wxDataViewEvent& aEvent );
238 void onHeaderContextMenu( wxDataViewEvent& aEvent );
239
240 void onDebounceTimer( wxTimerEvent& aEvent );
241
242protected:
243 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
244
245 wxSearchCtrl* m_query_ctrl;
251
253
254 wxBoxSizer* m_filtersSizer;
255
257
258 wxPoint m_hoverPos;
259 wxDataViewItem m_hoverItem;
262 wxDataViewItem m_previewItem;
264 wxPopupWindow* m_previewWindow;
266};
267
269wxDECLARE_EVENT( EVT_LIBITEM_SELECTED, wxCommandEvent );
270
272wxDECLARE_EVENT( EVT_LIBITEM_CHOSEN, wxCommandEvent );
273
274#endif /* LIB_TREE_H */
Define the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
Add dark theme support to wxHtmlWindow.
Definition: html_window.h:35
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:263
void RefreshLibTree()
Refresh the tree (mainly to update highlighting and asterisking)
Definition: lib_tree.cpp:440
wxPoint m_hoverPos
Definition: lib_tree.h:258
wxTimer * m_debounceTimer
Definition: lib_tree.h:249
void onHoverTimer(wxTimerEvent &aEvent)
Definition: lib_tree.cpp:808
LIB_TREE_NODE * GetCurrentTreeNode() const
Definition: lib_tree.cpp:332
void onQueryMouseMoved(wxMouseEvent &aEvent)
Definition: lib_tree.cpp:687
wxDataViewItem m_previewItem
Definition: lib_tree.h:262
HTML_WINDOW * m_details_ctrl
Definition: lib_tree.h:248
void onTreeActivate(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:871
wxString m_recentSearchesKey
Definition: lib_tree.h:252
void onQueryCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:607
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:548
wxWindow * GetFocusTarget()
Definition: lib_tree.cpp:446
int GetSelectionCount() const
Definition: lib_tree.h:91
void onItemContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:914
void destroyPreview()
Definition: lib_tree.cpp:741
void ShowChangedLanguage()
Definition: lib_tree.cpp:291
WX_DATAVIEWCTRL * m_tree_ctrl
Definition: lib_tree.h:247
void onQueryText(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:589
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition: lib_tree.cpp:462
wxSizer * GetFiltersSizer()
Definition: lib_tree.h:156
bool m_skipNextRightClick
Definition: lib_tree.h:256
bool m_inTimerEvent
Definition: lib_tree.h:250
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:474
void onIdle(wxIdleEvent &aEvent)
Definition: lib_tree.cpp:753
void FocusSearchFieldIfExists()
Focus the search widget if it exists.
Definition: lib_tree.cpp:455
void expandIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:534
void onPreselect(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:895
wxPopupWindow * m_previewWindow
Definition: lib_tree.h:264
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:343
void updateRecentSearchMenu()
Definition: lib_tree.cpp:393
void hidePreview()
Definition: lib_tree.cpp:732
LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const
Definition: lib_tree.h:142
void showPreview(wxDataViewItem aItem)
Definition: lib_tree.cpp:708
wxString GetSearchString() const
Definition: lib_tree.cpp:387
void onTreeSelect(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:859
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:315
wxTimer m_hoverTimer
Definition: lib_tree.h:261
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:541
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:355
void onTreeCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:833
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition: lib_tree.cpp:885
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
@ 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
@ FLAGS_NONE
Definition: lib_tree.h:54
@ SEARCH
Definition: lib_tree.h:55
void ExpandAll()
Definition: lib_tree.cpp:369
wxBoxSizer * m_filtersSizer
Definition: lib_tree.h:254
wxDataViewItem m_hoverItem
Definition: lib_tree.h:259
~LIB_TREE() override
Definition: lib_tree.cpp:253
void SetSearchString(const wxString &aSearchString)
Save/restore search string.
Definition: lib_tree.cpp:381
void setState(const STATE &aState)
Restore the symbol tree widget state from an object.
Definition: lib_tree.cpp:573
STATE getState() const
Return the symbol tree widget state.
Definition: lib_tree.cpp:555
bool m_previewDisabled
Definition: lib_tree.h:265
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
Definition: lib_tree.cpp:363
void BlockPreview(bool aBlock)
Definition: lib_tree.h:165
wxSearchCtrl * m_query_ctrl
Definition: lib_tree.h:245
void CollapseAll()
Definition: lib_tree.cpp:375
void centerIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:486
void onDebounceTimer(wxTimerEvent &aEvent)
Definition: lib_tree.cpp:599
wxRect m_hoverItemRect
Definition: lib_tree.h:260
STD_BITMAP_BUTTON * m_sort_ctrl
Definition: lib_tree.h:246
void onHeaderContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:980
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition: lib_tree.cpp:422
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:243
void SetSortMode(LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode)
Save/restore the sorting mode.
Definition: lib_tree.h:141
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 selected in the list.
Structure storing state of the symbol tree widget.
Definition: lib_tree.h:200
LIB_ID selection
Current selection, might be not valid if nothing was selected.
Definition: lib_tree.h:205
std::vector< wxDataViewItem > expanded
List of expanded nodes.
Definition: lib_tree.h:202