More forgiving keyword search.

In particular, allow comma separators in footprint filters without
making users type them in when searching.

Fixes: lp:1391533
* https://bugs.launchpad.net/kicad/+bug/1391533
This commit is contained in:
Jeff Young 2018-05-10 11:53:07 +01:00
parent 933ff189ad
commit a65088419e
3 changed files with 18 additions and 23 deletions

View File

@ -211,34 +211,27 @@ bool GetAssociatedDocument( wxWindow* aParent,
}
int KeyWordOk( const wxString& KeyList, const wxString& Database )
bool KeywordMatch( const wxString& aKeys, const wxString& aDatabase )
{
wxString KeysCopy, DataList;
if( aKeys.IsEmpty() )
return false;
if( KeyList.IsEmpty() )
return 0;
wxStringTokenizer keyTokenizer( aKeys, wxT( ", \t\n\r" ), wxTOKEN_STRTOK );
KeysCopy = KeyList; KeysCopy.MakeUpper();
DataList = Database; DataList.MakeUpper();
wxStringTokenizer Token( KeysCopy, wxT( " \n\r" ) );
while( Token.HasMoreTokens() )
while( keyTokenizer.HasMoreTokens() )
{
wxString Key = Token.GetNextToken();
wxString key = keyTokenizer.GetNextToken();
// Search Key in Datalist:
wxStringTokenizer Data( DataList, wxT( " \n\r" ) );
// Search for key in aDatabase:
wxStringTokenizer dataTokenizer( aDatabase, wxT( ", \t\n\r" ), wxTOKEN_STRTOK );
while( Data.HasMoreTokens() )
while( dataTokenizer.HasMoreTokens() )
{
wxString word = Data.GetNextToken();
if( word == Key )
return 1; // Key found !
if( dataTokenizer.GetNextToken() == key )
return true;
}
}
// keyword not found
return 0;
return false;
}

View File

@ -33,12 +33,12 @@
/**
* Function KeyWordOk
* Function KeywordMatch
* searches \a aKeyList for any words found in \a aDatabase.
*
* @return 0 if no keyword is found or 1 if keyword is found.
* @return true if keyword is found.
*/
int KeyWordOk( const wxString& aKeyList, const wxString& aDatabase );
bool KeywordMatch( const wxString& aKeys, const wxString& aDatabase );
/**
* Function GetAssociatedDocument

View File

@ -430,9 +430,11 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow,
if( !aKeyWord.IsEmpty() ) // Create a list of modules found by keyword.
{
wxString keyword = aKeyWord.Upper();
for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
{
if( KeyWordOk( aKeyWord, MList.GetItem( ii ).GetKeywords() ) )
if( KeywordMatch( keyword, MList.GetItem( ii ).GetKeywords().Upper() ) )
{
wxArrayString cols;
cols.Add( MList.GetItem( ii ).GetFootprintName() );