diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index ace47049..58d6d963 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -1327,3 +1327,17 @@ void getFilesInFolder(std::vector& files, const generic_string& ::FindClose(hFindFile); } +void trim(generic_string& str) +{ + // remove any leading or trailing spaces from str + + generic_string::size_type pos = str.find_last_not_of(' '); + + if (pos != generic_string::npos) + { + str.erase(pos + 1); + pos = str.find_first_not_of(' '); + if (pos != generic_string::npos) str.erase(0, pos); + } + else str.erase(str.begin(), str.end()); +}; diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index e3299db5..cd18ae13 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -233,3 +233,5 @@ template size_t vecRemoveDuplicates(std::vector& vec, bool isSort } return vec.size(); } + +void trim(generic_string& str); diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index 495a560c..fec18c27 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -1226,11 +1226,11 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM } return TRUE; - case IDD_FINDINFILES_FIND_BUTTON : + case IDD_FINDINFILES_FIND_BUTTON: { setStatusbarMessage(TEXT(""), FSNoMessage); const int filterSize = 256; - TCHAR filters[filterSize+1]; + TCHAR filters[filterSize + 1]; filters[filterSize] = '\0'; TCHAR directory[MAX_PATH]; ::GetDlgItemText(_hSelf, IDD_FINDINFILES_FILTERS_COMBO, filters, filterSize); @@ -1238,25 +1238,30 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM _options._filters = filters; ::GetDlgItemText(_hSelf, IDD_FINDINFILES_DIR_COMBO, directory, MAX_PATH); - addText2Combo(directory, ::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO)); _options._directory = directory; - - if ((lstrlen(directory) > 0) && (directory[lstrlen(directory)-1] != '\\')) - _options._directory += TEXT("\\"); + trim(_options._directory); + if (!_options._directory.empty()) + { + addText2Combo(_options._directory.c_str(), ::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO)); + if (_options._directory.back() != L'\\') + { + _options._directory += TEXT("\\"); + } - HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT); - combo2ExtendedMode(IDFINDWHAT); - _options._str2Search = getTextFromCombo(hFindCombo); - updateCombo(IDFINDWHAT); + HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT); + combo2ExtendedMode(IDFINDWHAT); + _options._str2Search = getTextFromCombo(hFindCombo); + updateCombo(IDFINDWHAT); - nppParamInst._isFindReplacing = true; - if (isMacroRecording) saveInMacro(wParam, FR_OP_FIND + FR_OP_FIF); - findAllIn(FILES_IN_DIR); - nppParamInst._isFindReplacing = false; + nppParamInst._isFindReplacing = true; + if (isMacroRecording) saveInMacro(wParam, FR_OP_FIND + FR_OP_FIF); + findAllIn(FILES_IN_DIR); + nppParamInst._isFindReplacing = false; + } } return TRUE; - case IDD_FINDINFILES_REPLACEINFILES : + case IDD_FINDINFILES_REPLACEINFILES: { std::lock_guard lock(findOps_mutex); @@ -1269,25 +1274,30 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM _options._filters = filters; ::GetDlgItemText(_hSelf, IDD_FINDINFILES_DIR_COMBO, directory, MAX_PATH); - addText2Combo(directory, ::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO)); _options._directory = directory; - - if ((lstrlen(directory) > 0) && (directory[lstrlen(directory)-1] != '\\')) - _options._directory += TEXT("\\"); - - if (replaceInFilesConfirmCheck(_options._directory, _options._filters)) + trim(_options._directory); + if (!_options._directory.empty()) { - HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT); - _options._str2Search = getTextFromCombo(hFindCombo); - HWND hReplaceCombo = ::GetDlgItem(_hSelf, IDREPLACEWITH); - _options._str4Replace = getTextFromCombo(hReplaceCombo); - updateCombo(IDFINDWHAT); - updateCombo(IDREPLACEWITH); + if (replaceInFilesConfirmCheck(_options._directory, _options._filters)) + { + addText2Combo(_options._directory.c_str(), ::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO)); + if (_options._directory.back() != L'\\') + { + _options._directory += TEXT("\\"); + } - nppParamInst._isFindReplacing = true; - if (isMacroRecording) saveInMacro(wParam, FR_OP_REPLACE + FR_OP_FIF); - ::SendMessage(_hParent, WM_REPLACEINFILES, 0, 0); - nppParamInst._isFindReplacing = false; + HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT); + _options._str2Search = getTextFromCombo(hFindCombo); + HWND hReplaceCombo = ::GetDlgItem(_hSelf, IDREPLACEWITH); + _options._str4Replace = getTextFromCombo(hReplaceCombo); + updateCombo(IDFINDWHAT); + updateCombo(IDREPLACEWITH); + + nppParamInst._isFindReplacing = true; + if (isMacroRecording) saveInMacro(wParam, FR_OP_REPLACE + FR_OP_FIF); + ::SendMessage(_hParent, WM_REPLACEINFILES, 0, 0); + nppParamInst._isFindReplacing = false; + } } } return TRUE; diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index 7866074a..4a67c461 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -2102,19 +2102,6 @@ INT_PTR CALLBACK Highlighting::run_dlgProc(UINT message, WPARAM wParam, LPARAM/* return FALSE; } -void trim(generic_string & str) -{ - generic_string::size_type pos = str.find_last_not_of(' '); - - if (pos != generic_string::npos) - { - str.erase(pos + 1); - pos = str.find_first_not_of(' '); - if (pos != generic_string::npos) str.erase(0, pos); - } - else str.erase(str.begin(), str.end()); -}; - INT_PTR CALLBACK PrintSettingsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) { NppParameters& nppParam = NppParameters::getInstance();