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/sizer.h>
30#include <wx/timer.h>
32#include <widgets/html_window.h>
34
35class wxTextCtrl;
36class wxHtmlLinkEvent;
37class wxSearchCtrl;
38class wxTimer;
39class wxTimerEvent;
40class wxPopupWindow;
41class BITMAP_BUTTON;
43class ACTION_MENU;
44class LIB_ID;
45
49class LIB_TREE : public wxPanel
50{
51public:
53 enum FLAGS
54 {
55 FLAGS_NONE = 0x00,
56 SEARCH = 0x01,
57 FILTERS = 0x02,
58 DETAILS = 0x04,
61 };
62
75 LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey,
76 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter, int aFlags = ALL_WIDGETS,
77 HTML_WINDOW* aDetails = nullptr );
78
79 ~LIB_TREE() override;
80
90 LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
91
93 {
94 return m_tree_ctrl->GetSelectedItemsCount();
95 }
96
105 int GetSelectedLibIds( std::vector<LIB_ID>& aSelection,
106 std::vector<int>* aUnit = nullptr ) const;
107
114
121 int GetSelectedTreeNodes( std::vector<LIB_TREE_NODE*>& aSelection ) const;
122
126 void SelectLibId( const LIB_ID& aLibId );
127
131 void CenterLibId( const LIB_ID& aLibId );
132
136 void Unselect();
137
141 void ExpandLibId( const LIB_ID& aLibId );
142
143 void ExpandAll();
144 void CollapseAll();
145
149 void SetSearchString( const wxString& aSearchString );
150 wxString GetSearchString() const;
151
155 void SetSortMode( LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode ) { m_adapter->SetSortMode( aMode ); }
156 LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const { return m_adapter->GetSortMode(); }
157
161 void Regenerate( bool aKeepState );
162
166 void RefreshLibTree();
167
168 wxWindow* GetFocusTarget();
169
170 wxSizer* GetFiltersSizer() { return m_filtersSizer; }
171
176
177 void ShowChangedLanguage();
178
179 void BlockPreview( bool aBlock )
180 {
181 m_previewDisabled = aBlock;
182 }
183
184 void ShutdownPreviews();
185
186protected:
190 void toggleExpand( const wxDataViewItem& aTreeId );
191
195 void selectIfValid( const wxDataViewItem& aTreeId );
196
197 void centerIfValid( const wxDataViewItem& aTreeId );
198
199 void expandIfValid( const wxDataViewItem& aTreeId );
200
205 void postPreselectEvent();
206
210 void postSelectEvent();
211
215 struct STATE
216 {
218 std::vector<wxDataViewItem> expanded;
219
222
224 };
225
229 STATE getState() const;
230
234 void setState( const STATE& aState );
235
237
238 void showPreview( wxDataViewItem aItem );
239 void hidePreview();
240
241 void onQueryText( wxCommandEvent& aEvent );
242 void onQueryCharHook( wxKeyEvent& aEvent );
243 void onQueryMouseMoved( wxMouseEvent& aEvent );
244
245 void onTreeSelect( wxDataViewEvent& aEvent );
246 void onTreeActivate( wxDataViewEvent& aEvent );
247 void onTreeCharHook( wxKeyEvent& aEvent );
248
249 void onIdle( wxIdleEvent& aEvent );
250 void onHoverTimer( wxTimerEvent& aEvent );
251
252 void onDetailsLink( wxHtmlLinkEvent& aEvent );
253 void onPreselect( wxCommandEvent& aEvent );
254 void onItemContextMenu( wxDataViewEvent& aEvent );
255 void onHeaderContextMenu( wxDataViewEvent& aEvent );
256
257 void onDebounceTimer( wxTimerEvent& aEvent );
258
259protected:
260 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
261
262 wxSearchCtrl* m_query_ctrl;
268
270
271 wxBoxSizer* m_filtersSizer;
272
274
275 wxPoint m_hoverPos;
276 wxDataViewItem m_hoverItem;
279 wxDataViewItem m_previewItem;
281 wxPopupWindow* m_previewWindow;
283};
284
286wxDECLARE_EVENT( EVT_LIBITEM_SELECTED, wxCommandEvent );
287
289wxDECLARE_EVENT( EVT_LIBITEM_CHOSEN, wxCommandEvent );
290
291#endif /* LIB_TREE_H */
Define the structure of a menu based on ACTIONs.
Definition action_menu.h:47
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:35
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:49
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
wxRect m_previewItemRect
Definition lib_tree.h:280
void RefreshLibTree()
Refresh the tree (mainly to update highlighting and asterisking)
Definition lib_tree.cpp:472
wxPoint m_hoverPos
Definition lib_tree.h:275
wxTimer * m_debounceTimer
Definition lib_tree.h:266
void onHoverTimer(wxTimerEvent &aEvent)
Definition lib_tree.cpp:858
LIB_TREE_NODE * GetCurrentTreeNode() const
Retrieve the tree node for the first selected item.
Definition lib_tree.cpp:351
void onQueryMouseMoved(wxMouseEvent &aEvent)
Definition lib_tree.cpp:749
wxDataViewItem m_previewItem
Definition lib_tree.h:279
HTML_WINDOW * m_details_ctrl
Definition lib_tree.h:265
void onTreeActivate(wxDataViewEvent &aEvent)
Definition lib_tree.cpp:938
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:53
void onQueryCharHook(wxKeyEvent &aEvent)
Definition lib_tree.cpp:648
void CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferably centered).
Definition lib_tree.cpp:381
void postSelectEvent()
Post #SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
Definition lib_tree.cpp:580
wxWindow * GetFocusTarget()
Definition lib_tree.cpp:478
int GetSelectionCount() const
Definition lib_tree.h:92
void ShutdownPreviews()
Definition lib_tree.cpp:287
void onItemContextMenu(wxDataViewEvent &aEvent)
Definition lib_tree.cpp:981
void ShowChangedLanguage()
Definition lib_tree.cpp:304
WX_DATAVIEWCTRL * m_tree_ctrl
Definition lib_tree.h:264
void onQueryText(wxCommandEvent &aEvent)
Definition lib_tree.cpp:630
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition lib_tree.cpp:494
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:361
wxSizer * GetFiltersSizer()
Definition lib_tree.h:170
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:506
void onIdle(wxIdleEvent &aEvent)
Definition lib_tree.cpp:803
void FocusSearchFieldIfExists()
Focus the search widget if it exists.
Definition lib_tree.cpp:487
void expandIfValid(const wxDataViewItem &aTreeId)
Definition lib_tree.cpp:566
void onPreselect(wxCommandEvent &aEvent)
Definition lib_tree.cpp:962
wxPopupWindow * m_previewWindow
Definition lib_tree.h:281
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition lib_tree.cpp:375
void updateRecentSearchMenu()
Definition lib_tree.cpp:425
void hidePreview()
Definition lib_tree.cpp:794
LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const
Definition lib_tree.h:156
void showPreview(wxDataViewItem aItem)
Definition lib_tree.cpp:770
wxString GetSearchString() const
Definition lib_tree.cpp:419
void onTreeSelect(wxDataViewEvent &aEvent)
Definition lib_tree.cpp:926
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:334
wxTimer m_hoverTimer
Definition lib_tree.h:278
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition lib_tree.cpp:573
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition lib_tree.cpp:387
BITMAP_BUTTON * m_sort_ctrl
Definition lib_tree.h:263
void onTreeCharHook(wxKeyEvent &aEvent)
Definition lib_tree.cpp:883
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition lib_tree.cpp:952
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:314
FLAGS
< Flags to select extra widgets and options
Definition lib_tree.h:54
@ MULTISELECT
Definition lib_tree.h:60
@ FILTERS
Definition lib_tree.h:57
@ DETAILS
Definition lib_tree.h:58
@ ALL_WIDGETS
Definition lib_tree.h:59
@ FLAGS_NONE
Definition lib_tree.h:55
void ExpandAll()
Definition lib_tree.cpp:401
wxBoxSizer * m_filtersSizer
Definition lib_tree.h:271
wxDataViewItem m_hoverItem
Definition lib_tree.h:276
~LIB_TREE() override
Definition lib_tree.cpp:250
void SetSearchString(const wxString &aSearchString)
Save/restore search string.
Definition lib_tree.cpp:413
void setState(const STATE &aState)
Restore the symbol tree widget state from an object.
Definition lib_tree.cpp:610
STATE getState() const
Return the symbol tree widget state.
Definition lib_tree.cpp:587
bool m_previewDisabled
Definition lib_tree.h:282
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
Definition lib_tree.cpp:395
void BlockPreview(bool aBlock)
Definition lib_tree.h:179
wxSearchCtrl * m_query_ctrl
Definition lib_tree.h:262
void CollapseAll()
Definition lib_tree.cpp:407
void centerIfValid(const wxDataViewItem &aTreeId)
Definition lib_tree.cpp:518
void onDebounceTimer(wxTimerEvent &aEvent)
Definition lib_tree.cpp:640
wxRect m_hoverItemRect
Definition lib_tree.h:277
void onHeaderContextMenu(wxDataViewEvent &aEvent)
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition lib_tree.cpp:454
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition lib_tree.h:260
void SetSortMode(LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode)
Save/restore the sorting mode.
Definition lib_tree.h:155
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:216
LIB_ID selection
Current selection, might be not valid if nothing was selected.
Definition lib_tree.h:221
VECTOR2I scrollpos
Definition lib_tree.h:223
std::vector< wxDataViewItem > expanded
List of expanded nodes.
Definition lib_tree.h:218
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695