2017-11-12 17:55:20 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 CERN
|
2021-06-14 18:00:08 +00:00
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-11-12 17:55:20 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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 3
|
|
|
|
* 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:
|
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 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
|
|
|
#include "symbol_tree_pane.h"
|
|
|
|
#include <widgets/lib_tree.h>
|
2022-09-16 03:06:23 +00:00
|
|
|
#include <lib_symbol_library_manager.h>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
2017-11-12 17:55:20 +00:00
|
|
|
#include <symbol_lib_table.h>
|
2019-06-05 22:29:59 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/ee_actions.h>
|
2017-11-30 11:31:36 +00:00
|
|
|
|
2022-09-16 03:06:23 +00:00
|
|
|
SYMBOL_TREE_PANE::SYMBOL_TREE_PANE( SYMBOL_EDIT_FRAME* aParent,
|
|
|
|
LIB_SYMBOL_LIBRARY_MANAGER* aLibMgr )
|
2017-11-12 17:55:20 +00:00
|
|
|
: wxPanel( aParent ),
|
2020-12-25 11:55:45 +00:00
|
|
|
m_symbolEditFrame( aParent ),
|
2019-06-02 18:58:09 +00:00
|
|
|
m_tree( nullptr ),
|
|
|
|
m_libMgr( aLibMgr )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
|
|
|
// Create widgets
|
|
|
|
wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
|
2022-09-15 13:32:27 +00:00
|
|
|
m_tree = new LIB_TREE( this, wxT( "symbols" ), &SYMBOL_LIB_TABLE::GetGlobalLibTable(),
|
|
|
|
m_libMgr->GetAdapter(), LIB_TREE::SEARCH | LIB_TREE::MULTISELECT );
|
2018-07-24 21:16:59 +00:00
|
|
|
boxSizer->Add( m_tree, 1, wxEXPAND, 5 );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2017-11-30 11:31:36 +00:00
|
|
|
SetSizer( boxSizer ); // should remove the previous sizer according to wxWidgets docs
|
2017-11-12 17:55:20 +00:00
|
|
|
Layout();
|
|
|
|
boxSizer->Fit( this );
|
|
|
|
|
2021-04-01 09:49:05 +00:00
|
|
|
m_libMgr->GetAdapter()->FinishTreeInitialization();
|
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
// Event handlers
|
2023-09-28 17:18:19 +00:00
|
|
|
Bind( EVT_LIBITEM_CHOSEN, &SYMBOL_TREE_PANE::onSymbolSelected, this );
|
2020-12-25 11:55:45 +00:00
|
|
|
m_tree->Bind( wxEVT_UPDATE_UI, &SYMBOL_TREE_PANE::onUpdateUI, this );
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
SYMBOL_TREE_PANE::~SYMBOL_TREE_PANE()
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2017-11-30 11:31:36 +00:00
|
|
|
m_tree->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
void SYMBOL_TREE_PANE::onSymbolSelected( wxCommandEvent& aEvent )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_symbolEditFrame->GetToolManager()->RunAction( EE_ACTIONS::editSymbol );
|
2019-11-26 21:38:57 +00:00
|
|
|
|
2019-06-05 22:29:59 +00:00
|
|
|
// Make sure current-part highlighting doesn't get lost in selection highlighting
|
2018-01-20 17:15:46 +00:00
|
|
|
m_tree->Unselect();
|
2019-11-26 21:38:57 +00:00
|
|
|
|
|
|
|
// Turn off any previous current-part highlighting
|
|
|
|
m_tree->RefreshLibTree();
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
2020-12-25 11:55:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SYMBOL_TREE_PANE::onUpdateUI( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( m_symbolEditFrame->GetCanvas()->HasFocus() )
|
|
|
|
{
|
|
|
|
// Don't allow a selected item in the tree when the canvas has focus: it's too easy
|
|
|
|
// to confuse the selected-highlighting with the being-edited-on-canvas-highlighting.
|
2021-07-19 16:59:49 +00:00
|
|
|
if( m_symbolEditFrame->GetCurSymbol() != nullptr )
|
|
|
|
{
|
|
|
|
m_tree->Unselect();
|
|
|
|
}
|
2020-12-25 11:55:45 +00:00
|
|
|
}
|
|
|
|
}
|