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  * @author Maciej Suminski <maciej.suminski@cern.ch>
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 3
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  * https://www.gnu.org/licenses/gpl-3.0.html
20  * or you may search the http://www.gnu.org website for the version 3 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 #include "symbol_tree_pane.h"
26 #include <widgets/lib_tree.h>
27 #include <symbol_library_manager.h>
28 #include <symbol_edit_frame.h>
29 #include <symbol_lib_table.h>
30 #include <tool/tool_manager.h>
31 #include <tools/ee_actions.h>
32 
34  : wxPanel( aParent ),
35  m_symbolEditFrame( aParent ),
36  m_tree( nullptr ),
37  m_libMgr( aLibMgr )
38 {
39  // Create widgets
40  wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
43  boxSizer->Add( m_tree, 1, wxEXPAND, 5 );
44 
45  SetSizer( boxSizer ); // should remove the previous sizer according to wxWidgets docs
46  Layout();
47  boxSizer->Fit( this );
48 
49  m_libMgr->GetAdapter()->FinishTreeInitialization();
50 
51  // Event handlers
52  Bind( COMPONENT_SELECTED, &SYMBOL_TREE_PANE::onComponentSelected, this );
53  m_tree->Bind( wxEVT_UPDATE_UI, &SYMBOL_TREE_PANE::onUpdateUI, this );
54 }
55 
56 
58 {
59  m_tree->Destroy();
60 }
61 
62 
63 void SYMBOL_TREE_PANE::onComponentSelected( wxCommandEvent& aEvent )
64 {
66 
67  // Make sure current-part highlighting doesn't get lost in selection highlighting
68  m_tree->Unselect();
69 
70  // Turn off any previous current-part highlighting
72 }
73 
74 
75 void SYMBOL_TREE_PANE::onUpdateUI( wxUpdateUIEvent& aEvent )
76 {
77  if( m_symbolEditFrame->GetCanvas()->HasFocus() )
78  {
79  // Don't allow a selected item in the tree when the canvas has focus: it's too easy
80  // to confuse the selected-highlighting with the being-edited-on-canvas-highlighting.
81  m_tree->Unselect();
82  }
83 }
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:141
static TOOL_ACTION editSymbol
Definition: ee_actions.h:170
void onComponentSelected(wxCommandEvent &aEvent)
LIB_TREE * m_tree
component 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:189
void RefreshLibTree()
Refreshes the tree (mainly to update highlighting and asterisking)
Definition: lib_tree.cpp:218
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:55
SYMBOL_TREE_PANE(SYMBOL_EDIT_FRAME *aParent, SYMBOL_LIBRARY_MANAGER *aLibMgr)
Widget displaying a tree of components with optional search text control and description panel....
Definition: lib_tree.h:42
The symbol library editor main window.
SYMBOL_EDIT_FRAME * m_symbolEditFrame