2013-05-31 17:33:46 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2024-05-15 09:32:40 +00:00
|
|
|
* Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-05-31 17:33:46 +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
|
|
|
|
*/
|
|
|
|
|
2019-08-08 22:11:59 +00:00
|
|
|
#include <trace_helpers.h>
|
2013-05-31 17:33:46 +00:00
|
|
|
|
|
|
|
#include <cvpcb_mainframe.h>
|
2013-06-06 15:37:48 +00:00
|
|
|
#include <cvpcb_id.h>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2022-07-10 00:15:36 +00:00
|
|
|
#include "lib_tree_model_adapter.h"
|
2013-05-31 17:33:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***************************************/
|
|
|
|
/* ListBox handling the library list */
|
|
|
|
/***************************************/
|
|
|
|
|
2020-01-11 21:14:09 +00:00
|
|
|
LIBRARY_LISTBOX::LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id ) :
|
2024-05-15 09:32:40 +00:00
|
|
|
ITEMS_LISTBOX_BASE( parent, id, wxDefaultPosition, wxDefaultSize, wxLC_SINGLE_SEL )
|
2013-05-31 17:33:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LIBRARY_LISTBOX::GetCount()
|
|
|
|
{
|
2024-05-15 09:32:40 +00:00
|
|
|
return (int) m_libraryList.Count();
|
2013-05-31 17:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIBRARY_LISTBOX::SetString( unsigned linecount, const wxString& text )
|
|
|
|
{
|
2014-07-31 03:04:34 +00:00
|
|
|
unsigned count = m_libraryList.Count();
|
2024-05-15 09:32:40 +00:00
|
|
|
|
2014-07-31 03:04:34 +00:00
|
|
|
if( count > 0 )
|
|
|
|
{
|
|
|
|
if( linecount >= count )
|
|
|
|
linecount = count - 1;
|
2022-07-10 00:15:36 +00:00
|
|
|
|
2013-06-06 15:37:48 +00:00
|
|
|
m_libraryList[linecount] = text;
|
2014-11-12 10:46:40 +00:00
|
|
|
UpdateWidth( linecount );
|
2014-07-31 03:04:34 +00:00
|
|
|
}
|
2013-05-31 17:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString LIBRARY_LISTBOX::GetSelectedLibrary()
|
|
|
|
{
|
2022-07-10 00:15:36 +00:00
|
|
|
wxString libName;
|
2013-05-31 17:33:46 +00:00
|
|
|
int ii = GetFirstSelected();
|
|
|
|
|
|
|
|
if( ii >= 0 )
|
|
|
|
{
|
2022-07-10 00:15:36 +00:00
|
|
|
libName = m_libraryList[ii];
|
|
|
|
libName.Trim( false );
|
|
|
|
|
|
|
|
if( libName.StartsWith( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() ) )
|
|
|
|
libName = libName.substr( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol().length() );
|
2013-05-31 17:33:46 +00:00
|
|
|
}
|
|
|
|
|
2022-07-10 00:15:36 +00:00
|
|
|
return libName;
|
2013-05-31 17:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIBRARY_LISTBOX::AppendLine( const wxString& text )
|
|
|
|
{
|
2022-07-10 00:15:36 +00:00
|
|
|
m_libraryList.Add( wxT( " " ) + text );
|
2014-11-12 10:46:40 +00:00
|
|
|
int lines = m_libraryList.Count();
|
|
|
|
SetItemCount( lines );
|
2013-05-31 17:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString LIBRARY_LISTBOX::OnGetItemText( long item, long column ) const
|
|
|
|
{
|
2013-06-06 15:37:48 +00:00
|
|
|
return m_libraryList.Item( item );
|
2013-05-31 17:33:46 +00:00
|
|
|
}
|
|
|
|
|
2013-06-06 15:37:48 +00:00
|
|
|
|
2014-06-04 17:34:23 +00:00
|
|
|
void LIBRARY_LISTBOX::SetSelection( int index, bool State )
|
2013-05-31 17:33:46 +00:00
|
|
|
{
|
2014-06-04 17:34:23 +00:00
|
|
|
if( index >= GetCount() )
|
2013-05-31 17:33:46 +00:00
|
|
|
index = GetCount() - 1;
|
|
|
|
|
|
|
|
if( (index >= 0) && (GetCount() > 0) )
|
|
|
|
{
|
|
|
|
#ifndef __WXMAC__
|
|
|
|
Select( index, State );
|
|
|
|
#endif
|
|
|
|
EnsureVisible( index );
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
Refresh();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-10 00:15:36 +00:00
|
|
|
void LIBRARY_LISTBOX::Finish()
|
2013-05-31 17:33:46 +00:00
|
|
|
{
|
2013-09-14 20:33:22 +00:00
|
|
|
if( m_libraryList.Count() )
|
|
|
|
{
|
|
|
|
RefreshItems( 0L, m_libraryList.Count()-1 );
|
2014-11-12 10:46:40 +00:00
|
|
|
UpdateWidth();
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
2013-05-31 17:33:46 +00:00
|
|
|
}
|
|
|
|
|
2024-05-15 09:32:40 +00:00
|
|
|
|
2022-09-27 22:58:03 +00:00
|
|
|
void LIBRARY_LISTBOX::ClearList()
|
|
|
|
{
|
|
|
|
m_libraryList.clear();
|
|
|
|
}
|
2013-05-31 17:33:46 +00:00
|
|
|
|
2024-05-15 09:32:40 +00:00
|
|
|
|
2013-05-31 17:33:46 +00:00
|
|
|
BEGIN_EVENT_TABLE( LIBRARY_LISTBOX, ITEMS_LISTBOX_BASE )
|
|
|
|
EVT_CHAR( LIBRARY_LISTBOX::OnChar )
|
2013-06-06 15:37:48 +00:00
|
|
|
EVT_LIST_ITEM_SELECTED( ID_CVPCB_LIBRARY_LIST, LIBRARY_LISTBOX::OnSelectLibrary )
|
2013-05-31 17:33:46 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
void LIBRARY_LISTBOX::OnChar( wxKeyEvent& event )
|
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( kicadTraceKeyEvent, wxS( "LIBRARY_LISTBOX::OnChar %s" ), dump( event ) );
|
2019-08-08 22:11:59 +00:00
|
|
|
|
2013-05-31 17:33:46 +00:00
|
|
|
int key = event.GetKeyCode();
|
2013-06-06 15:37:48 +00:00
|
|
|
|
2013-05-31 17:33:46 +00:00
|
|
|
switch( key )
|
|
|
|
{
|
2013-06-06 15:37:48 +00:00
|
|
|
case WXK_HOME:
|
|
|
|
case WXK_END:
|
|
|
|
case WXK_UP:
|
|
|
|
case WXK_DOWN:
|
|
|
|
case WXK_PAGEUP:
|
|
|
|
case WXK_PAGEDOWN:
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2013-05-31 17:33:46 +00:00
|
|
|
}
|
2013-06-06 15:37:48 +00:00
|
|
|
|
2013-05-31 17:33:46 +00:00
|
|
|
// Search for an item name starting by the key code:
|
|
|
|
key = toupper(key);
|
2013-06-06 15:37:48 +00:00
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < m_libraryList.GetCount(); ii++ )
|
2013-05-31 17:33:46 +00:00
|
|
|
{
|
2013-06-06 15:37:48 +00:00
|
|
|
wxString text = m_libraryList.Item( ii );
|
|
|
|
|
|
|
|
// Search for the start char of the footprint name. Skip the line number.
|
|
|
|
text.Trim( false ); // Remove leading spaces in line
|
2013-05-31 17:33:46 +00:00
|
|
|
unsigned jj = 0;
|
2013-06-06 15:37:48 +00:00
|
|
|
|
2013-05-31 17:33:46 +00:00
|
|
|
for( ; jj < text.Len(); jj++ )
|
|
|
|
{
|
|
|
|
// skip line number
|
|
|
|
if( text[jj] == ' ' )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( ; jj < text.Len(); jj++ )
|
2024-05-15 09:32:40 +00:00
|
|
|
{
|
|
|
|
// skip blanks
|
2013-05-31 17:33:46 +00:00
|
|
|
if( text[jj] != ' ' )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int start_char = toupper( text[jj] );
|
2013-06-06 15:37:48 +00:00
|
|
|
|
2013-05-31 17:33:46 +00:00
|
|
|
if( key == start_char )
|
|
|
|
{
|
|
|
|
SetSelection( ii, true ); // Ensure visible
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-10-14 13:18:48 +00:00
|
|
|
|
|
|
|
event.Skip();
|
2013-05-31 17:33:46 +00:00
|
|
|
}
|
2013-06-06 15:37:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
void LIBRARY_LISTBOX::OnSelectLibrary( wxListEvent& event )
|
|
|
|
{
|
2019-07-18 21:47:01 +00:00
|
|
|
// Apply the filter
|
2022-07-10 00:15:36 +00:00
|
|
|
GetParent()->SetFootprintFilter( FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY,
|
|
|
|
CVPCB_MAINFRAME::FILTER_ENABLE );
|
2018-07-10 19:58:33 +00:00
|
|
|
|
2013-06-06 15:37:48 +00:00
|
|
|
SetFocus();
|
|
|
|
GetParent()->OnSelectComponent( event );
|
|
|
|
}
|