2019-08-26 10:57:07 +00:00
|
|
|
/*
|
2017-04-10 14:22:41 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
|
2022-04-16 22:55:19 +00:00
|
|
|
* Copyright (C) 2014-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-04-10 14:22:41 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
#ifndef LIB_TREE_H
|
|
|
|
#define LIB_TREE_H
|
2017-04-10 14:22:41 +00:00
|
|
|
|
|
|
|
#include <wx/panel.h>
|
2018-07-27 20:47:51 +00:00
|
|
|
#include <lib_tree_model_adapter.h>
|
2021-10-10 12:52:37 +00:00
|
|
|
#include <html_window.h>
|
2017-04-10 14:22:41 +00:00
|
|
|
|
|
|
|
class wxDataViewCtrl;
|
|
|
|
class wxTextCtrl;
|
|
|
|
class wxHtmlLinkEvent;
|
2021-07-05 01:24:03 +00:00
|
|
|
class wxSearchCtrl;
|
2021-07-05 01:59:51 +00:00
|
|
|
class wxTimer;
|
|
|
|
class wxTimerEvent;
|
2019-06-05 19:15:57 +00:00
|
|
|
class ACTION_MENU;
|
2017-09-15 14:17:44 +00:00
|
|
|
class LIB_ID;
|
2018-07-27 20:47:51 +00:00
|
|
|
class LIB_TABLE;
|
2017-09-15 14:17:44 +00:00
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
/**
|
2021-06-10 14:10:55 +00:00
|
|
|
* Widget displaying a tree of symbols with optional search text control and description panel.
|
2017-04-10 14:22:41 +00:00
|
|
|
*/
|
2018-07-27 20:47:51 +00:00
|
|
|
class LIB_TREE : public wxPanel
|
2017-04-10 14:22:41 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-09-09 02:15:44 +00:00
|
|
|
///< Flags to select extra widgets and options
|
|
|
|
enum FLAGS
|
|
|
|
{
|
|
|
|
NONE = 0x00,
|
|
|
|
SEARCH = 0x01,
|
|
|
|
DETAILS = 0x02,
|
|
|
|
ALL_WIDGETS = 0x0F,
|
|
|
|
MULTISELECT = 0x10
|
|
|
|
};
|
2017-04-10 14:43:25 +00:00
|
|
|
|
2018-01-03 02:52:35 +00:00
|
|
|
/**
|
2021-06-10 14:10:55 +00:00
|
|
|
* Construct a symbol tree.
|
2018-01-03 02:52:35 +00:00
|
|
|
*
|
|
|
|
* @param aParent parent window containing this tree widget
|
2022-09-15 13:32:27 +00:00
|
|
|
* @param aRecentSearchesKey a key into a global map storing recent searches (usually "power",
|
|
|
|
* "symbols", or "footprints", but could be further differentiated)
|
2018-07-27 20:47:51 +00:00
|
|
|
* @param aLibTable table containing libraries and items to display
|
|
|
|
* @param aAdapter a LIB_TREE_MODEL_ADAPTER instance to use
|
2022-09-09 02:15:44 +00:00
|
|
|
* @param aFlags selection of sub-widgets to include and other options
|
2021-10-10 12:52:37 +00:00
|
|
|
* @param aDetails if not null, a custom HTML_WINDOW to hold symbol details. If null this
|
2018-07-27 20:47:51 +00:00
|
|
|
* will be created inside the LIB_TREE.
|
2018-01-03 02:52:35 +00:00
|
|
|
*/
|
2022-09-15 13:32:27 +00:00
|
|
|
LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey, LIB_TABLE* aLibTable,
|
|
|
|
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter, int aFlags = ALL_WIDGETS,
|
2021-10-10 12:52:37 +00:00
|
|
|
HTML_WINDOW* aDetails = nullptr );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2019-08-26 10:57:07 +00:00
|
|
|
~LIB_TREE() override;
|
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
/**
|
2021-06-10 14:10:55 +00:00
|
|
|
* For multi-unit symbols, if the user selects the symbol itself
|
2017-04-10 14:22:41 +00:00
|
|
|
* rather than picking an individual unit, 0 will be returned in aUnit.
|
|
|
|
* Beware that this is an invalid unit number - this should be replaced
|
|
|
|
* with whatever default is desired (usually 1).
|
|
|
|
*
|
|
|
|
* @param aUnit if not NULL, the selected unit is filled in here.
|
2017-09-15 14:17:44 +00:00
|
|
|
* @return the library id of the symbol that has been selected.
|
2017-04-10 14:22:41 +00:00
|
|
|
*/
|
2017-09-15 14:17:44 +00:00
|
|
|
LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
int GetSelectionCount() const
|
|
|
|
{
|
|
|
|
return m_tree_ctrl->GetSelectedItemsCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a list of selections for trees that allow multi-selection
|
|
|
|
* @see GetSelectedLibId for details on how aUnit will be filled.
|
|
|
|
* @param aSelection will be filled with a list of selected LIB_IDs
|
|
|
|
* @param aUnit is an optional pointer to a list to fill with unit numbers
|
|
|
|
* @return the number of selected items
|
|
|
|
*/
|
|
|
|
int GetSelectedLibIds( std::vector<LIB_ID>& aSelection,
|
|
|
|
std::vector<int>* aUnit = nullptr ) const;
|
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
LIB_TREE_NODE* GetCurrentTreeNode() const;
|
|
|
|
|
2017-11-14 11:03:19 +00:00
|
|
|
/**
|
2018-07-29 15:33:58 +00:00
|
|
|
* Select an item in the tree widget.
|
2017-11-14 11:03:19 +00:00
|
|
|
*/
|
|
|
|
void SelectLibId( const LIB_ID& aLibId );
|
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Ensure that an item is visible (preferably centered).
|
2018-07-29 15:33:58 +00:00
|
|
|
*/
|
|
|
|
void CenterLibId( const LIB_ID& aLibId );
|
|
|
|
|
2018-01-09 12:48:00 +00:00
|
|
|
/**
|
|
|
|
* Unselect currently selected item in wxDataViewCtrl
|
|
|
|
*/
|
|
|
|
void Unselect();
|
|
|
|
|
2018-08-19 16:53:01 +00:00
|
|
|
/**
|
|
|
|
* Expand and item i the tree widget.
|
|
|
|
*/
|
|
|
|
void ExpandLibId( const LIB_ID& aLibId );
|
|
|
|
|
2022-04-16 22:55:19 +00:00
|
|
|
/**
|
|
|
|
* Save/restore search string.
|
|
|
|
*/
|
|
|
|
void SetSearchString( const wxString& aSearchString );
|
|
|
|
wxString GetSearchString() const;
|
|
|
|
|
2017-11-30 11:31:36 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Regenerate the tree.
|
2017-11-30 11:31:36 +00:00
|
|
|
*/
|
2018-11-25 01:38:00 +00:00
|
|
|
void Regenerate( bool aKeepState );
|
2017-11-30 11:31:36 +00:00
|
|
|
|
2019-11-26 21:38:57 +00:00
|
|
|
/**
|
|
|
|
* Refreshes the tree (mainly to update highlighting and asterisking)
|
|
|
|
*/
|
|
|
|
void RefreshLibTree();
|
|
|
|
|
2020-12-08 17:44:44 +00:00
|
|
|
wxWindow* GetFocusTarget();
|
2018-06-08 23:50:06 +00:00
|
|
|
|
2022-12-20 19:54:02 +00:00
|
|
|
/**
|
|
|
|
* Focus the search widget if it exists
|
|
|
|
*/
|
|
|
|
void FocusSearchFieldIfExists();
|
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
protected:
|
2017-12-20 11:25:12 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Expand or collapse a node, switching it to the opposite state.
|
2017-12-20 11:25:12 +00:00
|
|
|
*/
|
|
|
|
void toggleExpand( const wxDataViewItem& aTreeId );
|
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
/**
|
|
|
|
* If a wxDataViewitem is valid, select it and post a selection event.
|
|
|
|
*/
|
|
|
|
void selectIfValid( const wxDataViewItem& aTreeId );
|
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
void centerIfValid( const wxDataViewItem& aTreeId );
|
|
|
|
|
2018-08-19 16:53:01 +00:00
|
|
|
void expandIfValid( const wxDataViewItem& aTreeId );
|
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
/**
|
|
|
|
* Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler
|
2017-06-25 21:13:39 +00:00
|
|
|
* that a new part has been preselected.
|
2017-04-10 14:22:41 +00:00
|
|
|
*/
|
2017-06-25 21:13:39 +00:00
|
|
|
void postPreselectEvent();
|
2017-04-10 14:22:41 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-10 14:10:55 +00:00
|
|
|
* Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
|
2017-04-10 14:22:41 +00:00
|
|
|
*/
|
2017-06-25 21:13:39 +00:00
|
|
|
void postSelectEvent();
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2017-11-30 11:31:36 +00:00
|
|
|
/**
|
2021-06-10 14:10:55 +00:00
|
|
|
* Structure storing state of the symbol tree widget.
|
2017-11-30 11:31:36 +00:00
|
|
|
*/
|
|
|
|
struct STATE
|
|
|
|
{
|
2021-01-25 12:42:36 +00:00
|
|
|
///< List of expanded nodes
|
2017-11-30 11:31:36 +00:00
|
|
|
std::vector<wxDataViewItem> expanded;
|
2020-02-07 17:06:24 +00:00
|
|
|
std::vector<wxString> pinned;
|
2017-11-30 11:31:36 +00:00
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Current selection, might be not valid if nothing was selected
|
2017-12-11 10:22:24 +00:00
|
|
|
LIB_ID selection;
|
2017-11-30 11:31:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-06-10 14:10:55 +00:00
|
|
|
* Return the symbol tree widget state.
|
2017-11-30 11:31:36 +00:00
|
|
|
*/
|
|
|
|
STATE getState() const;
|
|
|
|
|
|
|
|
/**
|
2021-06-10 14:10:55 +00:00
|
|
|
* Restore the symbol tree widget state from an object.
|
2017-11-30 11:31:36 +00:00
|
|
|
*/
|
|
|
|
void setState( const STATE& aState );
|
|
|
|
|
2022-09-15 13:32:27 +00:00
|
|
|
void updateRecentSearchMenu();
|
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
void onQueryText( wxCommandEvent& aEvent );
|
|
|
|
void onQueryCharHook( wxKeyEvent& aEvent );
|
2021-11-18 18:25:14 +00:00
|
|
|
void onQueryMouseMoved( wxMouseEvent& aEvent );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
|
|
|
void onTreeSelect( wxDataViewEvent& aEvent );
|
|
|
|
void onTreeActivate( wxDataViewEvent& aEvent );
|
2022-10-02 21:20:25 +00:00
|
|
|
void onTreeCharHook( wxKeyEvent& aEvent );
|
2022-07-28 13:51:13 +00:00
|
|
|
void onSize( wxSizeEvent& aEvent );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
|
|
|
void onDetailsLink( wxHtmlLinkEvent& aEvent );
|
2017-06-25 21:13:39 +00:00
|
|
|
void onPreselect( wxCommandEvent& aEvent );
|
2022-09-24 03:45:00 +00:00
|
|
|
void onItemContextMenu( wxDataViewEvent& aEvent );
|
|
|
|
void onHeaderContextMenu( wxDataViewEvent& aEvent );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2021-07-05 01:59:51 +00:00
|
|
|
void onDebounceTimer( wxTimerEvent& aEvent );
|
|
|
|
|
2019-08-26 10:57:07 +00:00
|
|
|
protected:
|
2020-11-07 14:31:50 +00:00
|
|
|
LIB_TABLE* m_lib_table;
|
2017-10-28 16:59:49 +00:00
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
|
|
|
|
|
2021-07-05 01:24:03 +00:00
|
|
|
wxSearchCtrl* m_query_ctrl;
|
2020-11-07 14:31:50 +00:00
|
|
|
wxDataViewCtrl* m_tree_ctrl;
|
2021-10-10 12:52:37 +00:00
|
|
|
HTML_WINDOW* m_details_ctrl;
|
2021-07-05 01:59:51 +00:00
|
|
|
wxTimer* m_debounceTimer;
|
2022-09-15 13:32:27 +00:00
|
|
|
bool m_inTimerEvent;
|
2021-02-25 20:13:42 +00:00
|
|
|
|
|
|
|
LIB_ID m_last_libid;
|
2022-09-15 13:32:27 +00:00
|
|
|
wxString m_recentSearchesKey;
|
2022-09-24 03:45:00 +00:00
|
|
|
|
|
|
|
bool m_skipNextRightClick;
|
2017-04-10 14:22:41 +00:00
|
|
|
};
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
///< Custom event sent when a new symbol is preselected
|
|
|
|
wxDECLARE_EVENT( SYMBOL_PRESELECTED, wxCommandEvent );
|
2017-06-25 21:13:39 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
///< Custom event sent when a symbol is selected
|
|
|
|
wxDECLARE_EVENT( SYMBOL_SELECTED, wxCommandEvent );
|
2017-06-25 21:13:39 +00:00
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
#endif /* LIB_TREE_H */
|