Add ability to find-all in selected text
Fix #7927, close #8133, close #8213, close #5089, close #8413
This commit is contained in:
parent
87dc9cc5d2
commit
71b98a7a28
@ -1271,6 +1271,7 @@ Find in all files except exe, obj && log:
|
||||
<find-result-caption value="Find result"/>
|
||||
<find-result-title value="Search"/>
|
||||
<find-result-title-info value="($INT_REPLACE1$ hits in $INT_REPLACE2$ files of $INT_REPLACE3$ searched)"/>
|
||||
<find-result-title-info-selections value="($INT_REPLACE1$ hits in $INT_REPLACE2$ selections of $INT_REPLACE3$ searched)"/>
|
||||
<find-result-title-info-extra value=" - Line Filter Mode: only display the filtered results"/>
|
||||
<find-result-hits value="($INT_REPLACE$ hits)"/>
|
||||
</MiscStrings>
|
||||
|
@ -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<UINT>(_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;
|
||||
|
@ -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<generic_string> & patterns, std::vector<generic_string> & fileNames, bool isRecursive, bool isInHiddenDir);
|
||||
void doSynScorll(HWND hW);
|
||||
|
@ -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:
|
||||
|
@ -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<WPARAM>(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:
|
||||
@ -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(""));
|
||||
|
||||
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<FoundInfo>* _pOldFoundInfos;
|
||||
std::vector<SearchResultMarking>* _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);
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user