diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index c39cdce2..874e0174 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -1271,6 +1271,7 @@ Find in all files except exe, obj && log: + diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index cb6731f7..853ac7ac 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -1677,7 +1677,8 @@ bool Notepad_plus::findInFinderFiles(FindersInfo *findInFolderInfo) } progress.close(); - findInFolderInfo->_pDestFinder->finishFilesSearch(nbTotal, int(filesCount), findInFolderInfo->_findOption._isMatchLineNumber); + const bool searchedInSelection = false; + findInFolderInfo->_pDestFinder->finishFilesSearch(nbTotal, int(filesCount), findInFolderInfo->_findOption._isMatchLineNumber, !searchedInSelection); _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc); _pEditView = pOldView; @@ -1730,6 +1731,8 @@ bool Notepad_plus::findInFiles() progress.open(_findReplaceDlg.getHSelf(), TEXT("Find In Files progress...")); } + const bool isEntireDoc = true; + for (size_t i = 0, updateOnCount = filesPerPercent; i < filesCount; ++i) { if (progress.isCancelled()) break; @@ -1750,7 +1753,7 @@ bool Notepad_plus::findInFiles() _invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? cp : SC_CP_UTF8); FindersInfo findersInfo; findersInfo._pFileName = fileNames.at(i).c_str(); - nbTotal += _findReplaceDlg.processAll(ProcessFindAll, FindReplaceDlg::_env, true, &findersInfo); + nbTotal += _findReplaceDlg.processAll(ProcessFindAll, FindReplaceDlg::_env, isEntireDoc, &findersInfo); if (closeBuf) MainFileManager.closeBuffer(id, _pEditView); } @@ -1767,7 +1770,7 @@ bool Notepad_plus::findInFiles() progress.close(); - _findReplaceDlg.finishFilesSearch(nbTotal, int(filesCount)); + _findReplaceDlg.finishFilesSearch(nbTotal, int(filesCount), isEntireDoc); _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc); _pEditView = pOldView; @@ -1829,7 +1832,7 @@ bool Notepad_plus::findInOpenedFiles() } } - _findReplaceDlg.finishFilesSearch(nbTotal, int(nbUniqueBuffers)); + _findReplaceDlg.finishFilesSearch(nbTotal, int(nbUniqueBuffers), isEntireDoc); _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc); _pEditView = pOldView; @@ -1843,26 +1846,43 @@ bool Notepad_plus::findInOpenedFiles() } -bool Notepad_plus::findInCurrentFile() +bool Notepad_plus::findInCurrentFile(bool isEntireDoc) { int nbTotal = 0; Buffer * pBuf = _pEditView->getCurrentBuffer(); + + Sci_CharacterRange mainSelection = _pEditView->getSelection(); // remember selection before switching view + ScintillaEditView *pOldView = _pEditView; _pEditView = &_invisibleEditView; Document oldDoc = _invisibleEditView.execute(SCI_GETDOCPOINTER); - const bool isEntireDoc = true; - _findReplaceDlg.beginNewFilesSearch(); _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); UINT cp = static_cast(_invisibleEditView.execute(SCI_GETCODEPAGE)); _invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? cp : SC_CP_UTF8); + + if (!isEntireDoc) + { + auto docLength = _invisibleEditView.execute(SCI_GETLENGTH); + + if ((mainSelection.cpMin > 0) || (mainSelection.cpMax < docLength)) + { + _invisibleEditView.execute(SCI_SETSELECTIONSTART, mainSelection.cpMin); + _invisibleEditView.execute(SCI_SETSELECTIONEND, mainSelection.cpMax); + } + else + { + isEntireDoc = true; + } + } + FindersInfo findersInfo; findersInfo._pFileName = pBuf->getFullPathName(); nbTotal += _findReplaceDlg.processAll(ProcessFindAll, FindReplaceDlg::_env, isEntireDoc, &findersInfo); - _findReplaceDlg.finishFilesSearch(nbTotal, 1); + _findReplaceDlg.finishFilesSearch(nbTotal, 1, isEntireDoc); _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc); _pEditView = pOldView; diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index e81d7de2..06699b5e 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -572,7 +572,7 @@ private: //void changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **translatedText); bool replaceInOpenedFiles(); bool findInOpenedFiles(); - bool findInCurrentFile(); + bool findInCurrentFile(bool isEntireDoc); void getMatchedFileNames(const TCHAR *dir, const std::vector & patterns, std::vector & fileNames, bool isRecursive, bool isInHiddenDir); void doSynScorll(HWND hW); diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 63f7d283..66a150b0 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -219,7 +219,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case WM_FINDALL_INCURRENTDOC: { - return findInCurrentFile(); + const bool isEntireDoc = wParam == 0; + return findInCurrentFile(isEntireDoc); } case WM_FINDINFILES: diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index eeb26016..e8653e16 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -869,7 +869,6 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM _countInSelCheckPos.top = _replaceInSelCheckPos.top = p.y; POINT countP = getTopPoint(::GetDlgItem(_hSelf, IDCCOUNTALL), !_isRTL); - _countInSelCheckPos.top = countP.y + 4; // in selection Frame RECT frameRect; @@ -881,7 +880,10 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM _countInSelFramePos.left = _replaceInSelFramePos.left = p.x; _countInSelFramePos.top = _replaceInSelFramePos.top = p.y; - _countInSelFramePos.top = countP.y - 9; + DPIManager* pDpiMgr = &(NppParameters::getInstance()._dpiManager); + + _countInSelFramePos.top = countP.y - pDpiMgr->scaleY(10); + _countInSelFramePos.bottom = pDpiMgr->scaleY(80 - 3); NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker(); @@ -1150,7 +1152,7 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppParamInst._isFindReplacing = true; if (isMacroRecording) saveInMacro(wParam, FR_OP_FIND + FR_OP_GLOBAL); - findAllIn(CURRENT_DOC); + findAllIn(_options._isInSelection ? CURR_DOC_SELECTION : CURRENT_DOC); nppParamInst._isFindReplacing = false; } return TRUE; @@ -1909,7 +1911,8 @@ int FindReplaceDlg::processAll(ProcessOperation op, const FindOption *opt, bool } //then readjust scope if the selection override is active and allowed - if ((pOptions->_isInSelection) && ((op == ProcessMarkAll) || ((op == ProcessReplaceAll) && (!isEntire)))) //if selection limiter and either mark all or replace all w/o entire document override + if ((pOptions->_isInSelection) && ((op == ProcessMarkAll) || ((op == ProcessReplaceAll || op == ProcessFindAll) && (!isEntire)))) + //if selection limiter and either mark all or replace all or find all w/o entire document override { startPosition = cr.cpMin; endPosition = cr.cpMax; @@ -2338,12 +2341,14 @@ void FindReplaceDlg::findAllIn(InWhat op) cmdid = WM_FINDALL_INOPENEDDOC; else if (op == FILES_IN_DIR) cmdid = WM_FINDINFILES; - else if (op == CURRENT_DOC) + else if ((op == CURRENT_DOC) || (op == CURR_DOC_SELECTION)) cmdid = WM_FINDALL_INCURRENTDOC; if (!cmdid) return; - if (::SendMessage(_hParent, cmdid, 0, 0)) + bool limitSearchScopeToSelection = op == CURR_DOC_SELECTION; + + if (::SendMessage(_hParent, cmdid, static_cast(limitSearchScopeToSelection ? 1 : 0), 0)) { generic_string text = _pFinder->getHitsString(_findAllResult); wsprintf(_findAllResultStr, text.c_str()); @@ -2609,6 +2614,11 @@ void FindReplaceDlg::saveInMacro(size_t cmd, int cmdType) booleans |= _options._isWrapAround?IDF_WRAP:0; booleans |= _options._whichDirection?IDF_WHICH_DIRECTION:0; } + else if (cmdType == FR_OP_FIND + FR_OP_GLOBAL) + { + // find all in curr doc can be limited by selected text + booleans |= _options._isInSelection ? IDF_IN_SELECTION_CHECK : 0; + } if (cmd == IDC_CLEAR_ALL) { booleans = _options._doMarkLine ? IDF_MARKLINE_CHECK : 0; @@ -2757,7 +2767,7 @@ void FindReplaceDlg::execSavedCommand(int cmd, uptr_t intValue, const generic_st break; case IDC_FINDALL_CURRENTFILE: nppParamInst._isFindReplacing = true; - findAllIn(CURRENT_DOC); + findAllIn(_env->_isInSelection ? CURR_DOC_SELECTION : CURRENT_DOC); nppParamInst._isFindReplacing = false; break; case IDC_REPLACE_OPENEDFILES: @@ -3176,11 +3186,11 @@ generic_string Finder::getHitsString(int count) const { if (count == 1) { - text = TEXT(" (1 hit)"); + text = TEXT("(1 hit)"); } else { - text = TEXT(" ("); + text = TEXT("("); text += std::to_wstring(count); text += TEXT(" hits)"); } @@ -3235,60 +3245,49 @@ void Finder::addFileHitCount(int count) ++_nbFoundFiles; } -void Finder::addSearchHitCount(int count, int countSearched, bool isMatchLines) +void Finder::addSearchHitCount(int count, int countSearched, bool isMatchLines, bool searchedEntireNotSelection) { - generic_string hitIn; - generic_string fileOf; - generic_string nbResStr = std::to_wstring(count); generic_string nbFoundFilesStr = std::to_wstring(_nbFoundFiles); generic_string nbSearchedFilesStr = std::to_wstring(countSearched); - NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker(); - generic_string text = pNativeSpeaker->getLocalizedStrFromID("find-result-title-info", TEXT("")); + NativeLangSpeaker* pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker(); + + generic_string text = pNativeSpeaker->getLocalizedStrFromID( + searchedEntireNotSelection ? "find-result-title-info" : "find-result-title-info-selections", + TEXT("")); if (text.empty()) { - if (count == 1 && _nbFoundFiles == 1) + // create default output: "(1 hit in 1 file of 1 searched)" + // variation "(1 hit in 2 files of 2 searched)" + // variation "(2 hits in 1 file of 3 searched)" + // variation "(0 hits in 0 files of 1 searched)" + // selection variations: "(1 hit in 1 selection of 1 searched)" " (0 hits in 0 selections of 1 searched)" + // line filter variation: "(1 hit in 1 file of 1 searched) - Line Filter Mode: only display the filtered results" + + generic_string hitsIn = count == 1 ? TEXT("hit") : TEXT("hits"); + + generic_string fileOrSelection = searchedEntireNotSelection ? TEXT("file") : TEXT("selection");; + if (_nbFoundFiles != 1) { - hitIn = TEXT(" hit in "); - fileOf = TEXT(" file of "); - } - else if (count == 1 && _nbFoundFiles != 1) - { - hitIn = TEXT(" hit in "); - fileOf = TEXT(" files of "); - } - else if (count != 1 && _nbFoundFiles == 1) - { - hitIn = TEXT(" hits in "); - fileOf = TEXT(" file of "); - } - else //if (count != 1 && _nbFoundFiles != 1) - { - hitIn = TEXT(" hits in "); - fileOf = TEXT(" files of "); + fileOrSelection += TEXT("s"); } - const TCHAR *moreInfo = isMatchLines ? TEXT(" - Line Filter Mode: only display the filtered results") : TEXT(""); - - text = TEXT(" ("); - text += nbResStr; - text += hitIn; - text += nbFoundFilesStr; - text += fileOf; - text += nbSearchedFilesStr; - text += TEXT(" searched"); - text += moreInfo; - text += TEXT(")"); + text = TEXT("(") + nbResStr + TEXT(" ") + hitsIn + TEXT(" in ") + nbFoundFilesStr + TEXT(" ") + + fileOrSelection + TEXT(" of ") + nbSearchedFilesStr + TEXT(" searched") TEXT(")"); } else { text = stringReplace(text, TEXT("$INT_REPLACE1$"), nbResStr); text = stringReplace(text, TEXT("$INT_REPLACE2$"), nbFoundFilesStr); text = stringReplace(text, TEXT("$INT_REPLACE3$"), nbSearchedFilesStr); + } - text += isMatchLines ? pNativeSpeaker->getLocalizedStrFromID("find-result-title-info-extra", TEXT("")) : TEXT(""); + if (isMatchLines) + { + generic_string lineFilterModeInfo = pNativeSpeaker->getLocalizedStrFromID("find-result-title-info-extra", TEXT(" - Line Filter Mode: only display the filtered results")); + text += lineFilterModeInfo; } setFinderReadOnly(false); @@ -3296,7 +3295,6 @@ void Finder::addSearchHitCount(int count, int countSearched, bool isMatchLines) setFinderReadOnly(true); } - void Finder::add(FoundInfo fi, SearchResultMarking mi, const TCHAR* foundline) { _pMainFoundInfos->push_back(fi); @@ -3425,7 +3423,7 @@ void Finder::beginNewFilesSearch() _scintView.collapse(searchHeaderLevel - SC_FOLDLEVELBASE, fold_collapse); } -void Finder::finishFilesSearch(int count, int searchedCount, bool isMatchLines) +void Finder::finishFilesSearch(int count, int searchedCount, bool isMatchLines, bool searchedEntireNotSelection) { std::vector* _pOldFoundInfos; std::vector* _pOldMarkings; @@ -3443,7 +3441,7 @@ void Finder::finishFilesSearch(int count, int searchedCount, bool isMatchLines) if (_pMainMarkings->size() > 0) _markingsStruct._markings = &((*_pMainMarkings)[0]); - addSearchHitCount(count, searchedCount, isMatchLines); + addSearchHitCount(count, searchedCount, isMatchLines, searchedEntireNotSelection); _scintView.execute(SCI_SETSEL, 0, 0); _scintView.execute(SCI_SETLEXER, SCLEX_SEARCHRESULT); diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h index 6409c357..841f6fd3 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h @@ -46,7 +46,7 @@ enum DIALOG_TYPE {FIND_DLG, REPLACE_DLG, FINDINFILES_DLG, MARK_DLG}; //#define FIND_REPLACE_STR_MAX 256 -enum InWhat{ALL_OPEN_DOCS, FILES_IN_DIR, CURRENT_DOC}; +enum InWhat{ALL_OPEN_DOCS, FILES_IN_DIR, CURRENT_DOC, CURR_DOC_SELECTION}; struct FoundInfo { FoundInfo(int start, int end, size_t lineNumber, const TCHAR *fullPath) @@ -125,14 +125,14 @@ public: void addSearchLine(const TCHAR *searchName); void addFileNameTitle(const TCHAR * fileName); void addFileHitCount(int count); - void addSearchHitCount(int count, int countSearched, bool isMatchLines = false); + void addSearchHitCount(int count, int countSearched, bool isMatchLines, bool searchedEntireNotSelection); void add(FoundInfo fi, SearchResultMarking mi, const TCHAR* foundline); void setFinderStyle(); void removeAll(); void openAll(); void copy(); void beginNewFilesSearch(); - void finishFilesSearch(int count, int searchedCount, bool isMatchLines = false); + void finishFilesSearch(int count, int searchedCount, bool isMatchLines, bool searchedEntireNotSelection); void gotoNextFoundResult(int direction); void gotoFoundLine(); void deleteResult(); @@ -303,9 +303,10 @@ public : _pFinder->addSearchLine(getText2search().c_str()); } - void finishFilesSearch(int count, int searchedCount) + void finishFilesSearch(int count, int searchedCount, bool searchedEntireNotSelection) { - _pFinder->finishFilesSearch(count, searchedCount); + const bool isMatchLines = false; + _pFinder->finishFilesSearch(count, searchedCount, isMatchLines, searchedEntireNotSelection); } void focusOnFinder() { diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.rc b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.rc index 84a41df2..0f0dd15a 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.rc +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.rc @@ -73,8 +73,8 @@ BEGIN PUSHBUTTON "Find Next",IDOK,268,20,91,14,WS_GROUP CONTROL "", IDC_2_BUTTONS_MODE, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 363, 20, 15, 15 PUSHBUTTON "Coun&t",IDCCOUNTALL,268,38,91,14 - PUSHBUTTON "Find All in All &Opened Documents",IDC_FINDALL_OPENEDFILES,268,56,91,21,BS_MULTILINE - PUSHBUTTON "Find All in Current &Document",IDC_FINDALL_CURRENTFILE,268,80,91,21,BS_MULTILINE + PUSHBUTTON "Find All in Current &Document",IDC_FINDALL_CURRENTFILE,268,56,91,21,BS_MULTILINE + PUSHBUTTON "Find All in All &Opened Documents",IDC_FINDALL_OPENEDFILES,268,80,91,21,BS_MULTILINE PUSHBUTTON "&Replace",IDREPLACE,268,38,91,14 PUSHBUTTON "Replace &All",IDREPLACEALL,268,56,91,14 PUSHBUTTON "Replace All in All Opened Doc&uments",IDC_REPLACE_OPENEDFILES,268,74,91,21,BS_MULTILINE