Enable and disable controls correctly for reg exp search mode in find-in-finder

Fix #8768, close #8776
This commit is contained in:
Scott Sumner 2020-08-28 08:32:24 -04:00 committed by Don HO
parent e44ed31434
commit 3fd3e85a54
2 changed files with 48 additions and 11 deletions

View File

@ -686,15 +686,19 @@ void FindInFinderDlg::initFromOptions()
HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT_FIFOLDER); HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT_FIFOLDER);
addText2Combo(_options._str2Search.c_str(), hFindCombo); addText2Combo(_options._str2Search.c_str(), hFindCombo);
::SendDlgItemMessage(_hSelf, IDC_MATCHLINENUM_CHECK_FIFOLDER, BM_SETCHECK, _options._isMatchLineNumber ? BST_CHECKED : BST_UNCHECKED, 0); setChecked(IDC_MATCHLINENUM_CHECK_FIFOLDER, _options._isMatchLineNumber);
::SendDlgItemMessage(_hSelf, IDWHOLEWORD_FIFOLDER, BM_SETCHECK, _options._isWholeWord ? BST_CHECKED : BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDMATCHCASE_FIFOLDER, BM_SETCHECK, _options._isMatchCase ? BST_CHECKED : BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDNORMAL_FIFOLDER, BM_SETCHECK, _options._searchType == FindNormal ? BST_CHECKED : BST_UNCHECKED, 0); setChecked(IDWHOLEWORD_FIFOLDER, _options._searchType != FindRegex && _options._isWholeWord);
::SendDlgItemMessage(_hSelf, IDEXTENDED_FIFOLDER, BM_SETCHECK, _options._searchType == FindExtended ? BST_CHECKED : BST_UNCHECKED, 0); ::EnableWindow(::GetDlgItem(_hSelf, IDWHOLEWORD_FIFOLDER), _options._searchType != FindRegex);
::SendDlgItemMessage(_hSelf, IDREGEXP_FIFOLDER, BM_SETCHECK, _options._searchType == FindRegex ? BST_CHECKED : BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDREDOTMATCHNL_FIFOLDER, BM_SETCHECK, _options._dotMatchesNewline ? BST_CHECKED : BST_UNCHECKED, 0); setChecked(IDMATCHCASE_FIFOLDER, _options._isMatchCase);
setChecked(IDNORMAL_FIFOLDER, _options._searchType == FindNormal);
setChecked(IDEXTENDED_FIFOLDER, _options._searchType == FindExtended);
setChecked(IDREGEXP_FIFOLDER, _options._searchType == FindRegex);
setChecked(IDREDOTMATCHNL_FIFOLDER, _options._dotMatchesNewline);
::EnableWindow(::GetDlgItem(_hSelf, IDREDOTMATCHNL_FIFOLDER), _options._searchType == FindRegex);
} }
void FindInFinderDlg::writeOptions() void FindInFinderDlg::writeOptions()
@ -705,7 +709,6 @@ void FindInFinderDlg::writeOptions()
_options._isWholeWord = isCheckedOrNot(IDWHOLEWORD_FIFOLDER); _options._isWholeWord = isCheckedOrNot(IDWHOLEWORD_FIFOLDER);
_options._isMatchCase = isCheckedOrNot(IDMATCHCASE_FIFOLDER); _options._isMatchCase = isCheckedOrNot(IDMATCHCASE_FIFOLDER);
_options._searchType = isCheckedOrNot(IDREGEXP_FIFOLDER) ? FindRegex : isCheckedOrNot(IDEXTENDED_FIFOLDER) ? FindExtended : FindNormal; _options._searchType = isCheckedOrNot(IDREGEXP_FIFOLDER) ? FindRegex : isCheckedOrNot(IDEXTENDED_FIFOLDER) ? FindExtended : FindNormal;
_options._dotMatchesNewline = isCheckedOrNot(IDREDOTMATCHNL_FIFOLDER); _options._dotMatchesNewline = isCheckedOrNot(IDREDOTMATCHNL_FIFOLDER);
} }
@ -726,10 +729,13 @@ INT_PTR CALLBACK FindInFinderDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
switch (LOWORD(wParam)) switch (LOWORD(wParam))
{ {
case IDCANCEL: case IDCANCEL:
{
::EndDialog(_hSelf, -1); ::EndDialog(_hSelf, -1);
return TRUE; return TRUE;
}
case IDOK: case IDOK:
{
writeOptions(); writeOptions();
::EndDialog(_hSelf, -1); ::EndDialog(_hSelf, -1);
FindersInfo findersInfo; FindersInfo findersInfo;
@ -738,6 +744,32 @@ INT_PTR CALLBACK FindInFinderDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
::SendMessage(_hParent, WM_FINDALL_INCURRENTFINDER, reinterpret_cast<WPARAM>(&findersInfo), 0); ::SendMessage(_hParent, WM_FINDALL_INCURRENTFINDER, reinterpret_cast<WPARAM>(&findersInfo), 0);
return TRUE; return TRUE;
} }
case IDNORMAL_FIFOLDER:
case IDEXTENDED_FIFOLDER:
case IDREGEXP_FIFOLDER:
{
if (isCheckedOrNot(IDREGEXP_FIFOLDER))
{
::EnableWindow(::GetDlgItem(_hSelf, IDWHOLEWORD_FIFOLDER), false);
setChecked(IDWHOLEWORD_FIFOLDER, false);
::EnableWindow(GetDlgItem(_hSelf, IDREDOTMATCHNL_FIFOLDER), true);
}
else if (isCheckedOrNot(IDEXTENDED_FIFOLDER))
{
::EnableWindow(::GetDlgItem(_hSelf, IDWHOLEWORD_FIFOLDER), true);
::EnableWindow(GetDlgItem(_hSelf, IDREDOTMATCHNL_FIFOLDER), false);
}
else
{
// normal mode
::EnableWindow(::GetDlgItem(_hSelf, IDWHOLEWORD_FIFOLDER), true);
::EnableWindow(GetDlgItem(_hSelf, IDREDOTMATCHNL_FIFOLDER), false);
}
return TRUE;
}
}
return FALSE; return FALSE;
} }
default: default:
@ -1019,7 +1051,7 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
} }
// At very first time (when find dlg is launched), search mode is Normal. // At very first time (when find dlg is launched), search mode is Normal.
// In that case, ". Matches newline" should be disabled as it applicable on for Regex // In that case, ". Matches newline" should be disabled as it applicable only for Regex
if (isCheckedOrNot(IDREGEXP)) if (isCheckedOrNot(IDREGEXP))
{ {
::EnableWindow(GetDlgItem(_hSelf, IDREDOTMATCHNL), true); ::EnableWindow(GetDlgItem(_hSelf, IDREDOTMATCHNL), true);

View File

@ -71,6 +71,11 @@ public :
return (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, checkControlID), BM_GETCHECK, 0, 0)); return (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, checkControlID), BM_GETCHECK, 0, 0));
} }
void setChecked(int checkControlID, bool checkOrNot = true) const
{
::SendDlgItemMessage(_hSelf, checkControlID, BM_SETCHECK, checkOrNot ? BST_CHECKED : BST_UNCHECKED, 0);
}
virtual void destroy() override; virtual void destroy() override;
protected: protected: