Skip to content

Commit

Permalink
Enhancement: add search options output to FiF Search-results
Browse files Browse the repository at this point in the history
  • Loading branch information
alankilborn authored and donho committed Dec 12, 2023
1 parent bf37d47 commit e497ae2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
5 changes: 5 additions & 0 deletions PowerEditor/installer/nativeLang/english.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,11 @@ Find in all files but exclude all folders log or logs recursively:
<find-result-title value="Search"/><!-- Must not begin with space or tab character -->
<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-options-searchmode-normal value="Normal"/>
<find-result-title-info-options-searchmode-extended value="Extended"/>
<find-result-title-info-options-searchmode-regexp value="RegEx"/>
<find-result-title-info-options-case value="Case"/>
<find-result-title-info-options-word value="Word"/>
<find-result-title-info-extra value=" - Line Filter Mode: only display the filtered results"/>
<find-result-hits value="($INT_REPLACE$ hits)"/>
<find-result-line-prefix value="Line"/><!-- Must not begin with space or tab character -->
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2123,7 +2123,7 @@ bool Notepad_plus::findInFinderFiles(FindersInfo *findInFolderInfo)
progress.close();

const bool searchedInSelection = false;
findInFolderInfo->_pDestFinder->finishFilesSearch(nbTotal, int(filesCount), findInFolderInfo->_findOption._isMatchLineNumber, !searchedInSelection);
findInFolderInfo->_pDestFinder->finishFilesSearch(nbTotal, int(filesCount), !searchedInSelection, &(findInFolderInfo->_findOption));

_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc);
_pEditView = pOldView;
Expand Down
38 changes: 34 additions & 4 deletions PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4696,7 +4696,7 @@ void Finder::addFileHitCount(int count)
++_nbFoundFiles;
}

