diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index 7bc5d6eec..6c682fe40 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -1023,6 +1023,20 @@ bool matchInList(const TCHAR *fileName, const std::vector & patt return is_matched; } +bool allPatternsAreExclusion(const std::vector patterns) +{ + bool oneInclusionPatternFound = false; + for (size_t i = 0, len = patterns.size(); i < len; ++i) + { + if (patterns[i][0] != '!') + { + oneInclusionPatternFound = true; + break; + } + } + return not oneInclusionPatternFound; +} + generic_string GetLastErrorAsString(DWORD errorCode) { generic_string errorMsg(_T("")); diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index 004101cbf..f479529a2 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -92,6 +92,7 @@ std::string getFileContent(const TCHAR *file2read); generic_string relativeFilePathToFullFilePath(const TCHAR *relativeFilePath); void writeFileContent(const TCHAR *file2write, const char *content2write); bool matchInList(const TCHAR *fileName, const std::vector & patterns); +bool allPatternsAreExclusion(const std::vector patterns); class WcharMbcsConvertor final { diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 3eb826035..56be831a6 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -1532,6 +1532,11 @@ bool Notepad_plus::replaceInFiles() _findReplaceDlg.setFindInFilesDirFilter(NULL, TEXT("*.*")); _findReplaceDlg.getPatterns(patterns2Match); } + else if (allPatternsAreExclusion(patterns2Match)) + { + patterns2Match.insert(patterns2Match.begin(), TEXT("*.*")); + } + vector fileNames; getMatchedFileNames(dir2Search, patterns2Match, fileNames, isRecursive, isInHiddenDir); @@ -1619,14 +1624,6 @@ bool Notepad_plus::findInFinderFiles(FindersInfo *findInFolderInfo) _pEditView = &_invisibleEditView; Document oldDoc = _invisibleEditView.execute(SCI_GETDOCPOINTER); - vector patterns2Match; - _findReplaceDlg.getPatterns(patterns2Match); - if (patterns2Match.size() == 0) - { - _findReplaceDlg.setFindInFilesDirFilter(NULL, TEXT("*.*")); - _findReplaceDlg.getPatterns(patterns2Match); - } - vector fileNames = findInFolderInfo->_pSourceFinder->getResultFilePaths(); findInFolderInfo->_pDestFinder->beginNewFilesSearch(); @@ -1711,6 +1708,10 @@ bool Notepad_plus::findInFiles() _findReplaceDlg.setFindInFilesDirFilter(NULL, TEXT("*.*")); _findReplaceDlg.getPatterns(patterns2Match); } + else if (allPatternsAreExclusion(patterns2Match)) + { + patterns2Match.insert(patterns2Match.begin(), TEXT("*.*")); + } vector fileNames; getMatchedFileNames(dir2Search, patterns2Match, fileNames, isRecursive, isInHiddenDir);