Skip to content

Commit

Permalink
Enhance Find Dialog: display extra info in the status bar
Browse files Browse the repository at this point in the history
Fix #14307, close #14347
  • Loading branch information
donho committed Nov 14, 2023
1 parent 812745d commit 05f339b
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 22 deletions.
1 change: 1 addition & 0 deletions PowerEditor/installer/nativeLang/english.xml
Expand Up @@ -1666,6 +1666,7 @@ Find in all files but exclude all folders log or logs recursively:
<find-status-replace-not-found value="Replace: no occurrence was found"/>
<find-status-replace-readonly value="Replace: Cannot replace text. The current document is read only"/>
<find-status-cannot-find value="Find: Can't find the text &quot;$STR_REPLACE$&quot;"/>
<find-status-cannot-find-pebkac-maybe value="The given occurence cannot be found. You may have forgotten to check &quot;Wrap around&quot; (to ON), &quot;Match case&quot; (to OFF), or &quot;Match whole word only&quot; (to OFF)."/>
<find-status-scope-selection value="in selected text"/>
<find-status-scope-all value="in entire file"/>
<find-status-scope-backward value="from start-of-file to caret"/>
Expand Down
1 change: 1 addition & 0 deletions PowerEditor/installer/nativeLang/english_customizable.xml
Expand Up @@ -1666,6 +1666,7 @@ Find in all files but exclude all folders log or logs recursively:
<find-status-replace-not-found value="Replace: no occurrence was found"/>
<find-status-replace-readonly value="Replace: Cannot replace text. The current document is read only"/>
<find-status-cannot-find value="Find: Can't find the text &quot;$STR_REPLACE$&quot;"/>
<find-status-cannot-find-pebkac-maybe value="The given occurence cannot be found. You may have forgotten to check &quot;Wrap around&quot; (to ON), &quot;Match case&quot; (to OFF), or &quot;Match whole word only&quot; (to OFF)."/>
<find-status-scope-selection value="in selected text"/>
<find-status-scope-all value="in entire file"/>
<find-status-scope-backward value="from start-of-file to caret"/>
Expand Down
1 change: 1 addition & 0 deletions PowerEditor/installer/nativeLang/french.xml
Expand Up @@ -1652,6 +1652,7 @@ Rechercher dans tous les fichiers mais pas dans les dossiers log ou logs récurs
<find-status-replace-not-found value="Remplacer : aucune occurrence n'a été trouvée"/>
<find-status-replace-readonly value="Remplacer : l'opération a échoué. Le fichier est en lecture seule"/>
<find-status-cannot-find value="Rechercher : &quot;$STR_REPLACE$&quot; n'a pas été trouvé"/>
<find-status-cannot-find-pebkac-maybe value="L'occurrence donnée n’a pas été trouvée. Vous avez peut-être oublié de cocher &quot;Boucler&quot; (activé), &quot;Respecter la casse&quot; (désactivé), ou &quot;Mot entier uniquement&quot; (désactivé)."/>
<find-status-scope-selection value="dans le texte sélectionné"/>
<find-status-scope-all value="dans le fichier"/>
<find-status-scope-backward value="du début du fichier au curseur"/>
Expand Down
5 changes: 3 additions & 2 deletions PowerEditor/installer/nativeLang/taiwaneseMandarin.xml
Expand Up @@ -1530,9 +1530,10 @@
<find-status-replace-top-reached value="取代:從下面取代了 1 個相符的字串。搜尋已抵達文件開首。"/>
<find-status-replaced-next-found value="取代:取代了 1 個字串。找到下一個字串。"/>
<find-status-replaced-next-not-found value="取代:取代了 1 個字串。找不到下一個字串。"/>
<find-status-replace-not-found value="取代:找不到搜尋字串"/>
<find-status-replace-not-found value="取代:找不到搜尋字串"/>
<find-status-replace-readonly value="取代:檔案唯讀,無法取代字串。"/>
<find-status-cannot-find value="搜尋:找不到搜尋字串「$STR_REPLACE$」。"/>
<find-status-cannot-find value="搜尋:找不到搜尋字串「$STR_REPLACE$」"/>
<find-status-cannot-find-pebkac-maybe value="找不到指定的字串。你可能忘記設定「循環」(設為開啟)、「區分大小寫」(設為關閉)或「僅符合整個單字」(設為關閉)"/>
<find-status-scope-selection value="在所選取的字串中"/>
<find-status-scope-all value="在整個檔案中"/>
<find-status-scope-backward value="從文件開始到游標位置"/>
Expand Down
91 changes: 72 additions & 19 deletions PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp
Expand Up @@ -30,6 +30,8 @@ FindOption FindReplaceDlg::_options;

