Fix inaccurate find/replace in files result while using invalid regexp
Fix #13164, close #13945
This commit is contained in:
parent
c4733db0af
commit
e7f7c319f5
|
@ -1629,18 +1629,14 @@ Find in all files but exclude all folders log or logs recursively:
|
|||
<find-status-end-reached value="Find: Found the 1st occurrence from the top. The end of the document has been reached."/>
|
||||
<find-status-replaceinfiles-1-replaced value="Replace in Files: 1 occurrence was replaced"/>
|
||||
<find-status-replaceinfiles-nb-replaced value="Replace in Files: $INT_REPLACE$ occurrences were replaced"/>
|
||||
<find-status-replaceinfiles-re-malformed value="Replace in Opened Files: The regular expression is malformed"/>
|
||||
<find-status-replaceinopenedfiles-1-replaced value="Replace in Opened Files: 1 occurrence was replaced"/>
|
||||
<find-status-replaceinopenedfiles-nb-replaced value="Replace in Opened Files: $INT_REPLACE$ occurrences were replaced"/>
|
||||
<find-status-mark-re-malformed value="Mark: The regular expression to search is malformed"/>
|
||||
<find-status-invalid-re value="Find: Invalid regular expression"/>
|
||||
<find-status-search-failed value="Find: Search failed"/>
|
||||
<find-status-mark-1-match value="Mark: 1 match"/>
|
||||
<find-status-mark-nb-matches value="Mark: $INT_REPLACE$ matches"/>
|
||||
<find-status-count-re-malformed value="Count: The regular expression to search is malformed"/>
|
||||
<find-status-count-1-match value="Count: 1 match"/>
|
||||
<find-status-count-nb-matches value="Count: $INT_REPLACE$ matches"/>
|
||||
<find-status-replaceall-re-malformed value="Replace All: The regular expression is malformed"/>
|
||||
<find-status-replaceall-1-replaced value="Replace All: 1 occurrence was replaced"/>
|
||||
<find-status-replaceall-nb-replaced value="Replace All: $INT_REPLACE$ occurrences were replaced"/>
|
||||
<find-status-replaceall-readonly value="Replace All: Cannot replace text. The current document is read only"/>
|
||||
|
|
|
@ -1630,18 +1630,13 @@ Find in all files but exclude all folders log or logs recursively:
|
|||
<find-status-end-reached value="Find: Found the 1st occurrence from the top. The end of the document has been reached."/>
|
||||
<find-status-replaceinfiles-1-replaced value="Replace in Files: 1 occurrence was replaced"/>
|
||||
<find-status-replaceinfiles-nb-replaced value="Replace in Files: $INT_REPLACE$ occurrences were replaced"/>
|
||||
<find-status-replaceinfiles-re-malformed value="Replace in Opened Files: The regular expression is malformed"/>
|
||||
<find-status-replaceinopenedfiles-1-replaced value="Replace in Opened Files: 1 occurrence was replaced"/>
|
||||
<find-status-replaceinopenedfiles-nb-replaced value="Replace in Opened Files: $INT_REPLACE$ occurrences were replaced"/>
|
||||
<find-status-mark-re-malformed value="Mark: The regular expression to search is malformed"/>
|
||||
<find-status-invalid-re value="Find: Invalid regular expression"/>
|
||||
<find-status-search-failed value="Find: Search failed"/>
|
||||
<find-status-mark-1-match value="Mark: 1 match"/>
|
||||
<find-status-mark-nb-matches value="Mark: $INT_REPLACE$ matches"/>
|
||||
<find-status-count-re-malformed value="Count: The regular expression to search is malformed"/>
|
||||
<find-status-count-1-match value="Count: 1 match"/>
|
||||
<find-status-count-nb-matches value="Count: $INT_REPLACE$ matches"/>
|
||||
<find-status-replaceall-re-malformed value="Replace All: The regular expression is malformed"/>
|
||||
<find-status-replaceall-1-replaced value="Replace All: 1 occurrence was replaced"/>
|
||||
<find-status-replaceall-nb-replaced value="Replace All: $INT_REPLACE$ occurrences were replaced"/>
|
||||
<find-status-replaceall-readonly value="Replace All: Cannot replace text. The current document is read only"/>
|
||||
|
|
|
@ -1626,18 +1626,13 @@ Rechercher dans tous les fichiers mais pas dans les dossiers log ou logs récurs
|
|||
<find-status-end-reached value="Rechercher : La 1ère occurrence a été trouvée depuis le haut. La fin du document a été atteinte"/>
|
||||
<find-status-replaceinfiles-1-replaced value="Remplacer dans les fichiers : 1 occurrence a été remplacée"/>
|
||||
<find-status-replaceinfiles-nb-replaced value="Remplacer dans les fichiers : $INT_REPLACE$ occurrences ont été remplacées"/>
|
||||
<find-status-replaceinfiles-re-malformed value="Remplacer dans les fichiers ouverts : l'expression régulière est malformée"/>
|
||||
<find-status-replaceinopenedfiles-1-replaced value="Remplacer dans les fichiers ouverts : 1 occurrence a été remplacée"/>
|
||||
<find-status-replaceinopenedfiles-nb-replaced value="Remplacer dans les fichiers ouverts : $INT_REPLACE$ occurrences ont été remplacées"/>
|
||||
<find-status-mark-re-malformed value="Marquer : l'expression régulière est malformée"/>
|
||||
<find-status-invalid-re value="Rechercher : Expression régulière invalide"/>
|
||||
<find-status-search-failed value="Rechercher: échec de la recherche"/>
|
||||
<find-status-mark-1-match value="1 résultat"/>
|
||||
<find-status-mark-nb-matches value="$INT_REPLACE$ résultats"/>
|
||||
<find-status-count-re-malformed value="Compter : l'expression régulière est malformée"/>
|
||||
<find-status-count-1-match value="Compter : 1 résultat"/>
|
||||
<find-status-count-nb-matches value="Compter : $INT_REPLACE$ résultats"/>
|
||||
<find-status-replaceall-re-malformed value="Remplacer tout : l'expression régulière est malformée"/>
|
||||
<find-status-replaceall-1-replaced value="Remplacer tout : 1 occurrence a été remplacée"/>
|
||||
<find-status-replaceall-nb-replaced value="Remplacer tout : $INT_REPLACE$ occurrences ont été remplacées"/>
|
||||
<find-status-replaceall-readonly value="Remplacer tout : l'opération a échoué. Le fichier est en lecture seule"/>
|
||||
|
|
|
@ -1503,17 +1503,13 @@
|
|||
<find-status-end-reached value="搜尋:從上面找到相符的字串。搜尋已抵達文件結尾。"/>
|
||||
<find-status-replaceinfiles-1-replaced value="在檔案中取代:取代了 1 個字串。"/>
|
||||
<find-status-replaceinfiles-nb-replaced value="在檔案中取代:取代了 $INT_REPLACE$ 個字串。"/>
|
||||
<find-status-replaceinfiles-re-malformed value="在所有開啟文件中取代:無效的規則運算式。"/>
|
||||
<find-status-replaceinopenedfiles-1-replaced value="在所有開啟文件中取代:取代了 1 個字串。"/>
|
||||
<find-status-replaceinopenedfiles-nb-replaced value="在所有開啟文件中取代:取代了 $INT_REPLACE$ 個字串。"/>
|
||||
<find-status-mark-re-malformed value="無效的規則運算式。"/>
|
||||
<find-status-invalid-re value="搜尋:無效的規則運算式。"/>
|
||||
<find-status-mark-1-match value="1 個相符。"/>
|
||||
<find-status-mark-nb-matches value="$INT_REPLACE$ 個相符。"/>
|
||||
<find-status-count-re-malformed value="標記:無效的規則運算式。"/>
|
||||
<find-status-count-1-match value="標記:1 個相符。"/>
|
||||
<find-status-count-nb-matches value="標記:$INT_REPLACE$ 個相符。"/>
|
||||
<find-status-replaceall-re-malformed value="全部取代:無效的規則運算式。"/>
|
||||
<find-status-replaceall-1-replaced value="全部取代:取代了 1 個字串。"/>
|
||||
<find-status-replaceall-nb-replaced value="全部取代:取代了 $INT_REPLACE$ 個字串。"/>
|
||||
<find-status-replaceall-readonly value="全部取代:檔案為唯讀,無法取代字串。"/>
|
||||
|
|
|
@ -1250,6 +1250,7 @@ bool Notepad_plus::replaceInOpenedFiles()
|
|||
|
||||
int nbTotal = 0;
|
||||
const bool isEntireDoc = true;
|
||||
bool hasInvalidRegExpr = false;
|
||||
|
||||
if (_mainWindowStatus & WindowMainActive)
|
||||
{
|
||||
|
@ -1265,12 +1266,21 @@ bool Notepad_plus::replaceInOpenedFiles()
|
|||
_invisibleEditView.setCurrentBuffer(pBuf);
|
||||
|
||||
_invisibleEditView.execute(SCI_BEGINUNDOACTION);
|
||||
nbTotal += _findReplaceDlg.processAll(ProcessReplaceAll, FindReplaceDlg::_env, isEntireDoc);
|
||||
int nb = _findReplaceDlg.processAll(ProcessReplaceAll, FindReplaceDlg::_env, isEntireDoc);
|
||||
if (nb == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{
|
||||
hasInvalidRegExpr = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
nbTotal += nb;
|
||||
}
|
||||
_invisibleEditView.execute(SCI_ENDUNDOACTION);
|
||||
}
|
||||
}
|
||||
|
||||
if (_mainWindowStatus & WindowSubActive)
|
||||
if (!hasInvalidRegExpr && (_mainWindowStatus & WindowSubActive))
|
||||
{
|
||||
for (size_t i = 0, len = _subDocTab.nbItem(); i < len; ++i)
|
||||
{
|
||||
|
@ -1284,7 +1294,16 @@ bool Notepad_plus::replaceInOpenedFiles()
|
|||
_invisibleEditView.setCurrentBuffer(pBuf);
|
||||
|
||||
_invisibleEditView.execute(SCI_BEGINUNDOACTION);
|
||||
nbTotal += _findReplaceDlg.processAll(ProcessReplaceAll, FindReplaceDlg::_env, isEntireDoc);
|
||||
int nb = _findReplaceDlg.processAll(ProcessReplaceAll, FindReplaceDlg::_env, isEntireDoc);
|
||||
if (nb == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{
|
||||
hasInvalidRegExpr = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
nbTotal += nb;
|
||||
}
|
||||
_invisibleEditView.execute(SCI_ENDUNDOACTION);
|
||||
}
|
||||
}
|
||||
|
@ -1293,11 +1312,9 @@ bool Notepad_plus::replaceInOpenedFiles()
|
|||
_invisibleEditView.setCurrentBuffer(oldBuf);
|
||||
_pEditView = pOldView;
|
||||
|
||||
|
||||
if (nbTotal < 0)
|
||||
if (hasInvalidRegExpr)
|
||||
{
|
||||
generic_string msg = _nativeLangSpeaker.getLocalizedStrFromID("find-status-replaceinfiles-re-malformed", TEXT("Replace in Opened Files: The regular expression is malformed."));
|
||||
_findReplaceDlg.setStatusbarMessage(msg, FSNotFound);
|
||||
_findReplaceDlg.setStatusbarMessageWithRegExprErr(&_invisibleEditView);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1952,6 +1969,8 @@ bool Notepad_plus::replaceInFilelist(std::vector<generic_string> & fileNames)
|
|||
progress.open(_findReplaceDlg.getHSelf(), msg.c_str());
|
||||
}
|
||||
|
||||
bool hasInvalidRegExpr = false;
|
||||
|
||||
for (size_t i = 0, updateOnCount = filesPerPercent; i < filesCount; ++i)
|
||||
{
|
||||
if (progress.isCancelled()) break;
|
||||
|
@ -1977,12 +1996,20 @@ bool Notepad_plus::replaceInFilelist(std::vector<generic_string> & fileNames)
|
|||
FindersInfo findersInfo;
|
||||
findersInfo._pFileName = fileNames.at(i).c_str();
|
||||
int nbReplaced = _findReplaceDlg.processAll(ProcessReplaceAll, FindReplaceDlg::_env, true, &findersInfo);
|
||||
nbTotal += nbReplaced;
|
||||
if (nbReplaced)
|
||||
{
|
||||
MainFileManager.saveBuffer(id, pBuf->getFullPathName());
|
||||
}
|
||||
|
||||
if (nbReplaced == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{
|
||||
hasInvalidRegExpr = true;
|
||||
break;;
|
||||
}
|
||||
else
|
||||
{
|
||||
nbTotal += nbReplaced;
|
||||
if (nbReplaced)
|
||||
{
|
||||
MainFileManager.saveBuffer(id, pBuf->getFullPathName());
|
||||
}
|
||||
}
|
||||
if (closeBuf)
|
||||
MainFileManager.closeBuffer(id, _pEditView);
|
||||
}
|
||||
|
@ -2013,7 +2040,11 @@ bool Notepad_plus::replaceInFilelist(std::vector<generic_string> & fileNames)
|
|||
result = _nativeLangSpeaker.getLocalizedStrFromID("find-status-replaceinfiles-nb-replaced", TEXT("Replace in Files: $INT_REPLACE$ occurrences were replaced."));
|
||||
result = stringReplace(result, TEXT("$INT_REPLACE$"), std::to_wstring(nbTotal));
|
||||
}
|
||||
_findReplaceDlg.setStatusbarMessage(result, FSMessage);
|
||||
|
||||
if (!hasInvalidRegExpr)
|
||||
_findReplaceDlg.setStatusbarMessage(result, FSMessage);
|
||||
else
|
||||
_findReplaceDlg.setStatusbarMessageWithRegExprErr(&_invisibleEditView);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2066,11 +2097,20 @@ bool Notepad_plus::findInFinderFiles(FindersInfo *findInFolderInfo)
|
|||
|
||||
findInFolderInfo->_pFileName = fileNames.at(i).c_str();
|
||||
|
||||
nbTotal += _findReplaceDlg.processAll(ProcessFindInFinder, &(findInFolderInfo->_findOption), true, findInFolderInfo);
|
||||
|
||||
int nb = _findReplaceDlg.processAll(ProcessFindInFinder, &(findInFolderInfo->_findOption), true, findInFolderInfo);
|
||||
if (nb == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
nbTotal += nb;
|
||||
}
|
||||
|
||||
if (closeBuf)
|
||||
MainFileManager.closeBuffer(id, _pEditView);
|
||||
}
|
||||
|
||||
if (i == updateOnCount)
|
||||
{
|
||||
updateOnCount += filesPerPercent;
|
||||
|
@ -2135,6 +2175,7 @@ bool Notepad_plus::findInFilelist(std::vector<generic_string> & fileNames)
|
|||
}
|
||||
|
||||
const bool isEntireDoc = true;
|
||||
bool hasInvalidRegExpr = false;
|
||||
|
||||
for (size_t i = 0, updateOnCount = filesPerPercent; i < filesCount; ++i)
|
||||
{
|
||||
|
@ -2158,7 +2199,15 @@ bool Notepad_plus::findInFilelist(std::vector<generic_string> & fileNames)
|
|||
FindersInfo findersInfo;
|
||||
findersInfo._pFileName = fileNames.at(i).c_str();
|
||||
|
||||
nbTotal += _findReplaceDlg.processAll(ProcessFindAll, FindReplaceDlg::_env, isEntireDoc, &findersInfo);
|
||||
int nb = _findReplaceDlg.processAll(ProcessFindAll, FindReplaceDlg::_env, isEntireDoc, &findersInfo);
|
||||
|
||||
if (nb == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{
|
||||
hasInvalidRegExpr = true;
|
||||
break;
|
||||
}
|
||||
|
||||
nbTotal += nb;
|
||||
|
||||
if (closeBuf)
|
||||
MainFileManager.closeBuffer(id, _pEditView);
|
||||
|
@ -2183,7 +2232,13 @@ bool Notepad_plus::findInFilelist(std::vector<generic_string> & fileNames)
|
|||
|
||||
_findReplaceDlg.putFindResult(nbTotal);
|
||||
|
||||
if (nbTotal != 0)
|
||||
if (hasInvalidRegExpr)
|
||||
{
|
||||
_findReplaceDlg.setStatusbarMessageWithRegExprErr(&_invisibleEditView);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nbTotal > 0)
|
||||
{
|
||||
NppParameters& nppParam = NppParameters::getInstance();
|
||||
NppGUI& nppGui = nppParam.getNppGUI();
|
||||
|
@ -2207,6 +2262,7 @@ bool Notepad_plus::findInOpenedFiles()
|
|||
Buffer * pBuf = NULL;
|
||||
|
||||
const bool isEntireDoc = true;
|
||||
bool hasInvalidRegExpr = false;
|
||||
|
||||
_findReplaceDlg.beginNewFilesSearch();
|
||||
|
||||
|
@ -2222,13 +2278,22 @@ bool Notepad_plus::findInOpenedFiles()
|
|||
FindersInfo findersInfo;
|
||||
findersInfo._pFileName = pBuf->getFullPathName();
|
||||
|
||||
nbTotal += _findReplaceDlg.processAll(ProcessFindAll, FindReplaceDlg::_env, isEntireDoc, &findersInfo);
|
||||
int nb = _findReplaceDlg.processAll(ProcessFindAll, FindReplaceDlg::_env, isEntireDoc, &findersInfo);
|
||||
if (nb == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{
|
||||
hasInvalidRegExpr = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
nbTotal += nb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t nbUniqueBuffers = _mainDocTab.nbItem();
|
||||
|
||||
if (_mainWindowStatus & WindowSubActive)
|
||||
if (!hasInvalidRegExpr && (_mainWindowStatus & WindowSubActive))
|
||||
{
|
||||
for (size_t i = 0, len2 = _subDocTab.nbItem(); i < len2 ; ++i)
|
||||
{
|
||||
|
@ -2244,7 +2309,16 @@ bool Notepad_plus::findInOpenedFiles()
|
|||
FindersInfo findersInfo;
|
||||
findersInfo._pFileName = pBuf->getFullPathName();
|
||||
|
||||
nbTotal += _findReplaceDlg.processAll(ProcessFindAll, FindReplaceDlg::_env, isEntireDoc, &findersInfo);
|
||||
int nb = _findReplaceDlg.processAll(ProcessFindAll, FindReplaceDlg::_env, isEntireDoc, &findersInfo);
|
||||
if (nb == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{
|
||||
hasInvalidRegExpr = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
nbTotal += nb;
|
||||
}
|
||||
|
||||
++nbUniqueBuffers;
|
||||
}
|
||||
|
@ -2257,7 +2331,13 @@ bool Notepad_plus::findInOpenedFiles()
|
|||
|
||||
_findReplaceDlg.putFindResult(nbTotal);
|
||||
|
||||
if (nbTotal != 0)
|
||||
if (hasInvalidRegExpr)
|
||||
{
|
||||
_findReplaceDlg.setStatusbarMessageWithRegExprErr(&_invisibleEditView);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nbTotal > 0)
|
||||
{
|
||||
NppParameters& nppParam = NppParameters::getInstance();
|
||||
NppGUI& nppGui = nppParam.getNppGUI();
|
||||
|
@ -2305,7 +2385,17 @@ bool Notepad_plus::findInCurrentFile(bool isEntireDoc)
|
|||
|
||||
FindersInfo findersInfo;
|
||||
findersInfo._pFileName = pBuf->getFullPathName();
|
||||
nbTotal += _findReplaceDlg.processAll(ProcessFindAll, FindReplaceDlg::_env, isEntireDoc, &findersInfo);
|
||||
bool hasInvalidRegExpr = false;
|
||||
|
||||
int nb = _findReplaceDlg.processAll(ProcessFindAll, FindReplaceDlg::_env, isEntireDoc, &findersInfo);
|
||||
if (nb == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{
|
||||
hasInvalidRegExpr = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
nbTotal += nb;
|
||||
}
|
||||
|
||||
_findReplaceDlg.finishFilesSearch(nbTotal, 1, isEntireDoc);
|
||||
|
||||
|
@ -2314,7 +2404,13 @@ bool Notepad_plus::findInCurrentFile(bool isEntireDoc)
|
|||
|
||||
_findReplaceDlg.putFindResult(nbTotal);
|
||||
|
||||
if (nbTotal != 0)
|
||||
if (hasInvalidRegExpr)
|
||||
{
|
||||
_findReplaceDlg.setStatusbarMessageWithRegExprErr(&_invisibleEditView);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nbTotal > 0)
|
||||
{
|
||||
NppParameters& nppParam = NppParameters::getInstance();
|
||||
NppGUI& nppGui = nppParam.getNppGUI();
|
||||
|
|
|
@ -1715,7 +1715,7 @@ BufferID FileManager::getBufferFromName(const TCHAR* name)
|
|||
{
|
||||
if (OrdinalIgnoreCaseCompareStrings(name, buf->getFullPathName()) == 0)
|
||||
{
|
||||
if (buf->_referees[0]->isVisible())
|
||||
if (!(buf->_referees.empty()) && buf->_referees[0]->isVisible())
|
||||
{
|
||||
return buf->getID();
|
||||
}
|
||||
|
|
|
@ -1970,14 +1970,15 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
|
|||
(*_ppEditView)->execute(SCI_ENDUNDOACTION);
|
||||
nppParamInst._isFindReplacing = false;
|
||||
|
||||
generic_string result;
|
||||
|
||||
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
|
||||
if (nbReplaced < 0)
|
||||
if (nbReplaced == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-replaceall-re-malformed", TEXT("Replace All: The regular expression is malformed."));
|
||||
setStatusbarMessageWithRegExprErr(*_ppEditView);
|
||||
}
|
||||
else
|
||||
{
|
||||
wstring result;
|
||||
if (nbReplaced == 1)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-replaceall-1-replaced", TEXT("Replace All: 1 occurrence was replaced"));
|
||||
|
@ -1989,8 +1990,9 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
|
|||
}
|
||||
result += TEXT(" ");
|
||||
result += getScopeInfoForStatusBar(&_options);
|
||||
|
||||
setStatusbarMessage(result, FSMessage);
|
||||
}
|
||||
setStatusbarMessage(result, FSMessage);
|
||||
getFocus();
|
||||
}
|
||||
}
|
||||
|
@ -2007,29 +2009,32 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
|
|||
|
||||
int nbCounted = processAll(ProcessCountAll, &_options);
|
||||
|
||||
generic_string result;
|
||||
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
|
||||
if (nbCounted < 0)
|
||||
if (nbCounted == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-count-re-malformed", TEXT("Count: The regular expression to search is malformed."));
|
||||
setStatusbarMessageWithRegExprErr(*_ppEditView);
|
||||
}
|
||||
else
|
||||
{
|
||||
wstring result;
|
||||
if (nbCounted == 1)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-count-1-match", TEXT("Count: 1 match"));
|
||||
}
|
||||
else
|
||||
else //if (nbCounted == 0 || nbCounted > 1)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-count-nb-matches", TEXT("Count: $INT_REPLACE$ matches"));
|
||||
result = stringReplace(result, TEXT("$INT_REPLACE$"), std::to_wstring(nbCounted));
|
||||
}
|
||||
result += TEXT(" ");
|
||||
result += getScopeInfoForStatusBar(&_options);
|
||||
|
||||
setStatusbarMessage(result, FSMessage);
|
||||
}
|
||||
|
||||
if (isMacroRecording) saveInMacro(wParam, FR_OP_FIND);
|
||||
setStatusbarMessage(result, FSMessage);
|
||||
if (isMacroRecording)
|
||||
saveInMacro(wParam, FR_OP_FIND);
|
||||
|
||||
getFocus();
|
||||
}
|
||||
}
|
||||
|
@ -2049,27 +2054,30 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
|
|||
int nbMarked = processAll(ProcessMarkAll, &_options);
|
||||
nppParamInst._isFindReplacing = false;
|
||||
|
||||
generic_string result;
|
||||
|
||||
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
|
||||
if (nbMarked < 0)
|
||||
if (nbMarked == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-mark-re-malformed", TEXT("Mark: The regular expression to search is malformed."));
|
||||
setStatusbarMessageWithRegExprErr(*_ppEditView);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstring result;
|
||||
if (nbMarked == 1)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-mark-1-match", TEXT("Mark: 1 match"));
|
||||
}
|
||||
else
|
||||
else //if (nbMarked == 0 || nbMarked > 1)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-mark-nb-matches", TEXT("Mark: $INT_REPLACE$ matches"));
|
||||
result = stringReplace(result, TEXT("$INT_REPLACE$"), std::to_wstring(nbMarked));
|
||||
}
|
||||
result += TEXT(" ");
|
||||
result += getScopeInfoForStatusBar(&_options);
|
||||
|
||||
setStatusbarMessage(result, FSMessage);
|
||||
}
|
||||
setStatusbarMessage(result, FSMessage);
|
||||
|
||||
getFocus();
|
||||
}
|
||||
}
|
||||
|
@ -2498,22 +2506,9 @@ bool FindReplaceDlg::processFindNext(const TCHAR *txt2find, const FindOption *op
|
|||
return false;
|
||||
}
|
||||
}
|
||||
else if (posFind < -1)
|
||||
else if (posFind == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{ // error
|
||||
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
|
||||
generic_string msgGeneral;
|
||||
if (posFind == -2)
|
||||
{
|
||||
msgGeneral = pNativeSpeaker->getLocalizedStrFromID("find-status-invalid-re", TEXT("Find: Invalid regular expression"));
|
||||
}
|
||||
else
|
||||
{
|
||||
msgGeneral = pNativeSpeaker->getLocalizedStrFromID("find-status-search-failed", TEXT("Find: Search failed"));
|
||||
}
|
||||
|
||||
char szMsg [511] = "";
|
||||
(*_ppEditView)->execute (SCI_GETBOOSTREGEXERRMSG, _countof (szMsg), reinterpret_cast<LPARAM>(szMsg));
|
||||
setStatusbarMessage(msgGeneral, FSNotFound, szMsg);
|
||||
setStatusbarMessageWithRegExprErr(*_ppEditView);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2644,7 +2639,9 @@ bool FindReplaceDlg::processReplace(const TCHAR *txt2find, const TCHAR *txt2repl
|
|||
{
|
||||
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
|
||||
generic_string msg = pNativeSpeaker->getLocalizedStrFromID("find-status-replace-not-found", TEXT("Replace: no occurrence was found."));
|
||||
setStatusbarMessage(msg, FSNotFound);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return moreMatches;
|
||||
|
@ -2744,6 +2741,9 @@ int FindReplaceDlg::processAll(ProcessOperation op, const FindOption *opt, bool
|
|||
|
||||
int nbProcessed = processRange(op, findReplaceInfo, pFindersInfo, pOptions, colourStyleID);
|
||||
|
||||
if (nbProcessed == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
return FIND_INVALID_REGULAR_EXPRESSION;
|
||||
|
||||
if (nbProcessed > 0 && op == ProcessReplaceAll && pOptions->_isInSelection)
|
||||
{
|
||||
size_t newDocLength = (*_ppEditView)->execute(SCI_GETLENGTH);
|
||||
|
@ -2869,9 +2869,12 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
|
|||
targetStart = pEditView->searchInTarget(pTextFind, stringSizeFind, findReplaceInfo._startRange, findReplaceInfo._endRange);
|
||||
|
||||
// If we've not found anything, just break out of the loop
|
||||
if (targetStart == -1 || targetStart == -2)
|
||||
if (targetStart == -1)
|
||||
break;
|
||||
|
||||
if (targetStart == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
return FIND_INVALID_REGULAR_EXPRESSION;
|
||||
|
||||
targetEnd = pEditView->execute(SCI_GETTARGETEND);
|
||||
|
||||
if (targetEnd > findReplaceInfo._endRange)
|
||||
|
@ -3649,6 +3652,20 @@ void FindReplaceDlg::setStatusbarMessage(const generic_string & msg, FindStatus
|
|||
}
|
||||
}
|
||||
|
||||
void FindReplaceDlg::setStatusbarMessageWithRegExprErr(ScintillaEditView* pEditView)
|
||||
{
|
||||
if (!pEditView)
|
||||
return;
|
||||
|
||||
char msg[511] {};
|
||||
pEditView->execute(SCI_GETBOOSTREGEXERRMSG, _countof(msg), reinterpret_cast<LPARAM>(msg));
|
||||
|
||||
NativeLangSpeaker* pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
|
||||
std::wstring result = pNativeSpeaker->getLocalizedStrFromID("find-status-invalid-re", TEXT("Find: Invalid Regular Expression"));
|
||||
|
||||
setStatusbarMessage(result, FSNotFound, msg);
|
||||
}
|
||||
|
||||
generic_string FindReplaceDlg::getScopeInfoForStatusBar(FindOption const *pFindOpt) const
|
||||
{
|
||||
generic_string scope;
|
||||
|
@ -3838,42 +3855,46 @@ void FindReplaceDlg::execSavedCommand(int cmd, uptr_t intValue, const generic_st
|
|||
(*_ppEditView)->execute(SCI_ENDUNDOACTION);
|
||||
nppParamInst._isFindReplacing = false;
|
||||
|
||||
generic_string result;
|
||||
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
|
||||
if (nbReplaced < 0)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-replaceall-re-malformed", TEXT("Replace All: The regular expression is malformed."));
|
||||
if (nbReplaced == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{
|
||||
setStatusbarMessageWithRegExprErr(*_ppEditView);
|
||||
}
|
||||
else
|
||||
{
|
||||
wstring result;
|
||||
NativeLangSpeaker* pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
|
||||
|
||||
if (nbReplaced == 1)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-replaceall-1-replaced", TEXT("Replace All: 1 occurrence was replaced"));
|
||||
}
|
||||
else
|
||||
else //if (nbReplaced == 0 || nbReplaced > 1)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-replaceall-nb-replaced", TEXT("Replace All: $INT_REPLACE$ occurrences were replaced"));
|
||||
result = stringReplace(result, TEXT("$INT_REPLACE$"), std::to_wstring(nbReplaced));
|
||||
}
|
||||
result += TEXT(" ");
|
||||
result += getScopeInfoForStatusBar(_env);
|
||||
|
||||
setStatusbarMessage(result, FSMessage);
|
||||
}
|
||||
|
||||
setStatusbarMessage(result, FSMessage);
|
||||
break;
|
||||
}
|
||||
|
||||
case IDCCOUNTALL:
|
||||
{
|
||||
int nbCounted = processAll(ProcessCountAll, _env);
|
||||
generic_string result;
|
||||
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
|
||||
if (nbCounted < 0)
|
||||
|
||||
if (nbCounted == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-count-re-malformed", TEXT("Count: The regular expression to search is malformed."));
|
||||
setStatusbarMessageWithRegExprErr(*_ppEditView);
|
||||
}
|
||||
else
|
||||
{
|
||||
wstring result;
|
||||
NativeLangSpeaker* pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
|
||||
|
||||
if (nbCounted == 1)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-count-1-match", TEXT("Count: 1 match"));
|
||||
|
@ -3885,8 +3906,9 @@ void FindReplaceDlg::execSavedCommand(int cmd, uptr_t intValue, const generic_st
|
|||
}
|
||||
result += TEXT(" ");
|
||||
result += getScopeInfoForStatusBar(_env);
|
||||
|
||||
setStatusbarMessage(result, FSMessage);
|
||||
}
|
||||
setStatusbarMessage(result, FSMessage);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -3895,15 +3917,15 @@ void FindReplaceDlg::execSavedCommand(int cmd, uptr_t intValue, const generic_st
|
|||
nppParamInst._isFindReplacing = true;
|
||||
int nbMarked = processAll(ProcessMarkAll, _env);
|
||||
nppParamInst._isFindReplacing = false;
|
||||
generic_string result;
|
||||
|
||||
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
|
||||
if (nbMarked < 0)
|
||||
if (nbMarked == FIND_INVALID_REGULAR_EXPRESSION)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-mark-re-malformed", TEXT("Mark: The regular expression to search is malformed."));
|
||||
setStatusbarMessageWithRegExprErr(*_ppEditView);
|
||||
}
|
||||
else
|
||||
{
|
||||
wstring result;
|
||||
NativeLangSpeaker* pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
|
||||
if (nbMarked == 1)
|
||||
{
|
||||
result = pNativeSpeaker->getLocalizedStrFromID("find-status-mark-1-match", TEXT("Mark: 1 match"));
|
||||
|
@ -3915,9 +3937,10 @@ void FindReplaceDlg::execSavedCommand(int cmd, uptr_t intValue, const generic_st
|
|||
}
|
||||
result += TEXT(" ");
|
||||
result += getScopeInfoForStatusBar(_env);
|
||||
|
||||
setStatusbarMessage(result, FSMessage);
|
||||
}
|
||||
|
||||
setStatusbarMessage(result, FSMessage);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#define FIND_RECURSIVE 1
|
||||
#define FIND_INHIDDENDIR 2
|
||||
|
||||
#define FIND_INVALID_REGULAR_EXPRESSION -2
|
||||
|
||||
#define FINDREPLACE_MAXLENGTH 2048
|
||||
#define FINDREPLACE_INSEL_TEXTSIZE_THRESHOLD 1024
|
||||
|
||||
|
@ -386,6 +388,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 setStatusbarMessageWithRegExprErr(ScintillaEditView* pEditView);
|
||||
generic_string getScopeInfoForStatusBar(FindOption const *pFindOpt) const;
|
||||
Finder * createFinder();
|
||||
bool removeFinder(Finder *finder2remove);
|
||||
|
@ -425,7 +428,7 @@ private :
|
|||
RECT _collapseButtonPos = {};
|
||||
RECT _uncollapseButtonPos = {};
|
||||
|
||||
ScintillaEditView **_ppEditView = nullptr;
|
||||
ScintillaEditView** _ppEditView = nullptr;
|
||||
Finder *_pFinder = nullptr;
|
||||
generic_string _findResTitle;
|
||||
|
||||
|
|
Loading…
Reference in New Issue