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:
parent
876a0c4c5a
commit
b2387286b1
@ -1327,3 +1327,17 @@ void getFilesInFolder(std::vector<generic_string>& files, const generic_string&
|
|||||||
::FindClose(hFindFile);
|
::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());
|
||||||
|
};
|
||||||
|
@ -233,3 +233,5 @@ template<typename T> size_t vecRemoveDuplicates(std::vector<T>& vec, bool isSort
|
|||||||
}
|
}
|
||||||
return vec.size();
|
return vec.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void trim(generic_string& str);
|
||||||
|
@ -1226,11 +1226,11 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
|
|||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
case IDD_FINDINFILES_FIND_BUTTON :
|
case IDD_FINDINFILES_FIND_BUTTON:
|
||||||
{
|
{
|
||||||
setStatusbarMessage(TEXT(""), FSNoMessage);
|
setStatusbarMessage(TEXT(""), FSNoMessage);
|
||||||
const int filterSize = 256;
|
const int filterSize = 256;
|
||||||
TCHAR filters[filterSize+1];
|
TCHAR filters[filterSize + 1];
|
||||||
filters[filterSize] = '\0';
|
filters[filterSize] = '\0';
|
||||||
TCHAR directory[MAX_PATH];
|
TCHAR directory[MAX_PATH];
|
||||||
::GetDlgItemText(_hSelf, IDD_FINDINFILES_FILTERS_COMBO, filters, filterSize);
|
::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;
|
_options._filters = filters;
|
||||||
|
|
||||||
::GetDlgItemText(_hSelf, IDD_FINDINFILES_DIR_COMBO, directory, MAX_PATH);
|
::GetDlgItemText(_hSelf, IDD_FINDINFILES_DIR_COMBO, directory, MAX_PATH);
|
||||||
addText2Combo(directory, ::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO));
|
|
||||||
_options._directory = directory;
|
_options._directory = directory;
|
||||||
|
trim(_options._directory);
|
||||||
if ((lstrlen(directory) > 0) && (directory[lstrlen(directory)-1] != '\\'))
|
if (!_options._directory.empty())
|
||||||
_options._directory += TEXT("\\");
|
{
|
||||||
|
addText2Combo(_options._directory.c_str(), ::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO));
|
||||||
|
if (_options._directory.back() != L'\\')
|
||||||
|
{
|
||||||
|
_options._directory += TEXT("\\");
|
||||||
|
}
|
||||||
|
|
||||||
HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT);
|
HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT);
|
||||||
combo2ExtendedMode(IDFINDWHAT);
|
combo2ExtendedMode(IDFINDWHAT);
|
||||||
_options._str2Search = getTextFromCombo(hFindCombo);
|
_options._str2Search = getTextFromCombo(hFindCombo);
|
||||||
updateCombo(IDFINDWHAT);
|
updateCombo(IDFINDWHAT);
|
||||||
|
|
||||||
nppParamInst._isFindReplacing = true;
|
nppParamInst._isFindReplacing = true;
|
||||||
if (isMacroRecording) saveInMacro(wParam, FR_OP_FIND + FR_OP_FIF);
|
if (isMacroRecording) saveInMacro(wParam, FR_OP_FIND + FR_OP_FIF);
|
||||||
findAllIn(FILES_IN_DIR);
|
findAllIn(FILES_IN_DIR);
|
||||||
nppParamInst._isFindReplacing = false;
|
nppParamInst._isFindReplacing = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
case IDD_FINDINFILES_REPLACEINFILES :
|
case IDD_FINDINFILES_REPLACEINFILES:
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(findOps_mutex);
|
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;
|
_options._filters = filters;
|
||||||
|
|
||||||
::GetDlgItemText(_hSelf, IDD_FINDINFILES_DIR_COMBO, directory, MAX_PATH);
|
::GetDlgItemText(_hSelf, IDD_FINDINFILES_DIR_COMBO, directory, MAX_PATH);
|
||||||
addText2Combo(directory, ::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO));
|
|
||||||
_options._directory = directory;
|
_options._directory = directory;
|
||||||
|
trim(_options._directory);
|
||||||
if ((lstrlen(directory) > 0) && (directory[lstrlen(directory)-1] != '\\'))
|
if (!_options._directory.empty())
|
||||||
_options._directory += TEXT("\\");
|
|
||||||
|
|
||||||
if (replaceInFilesConfirmCheck(_options._directory, _options._filters))
|
|
||||||
{
|
{
|
||||||
HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT);
|
if (replaceInFilesConfirmCheck(_options._directory, _options._filters))
|
||||||
_options._str2Search = getTextFromCombo(hFindCombo);
|
{
|
||||||
HWND hReplaceCombo = ::GetDlgItem(_hSelf, IDREPLACEWITH);
|
addText2Combo(_options._directory.c_str(), ::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO));
|
||||||
_options._str4Replace = getTextFromCombo(hReplaceCombo);
|
if (_options._directory.back() != L'\\')
|
||||||
updateCombo(IDFINDWHAT);
|
{
|
||||||
updateCombo(IDREPLACEWITH);
|
_options._directory += TEXT("\\");
|
||||||
|
}
|
||||||
|
|
||||||
nppParamInst._isFindReplacing = true;
|
HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT);
|
||||||
if (isMacroRecording) saveInMacro(wParam, FR_OP_REPLACE + FR_OP_FIF);
|
_options._str2Search = getTextFromCombo(hFindCombo);
|
||||||
::SendMessage(_hParent, WM_REPLACEINFILES, 0, 0);
|
HWND hReplaceCombo = ::GetDlgItem(_hSelf, IDREPLACEWITH);
|
||||||
nppParamInst._isFindReplacing = false;
|
_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;
|
return TRUE;
|
||||||
|
@ -2102,19 +2102,6 @@ INT_PTR CALLBACK Highlighting::run_dlgProc(UINT message, WPARAM wParam, LPARAM/*
|
|||||||
return FALSE;
|
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)
|
INT_PTR CALLBACK PrintSettingsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM)
|
||||||
{
|
{
|
||||||
NppParameters& nppParam = NppParameters::getInstance();
|
NppParameters& nppParam = NppParameters::getInstance();
|
||||||
|
Loading…
Reference in New Issue
Block a user