Add confirmation prompt to Replace-in-all-opened-docs command

Fix #5253, fix #8432, close #8438
This commit is contained in:
Scott Sumner 2020-06-19 09:05:08 -04:00 committed by Don HO
parent 68d66a560c
commit 19bdbd093c
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
3 changed files with 40 additions and 13 deletions

View File

@ -1268,6 +1268,8 @@ Find in all files except exe, obj && log:
<replace-in-files-confirm-title value="Are you sure?"/> <replace-in-files-confirm-title value="Are you sure?"/>
<replace-in-files-confirm-directory value="Are you sure you want to replace all occurrences in :"/> <replace-in-files-confirm-directory value="Are you sure you want to replace all occurrences in :"/>
<replace-in-files-confirm-filetype value="For file type :"/> <replace-in-files-confirm-filetype value="For file type :"/>
<replace-in-open-docs-confirm-title value="Are you sure?"/>
<replace-in-open-docs-confirm-message value="Are you sure you want to replace all occurrences in all open documents?"/>
<find-result-caption value="Find result"/> <find-result-caption value="Find result"/>
<find-result-title value="Search"/> <find-result-title value="Search"/>
<find-result-title-info value="($INT_REPLACE1$ hits in $INT_REPLACE2$ files of $INT_REPLACE3$ searched)"/> <find-result-title-info value="($INT_REPLACE1$ hits in $INT_REPLACE2$ files of $INT_REPLACE3$ searched)"/>

View File

@ -1266,17 +1266,20 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
if (_currentStatus == REPLACE_DLG) if (_currentStatus == REPLACE_DLG)
{ {
setStatusbarMessage(TEXT(""), FSNoMessage); if (replaceInOpenDocsConfirmCheck())
HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT); {
_options._str2Search = getTextFromCombo(hFindCombo); setStatusbarMessage(TEXT(""), FSNoMessage);
HWND hReplaceCombo = ::GetDlgItem(_hSelf, IDREPLACEWITH); HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT);
_options._str4Replace = getTextFromCombo(hReplaceCombo); _options._str2Search = getTextFromCombo(hFindCombo);
updateCombos(); HWND hReplaceCombo = ::GetDlgItem(_hSelf, IDREPLACEWITH);
_options._str4Replace = getTextFromCombo(hReplaceCombo);
updateCombos();
nppParamInst._isFindReplacing = true; nppParamInst._isFindReplacing = true;
if (isMacroRecording) saveInMacro(wParam, FR_OP_REPLACE + FR_OP_GLOBAL); if (isMacroRecording) saveInMacro(wParam, FR_OP_REPLACE + FR_OP_GLOBAL);
replaceAllInOpenedDocs(); replaceAllInOpenedDocs();
nppParamInst._isFindReplacing = false; nppParamInst._isFindReplacing = false;
}
} }
} }
return TRUE; return TRUE;
@ -2811,9 +2814,12 @@ void FindReplaceDlg::execSavedCommand(int cmd, uptr_t intValue, const generic_st
nppParamInst._isFindReplacing = false; nppParamInst._isFindReplacing = false;
break; break;
case IDC_REPLACE_OPENEDFILES: case IDC_REPLACE_OPENEDFILES:
nppParamInst._isFindReplacing = true; if (replaceInOpenDocsConfirmCheck())
replaceAllInOpenedDocs(); {
nppParamInst._isFindReplacing = false; nppParamInst._isFindReplacing = true;
replaceAllInOpenedDocs();
nppParamInst._isFindReplacing = false;
}
break; break;
case IDD_FINDINFILES_FIND_BUTTON: case IDD_FINDINFILES_FIND_BUTTON:
nppParamInst._isFindReplacing = true; nppParamInst._isFindReplacing = true;
@ -3227,6 +3233,24 @@ bool FindReplaceDlg::replaceInFilesConfirmCheck(generic_string directory, generi
return confirmed; return confirmed;
} }
bool FindReplaceDlg::replaceInOpenDocsConfirmCheck(void)
{
bool confirmed = false;
NativeLangSpeaker* pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
generic_string title = pNativeSpeaker->getLocalizedStrFromID("replace-in-open-docs-confirm-title", TEXT("Are you sure?"));
generic_string msg = pNativeSpeaker->getLocalizedStrFromID("replace-in-open-docs-confirm-message", TEXT("Are you sure you want to replace all occurrences in all open documents?"));
int res = ::MessageBox(NULL, msg.c_str(), title.c_str(), MB_OKCANCEL | MB_DEFBUTTON2 | MB_TASKMODAL);
if (res == IDOK)
{
confirmed = true;
}
return confirmed;
}
generic_string Finder::getHitsString(int count) const generic_string Finder::getHitsString(int count) const
{ {
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker(); NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();

View File

@ -417,6 +417,7 @@ private :
void saveInMacro(size_t cmd, int cmdType); void saveInMacro(size_t cmd, int cmdType);
void drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); void drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
bool replaceInFilesConfirmCheck(generic_string directory, generic_string fileTypes); bool replaceInFilesConfirmCheck(generic_string directory, generic_string fileTypes);
bool replaceInOpenDocsConfirmCheck(void);
}; };
//FindIncrementDlg: incremental search dialog, docked in rebar //FindIncrementDlg: incremental search dialog, docked in rebar