#define SHIFTED 0x8000

const wstring noFoundPotentialReason = L"The given occurence cannot be found. You may have forgotten to check \"Wrap around\" (to ON), \"Match case\" (to OFF), or \"Match whole word only\" (to OFF).";

void addText2Combo(const TCHAR * txt2add, HWND hCombo)
{
if (!hCombo) return;
Expand Down Expand Up @@ -1984,7 +1986,14 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
result += TEXT(" ");
result += getScopeInfoForStatusBar(&_options);

setStatusbarMessage(result, FSMessage);
wstring reasonMsg;
bool isTheMostLaxMode = _options._isWrapAround && !_options._isMatchCase && !_options._isWholeWord;
if (nbReplaced == 0 && !isTheMostLaxMode)
{
reasonMsg = pNativeSpeaker->getLocalizedStrFromID("find-status-cannot-find-pebkac-maybe", noFoundPotentialReason);
}

setStatusbarMessage(result, FSMessage, reasonMsg);
}
getFocus();
}
Expand Down Expand Up @@ -2021,8 +2030,15 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
}
result += TEXT(" ");
result += getScopeInfoForStatusBar(&_options);

setStatusbarMessage(result, FSMessage);

wstring reasonMsg;
bool isTheMostLaxMode = _options._isWrapAround && !_options._isMatchCase && !_options._isWholeWord;
if (nbCounted == 0 && !isTheMostLaxMode)
{
reasonMsg = pNativeSpeaker->getLocalizedStrFromID("find-status-cannot-find-pebkac-maybe", noFoundPotentialReason);
}

setStatusbarMessage(result, FSMessage, reasonMsg);
}

if (isMacroRecording)
Expand Down Expand Up @@ -2068,7 +2084,14 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
result += TEXT(" ");
result += getScopeInfoForStatusBar(&_options);

setStatusbarMessage(result, FSMessage);
wstring reasonMsg;
bool isTheMostLaxMode = _options._isWrapAround && !_options._isMatchCase && !_options._isWholeWord;
if (nbMarked == 0 && !isTheMostLaxMode)
{
reasonMsg = pNativeSpeaker->getLocalizedStrFromID("find-status-cannot-find-pebkac-maybe", noFoundPotentialReason);
}

setStatusbarMessage(result, FSMessage, reasonMsg);
}

