Add an non-UI option to allow regEx backward search

Set "regexBackward4PowerUser" to "yes" in config.xml to eanable this option.
This commit is contained in:
Don HO 2020-06-05 00:56:25 +02:00
parent 766a380325
commit 5e262c8122
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
4 changed files with 29 additions and 11 deletions

View File

@ -1025,7 +1025,8 @@ void Notepad_plus::command(int id)
if (_findReplaceDlg.isCreated())
{
FindOption op = _findReplaceDlg.getCurrentOptions();
if ((id == IDM_SEARCH_FINDPREV) && (op._searchType == FindRegex))
NppParameters& nppParams = NppParameters::getInstance();
if ((id == IDM_SEARCH_FINDPREV) && (op._searchType == FindRegex) && !nppParams.regexBackward4PowerUser())
{
// regex upward search is disabled
// make this a no-action command

View File

@ -2374,6 +2374,10 @@ void NppParameters::feedFindHistoryParameters(TiXmlNode *node)
boolStr = (findHistoryRoot->ToElement())->Attribute(TEXT("isSearch2ButtonsMode"));
if (boolStr)
_findHistory._isSearch2ButtonsMode = (lstrcmp(TEXT("yes"), boolStr) == 0);
boolStr = (findHistoryRoot->ToElement())->Attribute(TEXT("regexBackward4PowerUser"));
if (boolStr)
_findHistory._regexBackward4PowerUser = (lstrcmp(TEXT("yes"), boolStr) == 0);
}
void NppParameters::feedShortcut(TiXmlNode *node)
@ -5994,6 +5998,7 @@ bool NppParameters::writeFindHistory()
(findHistoryRoot->ToElement())->SetAttribute(TEXT("transparency"), _findHistory._transparency);
(findHistoryRoot->ToElement())->SetAttribute(TEXT("dotMatchesNewline"), _findHistory._dotMatchesNewline?TEXT("yes"):TEXT("no"));
(findHistoryRoot->ToElement())->SetAttribute(TEXT("isSearch2ButtonsMode"), _findHistory._isSearch2ButtonsMode?TEXT("yes"):TEXT("no"));
(findHistoryRoot->ToElement())->SetAttribute(TEXT("regexBackward4PowerUser"), _findHistory._regexBackward4PowerUser ? TEXT("yes") : TEXT("no"));
TiXmlElement hist_element{TEXT("")};

View File

@ -1171,6 +1171,9 @@ struct FindHistory final
bool _isDlgAlwaysVisible = false;
bool _isFilterFollowDoc = false;
bool _isFolderFollowDoc = false;
// Allow regExpr backward search: this option is not present in UI, only to modify in config.xml
bool _regexBackward4PowerUser = false;
};
@ -1747,6 +1750,7 @@ public:
void setShortcutDirty() { _isAnyShortcutModified = true; };
void setAdminMode(bool isAdmin) { _isAdminMode = isAdmin; }
bool isAdmin() const { return _isAdminMode; }
bool regexBackward4PowerUser() const { return _findHistory._regexBackward4PowerUser; }
private:
bool _isAnyShortcutModified = false;

View File

@ -344,8 +344,8 @@ void FindReplaceDlg::fillFindHistory()
// regex upward search is disabled
::SendDlgItemMessage(_hSelf, IDC_BACKWARDDIRECTION, BM_SETCHECK, BST_UNCHECKED, 0);
::EnableWindow(::GetDlgItem(_hSelf, IDC_BACKWARDDIRECTION), (BOOL)false);
::EnableWindow(::GetDlgItem(_hSelf, IDC_FINDPREV), (BOOL)false);
::EnableWindow(::GetDlgItem(_hSelf, IDC_BACKWARDDIRECTION), nppParams.regexBackward4PowerUser() ? TRUE : FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDC_FINDPREV), nppParams.regexBackward4PowerUser() ? TRUE : FALSE);
// If the search mode from history is regExp then enable the checkbox (. matches newline)
::EnableWindow(GetDlgItem(_hSelf, IDREDOTMATCHNL), true);
@ -1063,7 +1063,7 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
}
}
if ((_options._whichDirection == DIR_UP) && (_options._searchType == FindRegex))
if ((_options._whichDirection == DIR_UP) && (_options._searchType == FindRegex) && !nppParamInst.regexBackward4PowerUser())
{
// this can only happen when shift-key was pressed
// regex upward search is disabled
@ -1421,15 +1421,23 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
::SendDlgItemMessage(_hSelf, IDWHOLEWORD, BM_SETCHECK, _options._isWholeWord?BST_CHECKED:BST_UNCHECKED, 0);
//regex upward search is disabled
::SendDlgItemMessage(_hSelf, IDC_BACKWARDDIRECTION, BM_SETCHECK, BST_UNCHECKED, 0);
_options._whichDirection = DIR_DOWN;
if (!nppParamInst.regexBackward4PowerUser())
{
::SendDlgItemMessage(_hSelf, IDC_BACKWARDDIRECTION, BM_SETCHECK, BST_UNCHECKED, 0);
_options._whichDirection = DIR_DOWN;
}
}
::EnableWindow(::GetDlgItem(_hSelf, IDWHOLEWORD), (BOOL)!isRegex);
// regex upward search is disabled
::EnableWindow(::GetDlgItem(_hSelf, IDC_BACKWARDDIRECTION), (BOOL)!isRegex);
::EnableWindow(::GetDlgItem(_hSelf, IDC_FINDPREV), (BOOL)!isRegex);
BOOL doEnable = TRUE;
if (isRegex && !nppParamInst.regexBackward4PowerUser())
{
doEnable = FALSE;
}
::EnableWindow(::GetDlgItem(_hSelf, IDC_BACKWARDDIRECTION), doEnable);
::EnableWindow(::GetDlgItem(_hSelf, IDC_FINDPREV), doEnable);
return TRUE; }
@ -2687,7 +2695,7 @@ void FindReplaceDlg::execSavedCommand(int cmd, uptr_t intValue, const generic_st
switch (intValue)
{
case IDOK:
if ((_env->_whichDirection == DIR_UP) && (_env->_searchType == FindRegex))
if ((_env->_whichDirection == DIR_UP) && (_env->_searchType == FindRegex) && !nppParamInst.regexBackward4PowerUser())
{
// regex upward search is disabled
// this macro step could have been recorded in an earlier version before it was not allowed, or hand-edited
@ -2713,7 +2721,7 @@ void FindReplaceDlg::execSavedCommand(int cmd, uptr_t intValue, const generic_st
case IDC_FINDPREV:
// IDC_FINDPREV will not be recorded into new macros recorded with 7.8.5 and later
// stay playback compatible with 7.5.5 - 7.8.4 where IDC_FINDPREV was allowed but unneeded/undocumented
if (_env->_searchType == FindRegex)
if (_env->_searchType == FindRegex && !nppParamInst.regexBackward4PowerUser())
{
// regex upward search is disabled
// this macro step could have been recorded in an earlier version before it was not allowed, or hand-edited
@ -2729,7 +2737,7 @@ void FindReplaceDlg::execSavedCommand(int cmd, uptr_t intValue, const generic_st
break;
case IDREPLACE:
if ((_env->_whichDirection == DIR_UP) && (_env->_searchType == FindRegex))
if ((_env->_whichDirection == DIR_UP) && (_env->_searchType == FindRegex && !nppParamInst.regexBackward4PowerUser()))
{
// regex upward search is disabled
// this macro step could have been recorded in an earlier version before it was disabled, or hand-edited