Add "Count in selection" option in Find dialog

Close #722
This commit is contained in:
Don HO 2019-04-11 00:35:52 +02:00
parent 7e716a57f7
commit 4c548d187d
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
2 changed files with 50 additions and 8 deletions

View File

@ -812,6 +812,31 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
_findClosePos.left = p.x; _findClosePos.left = p.x;
_findClosePos.top = p.y + 10; _findClosePos.top = p.y + 10;
// in selection check
RECT checkRect;
::GetWindowRect(::GetDlgItem(_hSelf, IDC_IN_SELECTION_CHECK), &checkRect);
_countInSelCheckPos.bottom = _replaceInSelCheckPos.bottom = checkRect.bottom - checkRect.top;
_countInSelCheckPos.right = _replaceInSelCheckPos.right = checkRect.right - checkRect.left;
p = getTopPoint(::GetDlgItem(_hSelf, IDC_IN_SELECTION_CHECK), !_isRTL);
_countInSelCheckPos.left = _replaceInSelCheckPos.left = p.x;
_countInSelCheckPos.top = _replaceInSelCheckPos.top = p.y;
POINT countP = getTopPoint(::GetDlgItem(_hSelf, IDCCOUNTALL), !_isRTL);
_countInSelCheckPos.top = countP.y + 4;
// in selection Frame
RECT frameRect;
::GetWindowRect(::GetDlgItem(_hSelf, IDC_REPLACEINSELECTION), &frameRect);
_countInSelFramePos.bottom = _replaceInSelFramePos.bottom = frameRect.bottom - frameRect.top;
_countInSelFramePos.right = _replaceInSelFramePos.right = frameRect.right - frameRect.left;
p = getTopPoint(::GetDlgItem(_hSelf, IDC_REPLACEINSELECTION), !_isRTL);
_countInSelFramePos.left = _replaceInSelFramePos.left = p.x;
_countInSelFramePos.top = _replaceInSelFramePos.top = p.y;
_countInSelFramePos.top = countP.y - 9;
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker(); NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker();
generic_string searchButtonTip = pNativeSpeaker->getLocalizedStrFromID("shift-change-direction-tip", TEXT("Use Shift+Enter to search in the opposite direction.")); generic_string searchButtonTip = pNativeSpeaker->getLocalizedStrFromID("shift-change-direction-tip", TEXT("Use Shift+Enter to search in the opposite direction."));
@ -1387,7 +1412,7 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
case IDC_IN_SELECTION_CHECK : case IDC_IN_SELECTION_CHECK :
{ {
if ((_currentStatus == REPLACE_DLG) || (_currentStatus == MARK_DLG)) if ((_currentStatus == FIND_DLG) || (_currentStatus == REPLACE_DLG) || (_currentStatus == MARK_DLG))
_options._isInSelection = isCheckedOrNot(IDC_IN_SELECTION_CHECK); _options._isInSelection = isCheckedOrNot(IDC_IN_SELECTION_CHECK);
} }
return TRUE; return TRUE;
@ -1817,10 +1842,18 @@ int FindReplaceDlg::processAll(ProcessOperation op, const FindOption *opt, bool
} }
//then adjust scope if the full document needs to be changed //then adjust scope if the full document needs to be changed
if (pOptions->_isWrapAround || isEntire || (op == ProcessCountAll)) //entire document needs to be scanned if (op == ProcessCountAll)
{ {
startPosition = 0; if (pOptions->_isInSelection)
endPosition = docLength; {
startPosition = cr.cpMin;
endPosition = cr.cpMax;
}
else if (pOptions->_isWrapAround || isEntire) //entire document needs to be scanned
{
startPosition = 0;
endPosition = docLength;
}
} }
//then readjust scope if the selection override is active and allowed //then readjust scope if the selection override is active and allowed
@ -2358,7 +2391,9 @@ void FindReplaceDlg::enableReplaceFunc(bool isEnable)
{ {
_currentStatus = isEnable?REPLACE_DLG:FIND_DLG; _currentStatus = isEnable?REPLACE_DLG:FIND_DLG;
int hideOrShow = isEnable?SW_SHOW:SW_HIDE; int hideOrShow = isEnable?SW_SHOW:SW_HIDE;
RECT *pClosePos = isEnable?&_replaceClosePos:&_findClosePos; RECT *pClosePos = isEnable ? &_replaceClosePos : &_findClosePos;
RECT *pInSelectionFramePos = isEnable ? &_replaceInSelFramePos : &_countInSelFramePos;
RECT *pInSectionCheckPos = isEnable ? &_replaceInSelCheckPos : &_countInSelCheckPos;
enableFindInFilesControls(false); enableFindInFilesControls(false);
enableMarkAllControls(false); enableMarkAllControls(false);
@ -2369,8 +2404,8 @@ void FindReplaceDlg::enableReplaceFunc(bool isEnable)
::ShowWindow(::GetDlgItem(_hSelf, IDREPLACEALL),hideOrShow); ::ShowWindow(::GetDlgItem(_hSelf, IDREPLACEALL),hideOrShow);
::ShowWindow(::GetDlgItem(_hSelf, IDREPLACEINSEL),hideOrShow); ::ShowWindow(::GetDlgItem(_hSelf, IDREPLACEINSEL),hideOrShow);
::ShowWindow(::GetDlgItem(_hSelf, IDC_REPLACE_OPENEDFILES),hideOrShow); ::ShowWindow(::GetDlgItem(_hSelf, IDC_REPLACE_OPENEDFILES),hideOrShow);
::ShowWindow(::GetDlgItem(_hSelf, IDC_REPLACEINSELECTION),hideOrShow); ::ShowWindow(::GetDlgItem(_hSelf, IDC_REPLACEINSELECTION), SW_SHOW);
::ShowWindow(::GetDlgItem(_hSelf, IDC_IN_SELECTION_CHECK), hideOrShow); ::ShowWindow(::GetDlgItem(_hSelf, IDC_IN_SELECTION_CHECK), SW_SHOW);
::ShowWindow(::GetDlgItem(_hSelf, IDC_2_BUTTONS_MODE), SW_SHOW); ::ShowWindow(::GetDlgItem(_hSelf, IDC_2_BUTTONS_MODE), SW_SHOW);
bool is2ButtonMode = isCheckedOrNot(IDC_2_BUTTONS_MODE); bool is2ButtonMode = isCheckedOrNot(IDC_2_BUTTONS_MODE);
::ShowWindow(::GetDlgItem(_hSelf, IDOK), is2ButtonMode ? SW_HIDE : SW_SHOW); ::ShowWindow(::GetDlgItem(_hSelf, IDOK), is2ButtonMode ? SW_HIDE : SW_SHOW);
@ -2386,6 +2421,8 @@ void FindReplaceDlg::enableReplaceFunc(bool isEnable)
gotoCorrectTab(); gotoCorrectTab();
::MoveWindow(::GetDlgItem(_hSelf, IDCANCEL), pClosePos->left + _deltaWidth, pClosePos->top, pClosePos->right, pClosePos->bottom, TRUE); ::MoveWindow(::GetDlgItem(_hSelf, IDCANCEL), pClosePos->left + _deltaWidth, pClosePos->top, pClosePos->right, pClosePos->bottom, TRUE);
::MoveWindow(::GetDlgItem(_hSelf, IDC_IN_SELECTION_CHECK), pInSectionCheckPos->left + _deltaWidth, pInSectionCheckPos->top, pInSectionCheckPos->right, pInSectionCheckPos->bottom, TRUE);
::MoveWindow(::GetDlgItem(_hSelf, IDC_REPLACEINSELECTION), pInSelectionFramePos->left + _deltaWidth, pInSelectionFramePos->top, pInSelectionFramePos->right, pInSelectionFramePos->bottom, TRUE);
TCHAR label[MAX_PATH]; TCHAR label[MAX_PATH];
_tab.getCurrentTitle(label, MAX_PATH); _tab.getCurrentTitle(label, MAX_PATH);
@ -2866,6 +2903,9 @@ void FindReplaceDlg::enableMarkFunc()
_currentStatus = MARK_DLG; _currentStatus = MARK_DLG;
gotoCorrectTab(); gotoCorrectTab();
::MoveWindow(::GetDlgItem(_hSelf, IDCANCEL), _findInFilesClosePos.left + _deltaWidth, _findInFilesClosePos.top, _findInFilesClosePos.right, _findInFilesClosePos.bottom, TRUE); ::MoveWindow(::GetDlgItem(_hSelf, IDCANCEL), _findInFilesClosePos.left + _deltaWidth, _findInFilesClosePos.top, _findInFilesClosePos.right, _findInFilesClosePos.bottom, TRUE);
::MoveWindow(::GetDlgItem(_hSelf, IDC_IN_SELECTION_CHECK), _replaceInSelCheckPos.left + _deltaWidth, _replaceInSelCheckPos.top, _replaceInSelCheckPos.right, _replaceInSelCheckPos.bottom, TRUE);
::MoveWindow(::GetDlgItem(_hSelf, IDC_REPLACEINSELECTION), _replaceInSelFramePos.left + _deltaWidth, _replaceInSelFramePos.top, _replaceInSelFramePos.right, _replaceInSelFramePos.bottom, TRUE);
TCHAR label[MAX_PATH]; TCHAR label[MAX_PATH];
_tab.getCurrentTitle(label, MAX_PATH); _tab.getCurrentTitle(label, MAX_PATH);
::SetWindowText(_hSelf, label); ::SetWindowText(_hSelf, label);

View File

@ -351,6 +351,8 @@ private :
DIALOG_TYPE _currentStatus; DIALOG_TYPE _currentStatus;
RECT _findClosePos, _replaceClosePos, _findInFilesClosePos; RECT _findClosePos, _replaceClosePos, _findInFilesClosePos;
RECT _countInSelFramePos, _replaceInSelFramePos;
RECT _countInSelCheckPos, _replaceInSelCheckPos;
ScintillaEditView **_ppEditView; ScintillaEditView **_ppEditView;
Finder *_pFinder; Finder *_pFinder;