KiCad PCB EDA Suite
symbol_tree_pane.cpp
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) 2017 CERN
5  * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * https://www.gnu.org/licenses/gpl-3.0.html
21  * or you may search the http://www.gnu.org website for the version 3 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include "symbol_tree_pane.h"
27 #include <widgets/lib_tree.h>
28 #include <symbol_library_manager.h>
29 #include <symbol_edit_frame.h>
30 #include <symbol_lib_table.h>
31 #include <tool/tool_manager.h>
32 #include <tools/ee_actions.h>
33 
35  : wxPanel( aParent ),
36  m_symbolEditFrame( aParent ),
37  m_tree( nullptr ),
38  m_libMgr( aLibMgr )
39 {
40  // Create widgets
41  wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
44  boxSizer->Add( m_tree, 1, wxEXPAND, 5 );
45 
46  SetSizer( boxSizer ); // should remove the previous sizer according to wxWidgets docs
47  Layout();
48  boxSizer->Fit( this );
49 
50  m_libMgr->GetAdapter()->FinishTreeInitialization();
51 
52  // Event handlers
53  Bind( SYMBOL_SELECTED, &SYMBOL_TREE_PANE::onSymbolSelected, this );
54  m_tree->Bind( wxEVT_UPDATE_UI, &SYMBOL_TREE_PANE::onUpdateUI, this );
55 }
56 
57 
59 {
60  m_tree->Destroy();
61 }
62 
63 
64 void SYMBOL_TREE_PANE::onSymbolSelected( wxCommandEvent& aEvent )
65 {
67 
68  // Make sure current-part highlighting doesn't get lost in selection highlighting
69  m_tree->Unselect();
70 
71  // Turn off any previous current-part highlighting
73 }
74 
75 
76 void SYMBOL_TREE_PANE::onUpdateUI( wxUpdateUIEvent& aEvent )
77 {
78  if( m_symbolEditFrame->GetCanvas()->HasFocus() )
79  {
80  // Don't allow a selected item in the tree when the canvas has focus: it's too easy
81  // to confuse the selected-highlighting with the being-edited-on-canvas-highlighting.
82  m_tree->Unselect();
83  }
84 }
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
void onUpdateUI(wxUpdateUIEvent &aEvent)
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
static TOOL_ACTION editSymbol
Definition: ee_actions.h:169
LIB_TREE * m_tree
symbol search tree widget
Class to handle modifications to the symbol libraries.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:211
void RefreshLibTree()
Refreshes the tree (mainly to update highlighting and asterisking)
Definition: lib_tree.cpp:240
void onSymbolSelected(wxCommandEvent &aEvent)
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > & GetAdapter()
Return the adapter object that provides the stored data.
SYMBOL_LIBRARY_MANAGER * m_libMgr
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
SYMBOL_TREE_PANE(SYMBOL_EDIT_FRAME *aParent, SYMBOL_LIBRARY_MANAGER *aLibMgr)
Widget displaying a tree of symbols with optional search text control and description panel....
Definition: lib_tree.h:45
The symbol library editor main window.
SYMBOL_EDIT_FRAME * m_symbolEditFrame