getFocus();
Expand Down Expand Up @@ -2480,13 +2503,30 @@ bool FindReplaceDlg::processFindNext(const TCHAR *txt2find, const FindOption *op
if (oFindStatus)
*oFindStatus = FSNotFound;
//failed, or failed twice with wrap
if (NotIncremental == pOptions->_incrementalType) //incremental search doesnt trigger messages
if (pOptions->_incrementalType == NotIncremental) //incremental search doesnt trigger messages
{
generic_string newTxt2find = stringReplace(txt2find, TEXT("&"), TEXT("&&"));
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
generic_string msg = pNativeSpeaker->getLocalizedStrFromID("find-status-cannot-find", TEXT("Find: Can't find the text \"$STR_REPLACE$\""));
msg = stringReplace(msg, TEXT("$STR_REPLACE$"), newTxt2find);
setStatusbarMessage(msg, FSNotFound);
NativeLangSpeaker* pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
wstring warningMsg = pNativeSpeaker->getLocalizedStrFromID("find-status-cannot-find", L"Find: Can't find the text \"$STR_REPLACE$\"");
wstring newTxt2find = stringReplace(txt2find, L"&", L"&&");

if (newTxt2find.length() > 32) // truncate the search string to display, if the search string is too long
{
newTxt2find.erase(28);
newTxt2find += L"...";
}

warningMsg = stringReplace(warningMsg, L"$STR_REPLACE$", newTxt2find);

warningMsg += TEXT(" ");
warningMsg += getScopeInfoForStatusBar(&_options);

wstring reasonMsg;
bool isTheMostLaxMode = _options._isWrapAround && !_options._isMatchCase && !_options._isWholeWord;
if (!isTheMostLaxMode)
{
reasonMsg = pNativeSpeaker->getLocalizedStrFromID("find-status-cannot-find-pebkac-maybe", noFoundPotentialReason);
}
setStatusbarMessage(warningMsg, FSNotFound, reasonMsg);

// if the dialog is not shown, pass the focus to his parent(ie. Notepad++)
if (!::IsWindowVisible(_hSelf))
Expand Down Expand Up @@ -2633,11 +2673,22 @@ bool FindReplaceDlg::processReplace(const TCHAR *txt2find, const TCHAR *txt2repl
}
else
{
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
generic_string msg = pNativeSpeaker->getLocalizedStrFromID("find-status-replace-not-found", TEXT("Replace: no occurrence was found."));

if (_statusbarTooltipMsg.empty()) // Tooltip message non-empty means there's a find problem - so we keep the message as it is and not erase it
setStatusbarMessage(msg, FSNotFound);
{
NativeLangSpeaker* pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
generic_string msg = pNativeSpeaker->getLocalizedStrFromID("find-status-replace-not-found", TEXT("Replace: no occurrence was found"));

msg += L" ";
msg += getScopeInfoForStatusBar(&_options);

wstring reasonMsg;
bool isTheMostLaxMode = _options._isWrapAround && !_options._isMatchCase && !_options._isWholeWord;
if (!isTheMostLaxMode)
{
reasonMsg = pNativeSpeaker->getLocalizedStrFromID("find-status-cannot-find-pebkac-maybe", noFoundPotentialReason);
}
setStatusbarMessage(msg, FSNotFound, reasonMsg);
}
}

return moreMatches;
Expand Down Expand Up @@ -3609,14 +3660,15 @@ void FindReplaceDlg::saveInMacro(size_t cmd, int cmdType)
::SendMessage(_hParent, WM_FRSAVE_INT, IDC_FRCOMMAND_EXEC, cmd);
}

void FindReplaceDlg::setStatusbarMessage(const generic_string & msg, FindStatus staus, char const *pTooltipMsg)
void FindReplaceDlg::setStatusbarMessage(const wstring & msg, FindStatus staus, wstring tooltipMsg)
{
if (_statusbarTooltipWnd)
{
::DestroyWindow(_statusbarTooltipWnd);
_statusbarTooltipWnd = nullptr;
}
_statusbarTooltipMsg = (pTooltipMsg && (*pTooltipMsg)) ? s2ws(pTooltipMsg) : TEXT("");

_statusbarTooltipMsg = tooltipMsg;

if (staus == FSNotFound)
{
Expand Down Expand Up @@ -3662,8 +3714,9 @@ void FindReplaceDlg::setStatusbarMessageWithRegExprErr(ScintillaEditView* pEditV

NativeLangSpeaker* pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
std::wstring result = pNativeSpeaker->getLocalizedStrFromID("find-status-invalid-re", TEXT("Find: Invalid Regular Expression"));

setStatusbarMessage(result, FSNotFound, msg);
string s = msg;

setStatusbarMessage(result, FSNotFound, s2ws(s));
}

generic_string FindReplaceDlg::getScopeInfoForStatusBar(FindOption const *pFindOpt) const
Expand Down Expand Up @@ -4448,7 +4501,7 @@ void FindReplaceDlg::drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)

::DrawText(lpDrawItemStruct->hDC, ptStr, lstrlen(ptStr), &rect, DT_SINGLELINE | DT_VCENTER | DT_LEFT);

if (_statusbarTooltipMsg.length() == 0) return;
if (_statusbarTooltipMsg.empty()) return;

SIZE size{};
::GetTextExtentPoint32(lpDrawItemStruct->hDC, ptStr, lstrlen(ptStr), &size);
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/ScintillaComponent/FindReplaceDlg.h
Expand Up @@ -386,7 +386,7 @@ public :

void execSavedCommand(int cmd, uptr_t intValue, const generic_string& stringValue);
void clearMarks(const FindOption& opt);
void setStatusbarMessage(const generic_string & msg, FindStatus staus, char const *pTooltipMsg = NULL);
void setStatusbarMessage(const std::wstring & msg, FindStatus staus, std::wstring tooltipMsg = L"");
void setStatusbarMessageWithRegExprErr(ScintillaEditView* pEditView);
generic_string getScopeInfoForStatusBar(FindOption const *pFindOpt) const;
Finder * createFinder();
Expand Down

4 comments on commit 05f339b

@Marcellomco
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find "wrap around" option mentioned on "find-status-cannot-find-pebkac-maybe" entry.

@kubalav
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find "wrap around" option mentioned on "find-status-cannot-find-pebkac-maybe" entry.

see Item id="1606"

@GOLEM777
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The given occurence cannot be found.

may be i wrong, occuRRence

@donho
Copy link
Member Author

@donho donho commented on 05f339b Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GOLEM777
Oups! Fixed, thank you!

Please sign in to comment.