void Finder::addSearchHitCount(int count, int countSearched, bool isMatchLines, bool searchedEntireNotSelection)
void Finder::addSearchResultInfo(int count, int countSearched, bool searchedEntireNotSelection, const FindOption* pFindOpt)
{
generic_string nbResStr = std::to_wstring(count);
generic_string nbFoundFilesStr = std::to_wstring(_nbFoundFiles);
Expand Down Expand Up @@ -4735,7 +4735,37 @@ void Finder::addSearchHitCount(int count, int countSearched, bool isMatchLines,
text = stringReplace(text, TEXT("$INT_REPLACE3$"), nbSearchedFilesStr);
}

if (isMatchLines)
generic_string searchModeText;
if (pFindOpt->_searchType == FindExtended)
{
searchModeText += pNativeSpeaker->getLocalizedStrFromID("find-result-title-info-options-searchmode-extended", TEXT("Extended"));
}
else if (pFindOpt->_searchType == FindRegex)
{
searchModeText += pNativeSpeaker->getLocalizedStrFromID("find-result-title-info-options-searchmode-regexp", TEXT("RegEx"));
if (pFindOpt->_dotMatchesNewline) searchModeText += TEXT(".");
}
else
{
searchModeText += pNativeSpeaker->getLocalizedStrFromID("find-result-title-info-options-searchmode-normal", TEXT("Normal"));
}

generic_string searchOptionsText;
if (pFindOpt->_isMatchCase)
{
searchOptionsText += pNativeSpeaker->getLocalizedStrFromID("find-result-title-info-options-case", TEXT("Case"));
}
if (pFindOpt->_isWholeWord)
{
if (!searchOptionsText.empty()) searchOptionsText += TEXT("/");
searchOptionsText += pNativeSpeaker->getLocalizedStrFromID("find-result-title-info-options-word", TEXT("Word"));
}

if (!searchOptionsText.empty()) searchModeText += TEXT(": ");

text += TEXT(" [") + searchModeText + searchOptionsText + TEXT("]");

if (pFindOpt->_isMatchLineNumber)
{
generic_string lineFilterModeInfo = pNativeSpeaker->getLocalizedStrFromID("find-result-title-info-extra", TEXT(" - Line Filter Mode: only display the filtered results"));
text += lineFilterModeInfo;
Expand Down Expand Up @@ -4976,7 +5006,7 @@ void Finder::beginNewFilesSearch()
_scintView.collapse(searchHeaderLevel - SC_FOLDLEVELBASE, fold_collapse);
}

void Finder::finishFilesSearch(int count, int searchedCount, bool isMatchLines, bool searchedEntireNotSelection)
void Finder::finishFilesSearch(int count, int searchedCount, bool searchedEntireNotSelection, const FindOption* pFindOpt)
{
std::vector<FoundInfo>* _pOldFoundInfos;
std::vector<SearchResultMarkingLine>* _pOldMarkings;
Expand All @@ -4994,7 +5024,7 @@ void Finder::finishFilesSearch(int count, int searchedCount, bool isMatchLines,
if (_pMainMarkings->size() > 0)
_markingsStruct._markings = &((*_pMainMarkings)[0]);

addSearchHitCount(count, searchedCount, isMatchLines, searchedEntireNotSelection);
addSearchResultInfo(count, searchedCount, searchedEntireNotSelection, pFindOpt);
_scintView.execute(SCI_SETSEL, 0, 0);

//SCI_SETILEXER resets the lexer property @MarkingsStruct and then no data could be exchanged with the searchResult lexer
Expand Down
10 changes: 5 additions & 5 deletions PowerEditor/src/ScintillaComponent/FindReplaceDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct FindOption
bool _isProjectPanel_2 = false;
bool _isProjectPanel_3 = false;
bool _dotMatchesNewline = false;
bool _isMatchLineNumber = true; // only for Find in Folder
bool _isMatchLineNumber = false; // always false for main search
};

//This class contains generic search functions as static functions for easy access
Expand Down Expand Up @@ -124,7 +124,7 @@ friend class FindReplaceDlg;
void addSearchLine(const TCHAR *searchName);
void addFileNameTitle(const TCHAR * fileName);
void addFileHitCount(int count);
void addSearchHitCount(int count, int countSearched, bool isMatchLines, bool searchedEntireNotSelection);
void addSearchResultInfo(int count, int countSearched, bool searchedEntireNotSelection, const FindOption *pFindOpt);
const char* foundLine(FoundInfo fi, SearchResultMarkingLine mi, const TCHAR* foundline, size_t totalLineNumber);
void setFinderStyle();
void setFinderStyleForNpc(bool onlyColor = false);
Expand All @@ -135,7 +135,7 @@ friend class FindReplaceDlg;
void copy();
void copyPathnames();
void beginNewFilesSearch();
void finishFilesSearch(int count, int searchedCount, bool isMatchLines, bool searchedEntireNotSelection);
void finishFilesSearch(int count, int searchedCount, bool searchedEntireNotSelection, const FindOption *pFindOpt);

void gotoNextFoundResult(int direction);
std::pair<intptr_t, intptr_t> gotoFoundLine(size_t nOccurrence = 0); // value 0 means this argument is not used
Expand Down Expand Up @@ -232,6 +232,7 @@ class FindInFinderDlg : public StaticDialog
FindInFinderDlg() {
_options._isMatchCase = false;
_options._isWholeWord = false;
_options._isMatchLineNumber = true;
};

private:
Expand Down Expand Up @@ -340,8 +341,7 @@ public :

void finishFilesSearch(int count, int searchedCount, bool searchedEntireNotSelection)
{
const bool isMatchLines = false;
_pFinder->finishFilesSearch(count, searchedCount, isMatchLines, searchedEntireNotSelection);
_pFinder->finishFilesSearch(count, searchedCount, searchedEntireNotSelection, _env);
}

void focusOnFinder() {
Expand Down

0 comments on commit e497ae2

Please sign in to comment.