mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Allow auto complete to select pieces by number.
This commit is contained in:
parent
b0ac0089ab
commit
00f12a1677
1 changed files with 38 additions and 36 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue