Fix find in files failure issue due to directory path with leading/trailing spaces

Trim spaces on Directory for FindInFiles to fix such issue.

Fix #9199, close #9208
This commit is contained in:
Scott Sumner 2020-11-28 12:59:30 -05:00 committed by Don HO
parent 876a0c4c5a
commit b2387286b1
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
4 changed files with 57 additions and 44 deletions

View File

@ -1327,3 +1327,17 @@ void getFilesInFolder(std::vector<generic_string>& 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());
};

View File

@ -233,3 +233,5 @@ template<typename T> size_t vecRemoveDuplicates(std::vector<T>& vec, bool isSort
}
return vec.size();
}
void trim(generic_string& str);

View File

@ -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<std::mutex> 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;

View File

@ -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();