2011-11-08 16:37:25 +00:00
|
|
|
/**
|
|
|
|
* @file displlst.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <dialog_helpers.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitle,
|
|
|
|
const wxArrayString& aItemList, const wxString& aRefText,
|
2013-01-10 12:18:43 +00:00
|
|
|
void(* aCallBackFunction)(wxString& Text),
|
|
|
|
bool aSortList ) :
|
|
|
|
EDA_LIST_DIALOG_BASE( aParent, wxID_ANY, aTitle )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-01-10 12:18:43 +00:00
|
|
|
m_sortList = aSortList;
|
2010-11-19 18:50:23 +00:00
|
|
|
m_callBackFct = aCallBackFunction;
|
2013-01-10 12:18:43 +00:00
|
|
|
m_itemsListCp = &aItemList;
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
InsertItems( aItemList, 0 );
|
2013-01-10 12:18:43 +00:00
|
|
|
if( m_sortList )
|
|
|
|
sortList();
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2012-10-18 19:31:40 +00:00
|
|
|
if( !aRefText.IsEmpty() ) // try to select the item matching aRefText
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < aItemList.GetCount(); ii++ )
|
|
|
|
if( aItemList[ii] == aRefText )
|
|
|
|
{
|
|
|
|
m_listBox->SetSelection( ii );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
if( m_callBackFct == NULL )
|
2009-09-02 18:12:45 +00:00
|
|
|
{
|
2013-01-10 12:18:43 +00:00
|
|
|
m_messages->Show(false);
|
|
|
|
m_staticTextMsg->Show(false);
|
2007-12-11 23:12:37 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
m_filterBox->SetFocus();
|
2009-09-02 18:12:45 +00:00
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2010-11-19 18:50:23 +00:00
|
|
|
Centre();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
EDA_LIST_DIALOG::~EDA_LIST_DIALOG()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
void EDA_LIST_DIALOG::textChangeInFilterBox( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-01-10 12:18:43 +00:00
|
|
|
wxString filter;
|
|
|
|
wxString itemName;
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
filter = wxT("*") + m_filterBox->GetLineText(0).MakeLower() + wxT("*");
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
m_listBox->Clear();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
for(unsigned i = 0; i < m_itemsListCp->GetCount(); i++)
|
|
|
|
{
|
|
|
|
itemName = m_itemsListCp->Item(i);
|
|
|
|
|
|
|
|
if( itemName.MakeLower().Matches(filter) )
|
|
|
|
{
|
|
|
|
m_listBox->Insert(m_itemsListCp->Item(i),m_listBox->GetCount());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_sortList )
|
|
|
|
sortList();
|
|
|
|
}
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
wxString EDA_LIST_DIALOG::GetTextSelection()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
wxString text = m_listBox->GetStringSelection();
|
2007-12-11 23:12:37 +00:00
|
|
|
return text;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
void EDA_LIST_DIALOG::Append( const wxString& item )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
m_listBox->Append( item );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
void EDA_LIST_DIALOG::InsertItems( const wxArrayString& itemlist, int position )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
m_listBox->InsertItems( itemlist, position );
|
2013-01-10 12:18:43 +00:00
|
|
|
|
|
|
|
if( m_sortList )
|
|
|
|
sortList();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
void EDA_LIST_DIALOG::onCancelClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
EndModal( wxID_CANCEL );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
void EDA_LIST_DIALOG::onClickOnList( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-12-11 23:12:37 +00:00
|
|
|
wxString text;
|
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
if( m_callBackFct )
|
2007-12-11 23:12:37 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
m_messages->Clear();
|
|
|
|
text = m_listBox->GetStringSelection();
|
|
|
|
m_callBackFct( text );
|
|
|
|
m_messages->WriteText( text );
|
2007-12-11 23:12:37 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
void EDA_LIST_DIALOG::onDClickOnList( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
EndModal( wxID_OK );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
void EDA_LIST_DIALOG::onOkClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
EndModal( wxID_OK );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
void EDA_LIST_DIALOG::onClose( wxCloseEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
EndModal( wxID_CANCEL );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Sort alphabetically, case insensitive.
|
2007-10-07 03:08:24 +00:00
|
|
|
*/
|
2013-01-10 12:18:43 +00:00
|
|
|
static int sortItems( const wxString& item1, const wxString& item2 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-11-08 16:37:25 +00:00
|
|
|
return StrNumCmp( item1, item2, INT_MAX, true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
void EDA_LIST_DIALOG::sortList()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-11-08 16:37:25 +00:00
|
|
|
wxArrayString list = m_listBox->GetStrings();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
if( list.IsEmpty() )
|
2007-12-11 23:12:37 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
list.Sort( sortItems );
|
2010-11-19 18:50:23 +00:00
|
|
|
m_listBox->Clear();
|
2011-11-08 16:37:25 +00:00
|
|
|
m_listBox->Append( list );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|