Allow auto complete to select pieces by number.

This commit is contained in:
leo 2012-10-18 23:58:16 +00:00
parent b0ac0089ab
commit 00f12a1677

View file

@ -42,50 +42,47 @@ void CPiecesCombo::OnEditupdate()
if (!m_bAutoComplete) if (!m_bAutoComplete)
return; return;
char str[66]; char str[128];
int Length = GetWindowText(str, 128);
if (!Length)
return;
lcPiecesLibrary *pLib = lcGetPiecesLibrary(); lcPiecesLibrary *pLib = lcGetPiecesLibrary();
CPiecesBar* pBar = (CPiecesBar*)GetParent(); CPiecesBar* pBar = (CPiecesBar*)GetParent();
PieceInfo* pInfo; PieceInfo* NewPiece = NULL;
bool DescriptionMatch = false;
if (int n = GetWindowText(str, 65))
{
char newstr[66];
int sel = -1;
strcpy (newstr, "Z");
for (int i = 0; i < pLib->mPieces.GetSize(); i++) for (int i = 0; i < pLib->mPieces.GetSize(); i++)
{ {
pInfo = pLib->mPieces[i]; PieceInfo* Info = pLib->mPieces[i];
if ((pInfo->m_strDescription[0] == '~') && !pBar->m_bSubParts) if ((Info->m_strDescription[0] == '~') && !pBar->m_bSubParts)
continue; continue;
if (_strnicmp (str, pInfo->m_strDescription, n) == 0) if (_strnicmp(str, Info->m_strDescription, Length) == 0)
{ {
if (_stricmp (newstr, pInfo->m_strDescription) > 0) if (!NewPiece || _stricmp(NewPiece->m_strDescription, Info->m_strDescription) > 0)
{ {
strcpy (newstr, pInfo->m_strDescription); NewPiece = Info;
sel = i; DescriptionMatch = true;
} }
} }
else else if (_strnicmp(str, Info->m_strName, Length) == 0)
if (_strnicmp (str, pInfo->m_strName, n) == 0)
{ {
if (_stricmp (newstr, pInfo->m_strName) > 0) if (!NewPiece || _stricmp(NewPiece->m_strName, Info->m_strName) > 0)
{ {
strcpy (newstr, pInfo->m_strName); NewPiece = Info;
sel = i; DescriptionMatch = false;
} }
} }
} }
if (sel >= 0) if (NewPiece)
SelectPiece(pLib->mPieces[sel]);
if (strlen(newstr) > 1)
{ {
SetWindowText(newstr); SelectPiece(NewPiece);
SetEditSel(n, -1); SetWindowText(DescriptionMatch ? NewPiece->m_strDescription : NewPiece->m_strName);
} SetEditSel(Length, -1);
} }
} }
@ -122,11 +119,14 @@ BOOL CPiecesCombo::PreTranslateMessage(MSG* pMsg)
void CPiecesCombo::OnSelchange() void CPiecesCombo::OnSelchange()
{ {
char str[66]; char str[128];
CPiecesBar* pBar = (CPiecesBar*)GetParent(); CPiecesBar* pBar = (CPiecesBar*)GetParent();
lcPiecesLibrary* pLib = lcGetPiecesLibrary(); lcPiecesLibrary* pLib = lcGetPiecesLibrary();
if (!GetLBText (GetCurSel(), str)) if (GetLBTextLen(GetCurSel()) >= sizeof(str))
return;
if (!GetLBText(GetCurSel(), str))
return; return;
for (int i = 0; i < pLib->mPieces.GetSize(); i++) for (int i = 0; i < pLib->mPieces.GetSize(); i++)
@ -135,6 +135,8 @@ void CPiecesCombo::OnSelchange()
if (strcmp(str, pInfo->m_strDescription) == 0) if (strcmp(str, pInfo->m_strDescription) == 0)
SelectPiece(pInfo); SelectPiece(pInfo);
else if (strcmp(str, pInfo->m_strName) == 0)
SelectPiece(pInfo);
} }
} }