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)
return;
char str[66];
char str[128];
int Length = GetWindowText(str, 128);
if (!Length)
return;
lcPiecesLibrary *pLib = lcGetPiecesLibrary();
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++)
{
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;
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);
sel = i;
NewPiece = Info;
DescriptionMatch = true;
}
}
else
if (_strnicmp (str, pInfo->m_strName, n) == 0)
else if (_strnicmp(str, Info->m_strName, Length) == 0)
{
if (_stricmp (newstr, pInfo->m_strName) > 0)
if (!NewPiece || _stricmp(NewPiece->m_strName, Info->m_strName) > 0)
{
strcpy (newstr, pInfo->m_strName);
sel = i;
NewPiece = Info;
DescriptionMatch = false;
}
}
}
if (sel >= 0)
SelectPiece(pLib->mPieces[sel]);
if (strlen(newstr) > 1)
if (NewPiece)
{
SetWindowText(newstr);
SetEditSel(n, -1);
}
SelectPiece(NewPiece);
SetWindowText(DescriptionMatch ? NewPiece->m_strDescription : NewPiece->m_strName);
SetEditSel(Length, -1);
}
}
@ -122,10 +119,13 @@ BOOL CPiecesCombo::PreTranslateMessage(MSG* pMsg)
void CPiecesCombo::OnSelchange()
{
char str[66];
char str[128];
CPiecesBar* pBar = (CPiecesBar*)GetParent();
lcPiecesLibrary* pLib = lcGetPiecesLibrary();
if (GetLBTextLen(GetCurSel()) >= sizeof(str))
return;
if (!GetLBText(GetCurSel(), str))
return;
@ -135,6 +135,8 @@ void CPiecesCombo::OnSelchange()
if (strcmp(str, pInfo->m_strDescription) == 0)
SelectPiece(pInfo);
else if (strcmp(str, pInfo->m_strName) == 0)
SelectPiece(pInfo);
}
}