+chg: F/R Dialog and f/r pattern handling

This commit is contained in:
METANEOCORTEX\Kotti 2021-09-22 03:14:37 +02:00
parent e890580d16
commit 347a77af89
7 changed files with 4648 additions and 4538 deletions

File diff suppressed because it is too large Load Diff

View File

@ -92,7 +92,7 @@ void SetWindowReadingRTL(HWND hwnd, bool bRTL);
UINT ComboBox_GetTextLengthEx(HWND hDlg, int nIDDlgItem);
UINT ComboBox_GetCurSelEx(HWND hDlg, int nIDDlgItem);
UINT ComboBox_GetTextW2MB(HWND hDlg, int nIDDlgItem, LPSTR lpString, int nMaxCount);
int ComboBox_GetTextW2MB(HWND hDlg, int nIDDlgItem, LPSTR lpString, size_t cch);
void ComboBox_SetTextMB2W(HWND hDlg, int nIDDlgItem, LPCSTR lpString);
//void ComboBox_AddStringMB2W(HWND hDlg, int nIDDlgItem, LPCSTR lpString);

View File

@ -30,6 +30,7 @@
#include "crypto/crypto.h"
#include "uthash/utarray.h"
#include "uthash/utlist.h"
#include "uthash/utstring.h"
#include "tinyexpr/tinyexpr.h"
#include "Encoding.h"
#include "MuiLanguage.h"
@ -2064,23 +2065,31 @@ void EditEscapeCChars(HWND hwnd) {
}
EDITFINDREPLACE efr = INIT_EFR_DATA;
utstring_new(efr.chFindPattern);
utstring_new(efr.chReplaceTemplate);
efr.hwnd = hwnd;
UndoTransActionBegin();
StringCchCopyA(efr.chFindPattern, COUNTOF(efr.chFindPattern), "\\");
StringCchCopyA(efr.chReplaceTemplate, COUNTOF(efr.chReplaceTemplate), "\\\\");
utstring_bincpy(efr.chFindPattern, "\\", strlen("\\"));
utstring_bincpy(efr.chReplaceTemplate, "\\\\", strlen("\\\\"));
EditReplaceAllInSelection(hwnd, &efr, false);
StringCchCopyA(efr.chFindPattern, COUNTOF(efr.chFindPattern), "\"");
StringCchCopyA(efr.chReplaceTemplate, COUNTOF(efr.chReplaceTemplate), "\\\"");
utstring_clear(efr.chFindPattern);
utstring_bincpy(efr.chFindPattern, "\"", strlen("\""));
utstring_clear(efr.chReplaceTemplate);
utstring_bincpy(efr.chReplaceTemplate, "\\\"", strlen("\\\""));
EditReplaceAllInSelection(hwnd, &efr, false);
StringCchCopyA(efr.chFindPattern, COUNTOF(efr.chFindPattern), "\'");
StringCchCopyA(efr.chReplaceTemplate, COUNTOF(efr.chReplaceTemplate), "\\\'");
utstring_clear(efr.chFindPattern);
utstring_bincpy(efr.chFindPattern, "\'", strlen("\'"));
utstring_clear(efr.chReplaceTemplate);
utstring_bincpy(efr.chReplaceTemplate, "\\\'", strlen("\\\'"));
EditReplaceAllInSelection(hwnd, &efr, false);
EndUndoTransAction();
ReleaseEFR(&efr);
}
@ -2099,23 +2108,31 @@ void EditUnescapeCChars(HWND hwnd) {
}
EDITFINDREPLACE efr = INIT_EFR_DATA;
utstring_new(efr.chFindPattern);
utstring_new(efr.chReplaceTemplate);
efr.hwnd = hwnd;
UndoTransActionBegin();
StringCchCopyA(efr.chFindPattern, FNDRPL_BUFFER, "\\\\");
StringCchCopyA(efr.chReplaceTemplate, FNDRPL_BUFFER, "\\");
utstring_bincpy(efr.chFindPattern, "\\\\", strlen("\\\\"));
utstring_bincpy(efr.chReplaceTemplate, "\\", strlen("\\"));
EditReplaceAllInSelection(hwnd, &efr, false);
StringCchCopyA(efr.chFindPattern, FNDRPL_BUFFER, "\\\"");
StringCchCopyA(efr.chReplaceTemplate, FNDRPL_BUFFER, "\"");
utstring_clear(efr.chFindPattern);
utstring_bincpy(efr.chFindPattern, "\\\"", strlen("\\\""));
utstring_clear(efr.chReplaceTemplate);
utstring_bincpy(efr.chReplaceTemplate, "\"", strlen("\""));
EditReplaceAllInSelection(hwnd, &efr, false);
StringCchCopyA(efr.chFindPattern, FNDRPL_BUFFER, "\\\'");
StringCchCopyA(efr.chReplaceTemplate, FNDRPL_BUFFER, "\'");
utstring_clear(efr.chFindPattern);
utstring_bincpy(efr.chFindPattern, "\\\'", strlen("\\\'"));
utstring_clear(efr.chReplaceTemplate);
utstring_bincpy(efr.chReplaceTemplate, "\'", strlen("\'"));
EditReplaceAllInSelection(hwnd, &efr, false);
EndUndoTransAction();
ReleaseEFR(&efr);
}
@ -2478,16 +2495,21 @@ void EditUpdateTimestamps()
_GetCurrentTimeStamp(wchReplaceStrg, COUNTOF(wchReplaceStrg), true); // DateTimeFormat
EDITFINDREPLACE efrTS_L = INIT_EFR_DATA;
utstring_new(efrTS_L.chFindPattern);
utstring_new(efrTS_L.chReplaceTemplate);
efrTS_L.hwnd = Globals.hwndEdit;
efrTS_L.fuFlags = (SCFIND_REGEXP | SCFIND_POSIX);
WideCharToMultiByte(Encoding_SciCP, 0, Settings2.TimeStampRegEx, -1, efrTS_L.chFindPattern, COUNTOF(efrTS_L.chFindPattern), NULL, NULL);
WideCharToMultiByte(Encoding_SciCP, 0, wchReplaceStrg, -1, efrTS_L.chReplaceTemplate, COUNTOF(efrTS_L.chReplaceTemplate), NULL, NULL);
utstring_setw(efrTS_L.chFindPattern, Settings2.TimeStampRegEx);
utstring_setw(efrTS_L.chReplaceTemplate, wchReplaceStrg);
if (!SciCall_IsSelectionEmpty()) {
EditReplaceAllInSelection(Globals.hwndEdit, &efrTS_L, true);
} else {
EditReplaceAll(Globals.hwndEdit, &efrTS_L, true);
}
ReleaseEFR(&efrTS_L);
}
@ -5434,14 +5456,16 @@ static void _SetSearchFlags(HWND hwnd, LPEDITFINDREPLACE lpefr)
bool bIsFindDlg = (GetDlgItem(Globals.hwndDlgFindReplace, IDC_REPLACE) == NULL);
ComboBox_GetTextW2MB(hwnd, IDC_FINDTEXT, szBuf, COUNTOF(szBuf));
if (StringCchCompareXA(szBuf, lpefr->chFindPattern) != 0) {
StringCchCopyA(lpefr->chFindPattern, COUNTOF(lpefr->chFindPattern), szBuf);
if (StringCchCompareXA(szBuf, utstring_body(lpefr->chFindPattern)) != 0) {
utstring_clear(lpefr->chFindPattern);
utstring_bincpy(lpefr->chFindPattern, szBuf, strlen(szBuf));
lpefr->bStateChanged = true;
}
ComboBox_GetTextW2MB(hwnd, IDC_REPLACETEXT, szBuf, COUNTOF(szBuf));
if (StringCchCompareXA(szBuf, lpefr->chReplaceTemplate) != 0) {
StringCchCopyA(lpefr->chReplaceTemplate, COUNTOF(lpefr->chReplaceTemplate), szBuf);
if (StringCchCompareXA(szBuf, utstring_body(lpefr->chReplaceTemplate)) != 0) {
utstring_clear(lpefr->chReplaceTemplate);
utstring_bincpy(lpefr->chReplaceTemplate, szBuf, strlen(szBuf));
lpefr->bStateChanged = true;
}
@ -5671,8 +5695,8 @@ static size_t _EditGetFindStrg(HWND hwnd, LPEDITFINDREPLACE lpefr, LPSTR szFind,
if (!lpefr) {
return 0;
}
if (!StrIsEmptyA(lpefr->chFindPattern)) {
StringCchCopyA(szFind, cchCnt, lpefr->chFindPattern);
if (!utstring_is_empty(lpefr->chFindPattern)) {
StringCchCopyA(szFind, cchCnt, utstring_body(lpefr->chFindPattern));
} else {
CopyFindPatternMB(szFind, cchCnt);
}
@ -5697,7 +5721,8 @@ static size_t _EditGetFindStrg(HWND hwnd, LPEDITFINDREPLACE lpefr, LPSTR szFind,
}
// ensure to F/R-dialog data structure consistency
StringCchCopyA(lpefr->chFindPattern, COUNTOF(lpefr->chFindPattern), szFind);
utstring_clear(lpefr->chFindPattern);
utstring_bincpy(lpefr->chFindPattern, szFind, strlen(szFind));
if (!StrIsEmptyA(szFind) && lpefr->bWildcardSearch) {
_EscapeWildcards(szFind, cchCnt, lpefr);
@ -5905,8 +5930,8 @@ extern int g_flagMatchText;
static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
static EDITFINDREPLACE s_efrSave = INIT_EFR_DATA;
static LPEDITFINDREPLACE s_pEfrDataDlg = NULL;
static LPEDITFINDREPLACE s_pEfrData = NULL;
static bool s_bIsReplaceDlg = false;
static UINT_PTR pTimerIdentifier = 0;
@ -5939,9 +5964,9 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
// clear cmd line stuff
g_flagMatchText = 0;
s_pEfrDataDlg = NULL;
s_pEfrData = NULL;
// the global static Find/Replace data structure
// the global static Find/Replace data structure (main)
SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam);
SetDialogIconNP3(hwnd);
@ -5973,7 +5998,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
EditSetCaretToSelectionStart(); // avoid search text selection jumps to next match (before ResizeDlg_InitX())
s_pEfrDataDlg = (LPEDITFINDREPLACE)GetWindowLongPtr(hwnd, DWLP_USER);
s_pEfrData = (LPEDITFINDREPLACE)GetWindowLongPtr(hwnd, DWLP_USER);
Globals.iReplacedOccurrences = 0;
Globals.FindReplaceMatchFoundState = FND_NOP;
@ -6002,8 +6027,8 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
}
if (!GetWindowTextLengthW(GetDlgItem(hwnd, IDC_FINDTEXT))) {
if (!StrIsEmptyA(s_pEfrDataDlg->chFindPattern)) {
ComboBox_SetTextMB2W(hwnd, IDC_FINDTEXT, s_pEfrDataDlg->chFindPattern);
if (!utstring_is_empty(s_pEfrData->chFindPattern)) {
ComboBox_SetTextMB2W(hwnd, IDC_FINDTEXT, utstring_body(s_pEfrData->chFindPattern));
}
}
@ -6025,66 +6050,60 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
SHAutoComplete(cbInfoR.hwndItem, SHACF_FILESYS_ONLY | SHACF_AUTOAPPEND_FORCE_OFF | SHACF_AUTOSUGGEST_FORCE_OFF);
}
if (!StrIsEmptyA(s_pEfrDataDlg->chReplaceTemplate)) {
ComboBox_SetTextMB2W(hwnd, IDC_REPLACETEXT, s_pEfrDataDlg->chReplaceTemplate);
if (!utstring_is_empty(s_pEfrData->chReplaceTemplate)) {
ComboBox_SetTextMB2W(hwnd, IDC_REPLACETEXT, utstring_body(s_pEfrData->chReplaceTemplate));
}
}
CheckDlgButton(hwnd, IDC_FINDREGEXP, SetBtn(s_pEfrDataDlg->bRegExprSearch));
CheckDlgButton(hwnd, IDC_FINDREGEXP, SetBtn(s_pEfrData->bRegExprSearch));
bool const bDotMatchAll = (s_pEfrDataDlg->fuFlags & SCFIND_DOT_MATCH_ALL) != 0;
CheckDlgButton(hwnd, IDC_DOT_MATCH_ALL, SetBtn(s_pEfrDataDlg->bRegExprSearch && bDotMatchAll));
DialogEnableControl(hwnd, IDC_DOT_MATCH_ALL, s_pEfrDataDlg->bRegExprSearch);
bool const bDotMatchAll = (s_pEfrData->fuFlags & SCFIND_DOT_MATCH_ALL) != 0;
CheckDlgButton(hwnd, IDC_DOT_MATCH_ALL, SetBtn(s_pEfrData->bRegExprSearch && bDotMatchAll));
DialogEnableControl(hwnd, IDC_DOT_MATCH_ALL, s_pEfrData->bRegExprSearch);
if (s_pEfrDataDlg->bRegExprSearch) {
s_pEfrDataDlg->bWildcardSearch = false;
if (s_pEfrData->bRegExprSearch) {
s_pEfrData->bWildcardSearch = false;
}
if (s_pEfrDataDlg->bWildcardSearch) {
if (s_pEfrData->bWildcardSearch) {
CheckDlgButton(hwnd, IDC_WILDCARDSEARCH, BST_CHECKED);
CheckDlgButton(hwnd, IDC_FINDREGEXP, BST_UNCHECKED);
}
// transform BS handled by regex (wildcard search based on):
CheckDlgButton(hwnd, IDC_FINDTRANSFORMBS, SetBtn(s_pEfrDataDlg->bTransformBS || s_pEfrDataDlg->bRegExprSearch || s_pEfrDataDlg->bWildcardSearch));
DialogEnableControl(hwnd, IDC_FINDTRANSFORMBS, !(s_pEfrDataDlg->bRegExprSearch || s_pEfrDataDlg->bWildcardSearch));
CheckDlgButton(hwnd, IDC_FINDTRANSFORMBS, SetBtn(s_pEfrData->bTransformBS || s_pEfrData->bRegExprSearch || s_pEfrData->bWildcardSearch));
DialogEnableControl(hwnd, IDC_FINDTRANSFORMBS, !(s_pEfrData->bRegExprSearch || s_pEfrData->bWildcardSearch));
CheckDlgButton(hwnd, IDC_ALL_OCCURRENCES, SetBtn(s_pEfrDataDlg->bMarkOccurences));
if (!s_pEfrDataDlg->bMarkOccurences) {
EditClearAllOccurrenceMarkers(s_pEfrDataDlg->hwnd);
CheckDlgButton(hwnd, IDC_ALL_OCCURRENCES, SetBtn(s_pEfrData->bMarkOccurences));
if (!s_pEfrData->bMarkOccurences) {
EditClearAllOccurrenceMarkers(s_pEfrData->hwnd);
Globals.iMarkOccurrencesCount = 0;
}
CheckDlgButton(hwnd, IDC_FINDCASE, SetBtn(s_pEfrDataDlg->fuFlags & SCFIND_MATCHCASE));
CheckDlgButton(hwnd, IDC_FINDWORD, SetBtn(s_pEfrDataDlg->fuFlags & SCFIND_WHOLEWORD));
CheckDlgButton(hwnd, IDC_FINDSTART, SetBtn(s_pEfrDataDlg->fuFlags & SCFIND_WORDSTART));
CheckDlgButton(hwnd, IDC_NOWRAP, SetBtn(s_pEfrDataDlg->bNoFindWrap));
CheckDlgButton(hwnd, IDC_FINDCASE, SetBtn(s_pEfrData->fuFlags & SCFIND_MATCHCASE));
CheckDlgButton(hwnd, IDC_FINDWORD, SetBtn(s_pEfrData->fuFlags & SCFIND_WHOLEWORD));
CheckDlgButton(hwnd, IDC_FINDSTART, SetBtn(s_pEfrData->fuFlags & SCFIND_WORDSTART));
CheckDlgButton(hwnd, IDC_NOWRAP, SetBtn(s_pEfrData->bNoFindWrap));
if (s_bIsReplaceDlg) {
if (s_bSwitchedFindReplace) {
CheckDlgButton(hwnd, IDC_FINDCLOSE, SetBtn(s_pEfrDataDlg->bFindClose));
} else {
CheckDlgButton(hwnd, IDC_FINDCLOSE, SetBtn(s_pEfrDataDlg->bReplaceClose));
}
CheckDlgButton(hwnd, IDC_FINDCLOSE, SetBtn(s_pEfrData->bReplaceClose));
} else {
if (s_bSwitchedFindReplace) {
CheckDlgButton(hwnd, IDC_FINDCLOSE, SetBtn(s_pEfrDataDlg->bReplaceClose));
} else {
CheckDlgButton(hwnd, IDC_FINDCLOSE, SetBtn(s_pEfrDataDlg->bFindClose));
}
CheckDlgButton(hwnd, IDC_FINDCLOSE, SetBtn(s_pEfrData->bFindClose));
}
CheckDlgButton(hwnd, IDC_TRANSPARENT, SetBtn(Settings.FindReplaceTransparentMode));
if (!s_bSwitchedFindReplace) {
if (Settings.FindReplaceDlgPosX == CW_USEDEFAULT || Settings.FindReplaceDlgPosY == CW_USEDEFAULT) {
CenterDlgInParent(hwnd, NULL);
} else {
SetDlgPos(hwnd, Settings.FindReplaceDlgPosX, Settings.FindReplaceDlgPosY);
}
} else {
if (s_bSwitchedFindReplace) {
// restore from prev Dlg
SetDlgPos(hwnd, s_xFindReplaceDlgSave, s_yFindReplaceDlgSave);
s_bSwitchedFindReplace = false;
CopyMemory(s_pEfrDataDlg, &s_efrSave, sizeof(EDITFINDREPLACE));
}
else {
if (Settings.FindReplaceDlgPosX == CW_USEDEFAULT || Settings.FindReplaceDlgPosY == CW_USEDEFAULT) {
CenterDlgInParent(hwnd, NULL);
}
else {
SetDlgPos(hwnd, Settings.FindReplaceDlgPosX, Settings.FindReplaceDlgPosY);
}
}
WCHAR wchMenuBuf[80] = {L'\0'};
@ -6108,10 +6127,10 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
s_anyMatch = NO_MATCH;
_SetSearchFlags(hwnd, s_pEfrDataDlg); // sync
s_pEfrDataDlg->bStateChanged = true; // force update
_SetSearchFlags(hwnd, s_pEfrData); // sync
s_pEfrData->bStateChanged = true; // force update
DialogEnableControl(hwnd, IDC_TOGGLE_VISIBILITY, s_pEfrDataDlg->bMarkOccurences);
DialogEnableControl(hwnd, IDC_TOGGLE_VISIBILITY, s_pEfrData->bMarkOccurences);
_DelayMarkAll(_MQ_STD);
@ -6129,13 +6148,13 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
KillTimer(hwnd, pTimerIdentifier);
pTimerIdentifier = 0;
_SetSearchFlags(hwnd, s_pEfrDataDlg); // sync
CopyMemory(&(Settings.EFR_Data), s_pEfrDataDlg, sizeof(EDITFINDREPLACE)); // remember options
_SetSearchFlags(hwnd, s_pEfrData); // sync
DuplicateEFR(&(Settings.EFR_Data), s_pEfrData);
if (!s_bSwitchedFindReplace) {
if (s_anyMatch == MATCH) {
// Save MRUs
if (!StrIsEmptyA(s_pEfrDataDlg->chFindPattern)) {
if (!utstring_is_empty(s_pEfrData->chFindPattern)) {
if (GetDlgItemText(hwnd, IDC_FINDTEXT, s_tchBuf, COUNTOF(s_tchBuf))) {
MRU_Add(Globals.pMRUfind, s_tchBuf, 0, -1, -1, NULL);
SetFindPattern(s_tchBuf);
@ -6151,13 +6170,13 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
EnableCmd(GetMenu(Globals.hwndMain), IDM_VIEW_MARKOCCUR_ONOFF, true);
if (FocusedView.HideNonMatchedLines) {
EditToggleView(s_pEfrDataDlg->hwnd);
EditToggleView(s_pEfrData->hwnd);
}
if (IsMarkOccurrencesEnabled()) {
MarkAllOccurrences(_MQ_STD, true);
} else {
EditClearAllOccurrenceMarkers(s_pEfrDataDlg->hwnd);
EditClearAllOccurrenceMarkers(s_pEfrData->hwnd);
Globals.iMarkOccurrencesCount = 0;
}
@ -6183,7 +6202,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
DeleteObject(hBrushRed);
DeleteObject(hBrushGreen);
DeleteObject(hBrushBlue);
s_pEfrDataDlg = NULL;
s_pEfrData = NULL;
Globals.hwndDlgFindReplace = NULL;
}
return FALSE;
@ -6233,7 +6252,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
case WM_CTLCOLOREDIT:
case WM_CTLCOLORLISTBOX: {
if (!s_pEfrDataDlg) {
if (!s_pEfrData) {
return false;
}
HWND hCheck = (HWND)lParam;
@ -6276,7 +6295,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
case WM_ACTIVATE: {
if (!s_pEfrDataDlg) {
if (!s_pEfrData) {
return false;
}
@ -6298,8 +6317,8 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
s_InitialCaretPos = SciCall_GetCurrentPos();
s_InitialTopLine = SciCall_GetFirstVisibleLine();
s_InitialSearchStart = s_InitialCaretPos;
if (s_pEfrDataDlg) {
s_pEfrDataDlg->bStateChanged = true;
if (s_pEfrData) {
s_pEfrData->bStateChanged = true;
}
}
@ -6322,7 +6341,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
case WM_COMMAND: {
if (!s_pEfrDataDlg) {
if (!s_pEfrData) {
return FALSE;
}
@ -6331,7 +6350,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
case IDC_DOC_MODIFIED:
s_InitialSearchStart = SciCall_GetSelectionStart();
s_InitialTopLine = -1; // reset
s_pEfrDataDlg->bStateChanged = true;
s_pEfrData->bStateChanged = true;
_DelayMarkAll(_MQ_STD);
break;
@ -6339,7 +6358,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
case IDC_FINDTEXT:
case IDC_REPLACETEXT: {
bool bFndPatternChanged = s_pEfrDataDlg->bStateChanged;
bool bFndPatternChanged = s_pEfrData->bStateChanged;
switch (HIWORD(wParam)) {
@ -6367,10 +6386,11 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
case CBN_SELENDOK:
case CBN_EDITCHANGE:
bFndPatternChanged = (LOWORD(wParam) == IDC_FINDTEXT);
LPSTR const buffer = bFndPatternChanged ? s_pEfrDataDlg->chFindPattern : s_pEfrDataDlg->chReplaceTemplate;
ComboBox_GetTextW2MB(hwnd, LOWORD(wParam), buffer, FNDRPL_BUFFER);
UT_string* const buffer = bFndPatternChanged ? s_pEfrData->chFindPattern : s_pEfrData->chReplaceTemplate;
utstring_reserve(buffer, FNDRPL_BUFFER);
ComboBox_GetTextW2MB(hwnd, LOWORD(wParam), utstring_body(buffer), (int)utstring_alloc_len(buffer));
if (bFndPatternChanged) {
SetFindPatternMB(s_pEfrDataDlg->chFindPattern);
SetFindPatternMB(utstring_body(s_pEfrData->chFindPattern));
}
break;
@ -6393,7 +6413,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
// if first time you bring up find/replace dialog,
// use most recent search pattern to find box
// in case of no history: paste clipboard
_EditGetFindStrg(Globals.hwndEdit, s_pEfrDataDlg, lpszSelection, SizeOfMem(lpszSelection));
_EditGetFindStrg(Globals.hwndEdit, s_pEfrData, lpszSelection, SizeOfMem(lpszSelection));
}
}
if (lpszSelection) {
@ -6413,15 +6433,16 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
break; // return
}
_SetSearchFlags(hwnd, s_pEfrDataDlg);
SetFindPatternMB(s_pEfrDataDlg->chFindPattern);
_SetSearchFlags(hwnd, s_pEfrData);
SetFindPatternMB(utstring_body(s_pEfrData->chFindPattern));
if (s_pEfrDataDlg->bWildcardSearch) {
_EscapeWildcards(s_pEfrDataDlg->chFindPattern, COUNTOF(s_pEfrDataDlg->chFindPattern), s_pEfrDataDlg);
if (s_pEfrData->bWildcardSearch) {
_EscapeWildcards(utstring_body(s_pEfrData->chFindPattern), utstring_alloc_len(s_pEfrData->chFindPattern), s_pEfrData);
utstring_sanitize(s_pEfrData->chFindPattern);
}
bool const bIsRegex = (s_pEfrDataDlg->fuFlags & SCFIND_REGEXP);
if (s_pEfrDataDlg->bTransformBS || bIsRegex) {
TransformBackslashes(s_pEfrDataDlg->chFindPattern, bIsRegex, Encoding_SciCP, NULL);
bool const bIsRegex = (s_pEfrData->fuFlags & SCFIND_REGEXP);
if (s_pEfrData->bTransformBS || bIsRegex) {
TransformBackslashes(utstring_body(s_pEfrData->chFindPattern), bIsRegex, Encoding_SciCP, NULL);
}
// ------------------------
@ -6432,8 +6453,8 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
DocPos start = s_InitialSearchStart;
DocPos end = Sci_GetDocEndPosition();
DocPos const slen = StringCchLenA(s_pEfrDataDlg->chFindPattern, COUNTOF(s_pEfrDataDlg->chFindPattern));
DocPos const iPos = _FindInTarget(s_pEfrDataDlg->chFindPattern, slen, (int)(s_pEfrDataDlg->fuFlags), &start, &end, false, FRMOD_NORM);
DocPos const slen = utstring_len(s_pEfrData->chFindPattern);
DocPos const iPos = _FindInTarget(utstring_body(s_pEfrData->chFindPattern), slen, (int)(s_pEfrData->fuFlags), &start, &end, false, FRMOD_NORM);
if (iPos >= 0) {
if (s_bIsReplaceDlg) {
SciCall_ScrollRange(end, iPos);
@ -6457,30 +6478,30 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
case IDT_TIMER_CALLBACK_MRKALL: {
//DocPos const startPos = (DocPos)lParam;
s_anyMatch = _FindHasMatch(s_pEfrDataDlg->hwnd, s_pEfrDataDlg, 0, false);
s_anyMatch = _FindHasMatch(s_pEfrData->hwnd, s_pEfrData, 0, false);
InvalidateRect(GetDlgItem(hwnd, IDC_FINDTEXT), NULL, TRUE); // coloring
if (s_pEfrDataDlg->bMarkOccurences) {
if (s_pEfrData->bMarkOccurences) {
static char s_lastFind[FNDRPL_BUFFER] = { L'\0' };
if (s_pEfrDataDlg->bStateChanged || (StringCchCompareXA(s_lastFind, s_pEfrDataDlg->chFindPattern) != 0)) {
StringCchCopyA(s_lastFind, COUNTOF(s_lastFind), s_pEfrDataDlg->chFindPattern);
_FindHasMatch(s_pEfrDataDlg->hwnd, s_pEfrDataDlg, 0, s_pEfrDataDlg->bMarkOccurences);
if (s_pEfrData->bStateChanged || (StringCchCompareXA(s_lastFind, utstring_body(s_pEfrData->chFindPattern)) != 0)) {
StringCchCopyA(s_lastFind, COUNTOF(s_lastFind), utstring_body(s_pEfrData->chFindPattern));
_FindHasMatch(s_pEfrData->hwnd, s_pEfrData, 0, s_pEfrData->bMarkOccurences);
if (FocusedView.HideNonMatchedLines) {
EditToggleView(s_pEfrDataDlg->hwnd);
EditToggleView(s_pEfrData->hwnd);
}
}
} else if (s_pEfrDataDlg->bStateChanged) {
} else if (s_pEfrData->bStateChanged) {
if (FocusedView.HideNonMatchedLines) {
SendWMCommand(hwnd, IDC_TOGGLE_VISIBILITY);
} else {
EditClearAllOccurrenceMarkers(s_pEfrDataDlg->hwnd);
EditClearAllOccurrenceMarkers(s_pEfrData->hwnd);
}
}
s_pEfrDataDlg->bStateChanged = false;
s_pEfrData->bStateChanged = false;
}
break;
case IDC_ALL_OCCURRENCES: {
_SetSearchFlags(hwnd, s_pEfrDataDlg);
_SetSearchFlags(hwnd, s_pEfrData);
if (IsButtonChecked(hwnd, IDC_ALL_OCCURRENCES)) {
DialogEnableControl(hwnd, IDC_TOGGLE_VISIBILITY, true);
@ -6488,9 +6509,9 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
} else { // switched OFF
DialogEnableControl(hwnd, IDC_TOGGLE_VISIBILITY, false);
if (FocusedView.HideNonMatchedLines) {
EditToggleView(s_pEfrDataDlg->hwnd);
EditToggleView(s_pEfrData->hwnd);
}
EditClearAllOccurrenceMarkers(s_pEfrDataDlg->hwnd);
EditClearAllOccurrenceMarkers(s_pEfrData->hwnd);
Globals.iMarkOccurrencesCount = 0;
InvalidateRect(GetDlgItem(hwnd, IDC_FINDTEXT), NULL, TRUE);
}
@ -6498,12 +6519,12 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
break;
case IDC_TOGGLE_VISIBILITY:
if (s_pEfrDataDlg) {
EditToggleView(s_pEfrDataDlg->hwnd);
if (s_pEfrData) {
EditToggleView(s_pEfrData->hwnd);
if (!FocusedView.HideNonMatchedLines) {
s_pEfrDataDlg->bStateChanged = true;
s_pEfrData->bStateChanged = true;
s_InitialTopLine = -1; // reset
EditClearAllOccurrenceMarkers(s_pEfrDataDlg->hwnd);
EditClearAllOccurrenceMarkers(s_pEfrData->hwnd);
_DelayMarkAll(_MQ_STD);
}
}
@ -6520,14 +6541,14 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
} else { // unchecked
DialogEnableControl(hwnd, IDC_DOT_MATCH_ALL, false);
DialogEnableControl(hwnd, IDC_FINDTRANSFORMBS, true);
CheckDlgButton(hwnd, IDC_FINDTRANSFORMBS, SetBtn(s_pEfrDataDlg->bTransformBS));
CheckDlgButton(hwnd, IDC_FINDTRANSFORMBS, SetBtn(s_pEfrData->bTransformBS));
}
_SetSearchFlags(hwnd, s_pEfrDataDlg);
_SetSearchFlags(hwnd, s_pEfrData);
_DelayMarkAll(_MQ_STD);
break;
case IDC_DOT_MATCH_ALL:
_SetSearchFlags(hwnd, s_pEfrDataDlg);
_SetSearchFlags(hwnd, s_pEfrData);
_DelayMarkAll(_MQ_STD);
break;
@ -6541,31 +6562,31 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
DialogEnableControl(hwnd, IDC_FINDTRANSFORMBS, false);
} else { // unchecked
DialogEnableControl(hwnd, IDC_FINDTRANSFORMBS, true);
CheckDlgButton(hwnd, IDC_FINDTRANSFORMBS, SetBtn(s_pEfrDataDlg->bTransformBS));
CheckDlgButton(hwnd, IDC_FINDTRANSFORMBS, SetBtn(s_pEfrData->bTransformBS));
}
_SetSearchFlags(hwnd, s_pEfrDataDlg);
_SetSearchFlags(hwnd, s_pEfrData);
_DelayMarkAll(_MQ_STD);
}
break;
case IDC_FINDTRANSFORMBS: {
_SetSearchFlags(hwnd, s_pEfrDataDlg);
_SetSearchFlags(hwnd, s_pEfrData);
_DelayMarkAll(_MQ_STD);
}
break;
case IDC_FINDCASE:
_SetSearchFlags(hwnd, s_pEfrDataDlg);
_SetSearchFlags(hwnd, s_pEfrData);
_DelayMarkAll(_MQ_STD);
break;
case IDC_FINDWORD:
_SetSearchFlags(hwnd, s_pEfrDataDlg);
_SetSearchFlags(hwnd, s_pEfrData);
_DelayMarkAll(_MQ_STD);
break;
case IDC_FINDSTART:
_SetSearchFlags(hwnd, s_pEfrDataDlg);
_SetSearchFlags(hwnd, s_pEfrData);
_DelayMarkAll(_MQ_STD);
break;
@ -6588,24 +6609,23 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
(s_bIsReplaceDlg && LOWORD(wParam) == IDMSG_SWITCHTOFIND)) {
GetDlgPos(hwnd, &s_xFindReplaceDlgSave, &s_yFindReplaceDlgSave);
s_bSwitchedFindReplace = true;
CopyMemory(&s_efrSave, s_pEfrDataDlg, sizeof(EDITFINDREPLACE));
}
if (!s_bSwitchedFindReplace && !_EnableFRDlgCtrls(hwnd)) {
return true;
}
_SetSearchFlags(hwnd, s_pEfrDataDlg);
_SetSearchFlags(hwnd, s_pEfrData);
if (!s_bSwitchedFindReplace) {
// Save MRUs
if (!StrIsEmptyA(s_pEfrDataDlg->chFindPattern)) {
MultiByteToWideChar(Encoding_SciCP, 0, s_pEfrDataDlg->chFindPattern, -1, s_tchBuf, (int)COUNTOF(s_tchBuf));
if (!utstring_is_empty(s_pEfrData->chFindPattern)) {
utstring_getw(s_pEfrData->chFindPattern, s_tchBuf, COUNTOF(s_tchBuf));
MRU_Add(Globals.pMRUfind, s_tchBuf, 0, -1, -1, NULL);
SetFindPattern(s_tchBuf);
}
if (!StrIsEmptyA(s_pEfrDataDlg->chReplaceTemplate)) {
MultiByteToWideChar(Encoding_SciCP, 0, s_pEfrDataDlg->chReplaceTemplate, -1, s_tchBuf, (int)COUNTOF(s_tchBuf));
if (!utstring_is_empty(s_pEfrData->chReplaceTemplate)) {
utstring_getw(s_pEfrData->chReplaceTemplate, s_tchBuf, COUNTOF(s_tchBuf));
MRU_Add(Globals.pMRUreplace, s_tchBuf, 0, -1, -1, NULL);
}
}
@ -6623,20 +6643,22 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
SendDlgItemMessage(hwnd, IDC_REPLACETEXT, CB_ADDSTRING, 0, (LPARAM)s_tchBuf);
}
ComboBox_SetTextMB2W(hwnd, IDC_FINDTEXT, s_pEfrDataDlg->chFindPattern);
ComboBox_SetTextMB2W(hwnd, IDC_REPLACETEXT, s_pEfrDataDlg->chReplaceTemplate);
ComboBox_SetTextMB2W(hwnd, IDC_FINDTEXT, utstring_body(s_pEfrData->chFindPattern));
ComboBox_SetTextMB2W(hwnd, IDC_REPLACETEXT, utstring_body(s_pEfrData->chReplaceTemplate));
if (!s_bSwitchedFindReplace) {
SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)(GetFocus()), 1);
}
bool bFound = false;
switch (LOWORD(wParam)) {
case IDOK: // find next
case IDACC_SELTONEXT:
if (s_bIsReplaceDlg) {
Globals.bReplaceInitialized = true;
}
EditFindNext(s_pEfrDataDlg->hwnd, s_pEfrDataDlg, (LOWORD(wParam) == IDACC_SELTONEXT), IsKeyDown(VK_F3));
bFound = EditFindNext(s_pEfrData->hwnd, s_pEfrData, (LOWORD(wParam) == IDACC_SELTONEXT), IsKeyDown(VK_F3));
SET_INITIAL_ANCHORS()
break;
@ -6645,33 +6667,34 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
if (s_bIsReplaceDlg) {
Globals.bReplaceInitialized = true;
}
EditFindPrev(s_pEfrDataDlg->hwnd, s_pEfrDataDlg, (LOWORD(wParam) == IDACC_SELTOPREV), IsKeyDown(VK_F3));
bFound = EditFindPrev(s_pEfrData->hwnd, s_pEfrData, (LOWORD(wParam) == IDACC_SELTOPREV), IsKeyDown(VK_F3));
SET_INITIAL_ANCHORS()
break;
case IDC_REPLACE: {
Globals.bReplaceInitialized = true;
EditReplace(s_pEfrDataDlg->hwnd, s_pEfrDataDlg);
bFound = EditReplace(s_pEfrData->hwnd, s_pEfrData);
}
break;
case IDC_REPLACEALL:
Globals.bReplaceInitialized = true;
EditReplaceAll(s_pEfrDataDlg->hwnd, s_pEfrDataDlg, true);
bFound = EditReplaceAll(s_pEfrData->hwnd, s_pEfrData, true);
break;
case IDC_REPLACEINSEL:
if (!SciCall_IsSelectionEmpty()) {
Globals.bReplaceInitialized = true;
EditReplaceAllInSelection(s_pEfrDataDlg->hwnd, s_pEfrDataDlg, true);
bFound = EditReplaceAllInSelection(s_pEfrData->hwnd, s_pEfrData, true);
}
break;
}
if (!s_bIsReplaceDlg && (s_pEfrDataDlg->bFindClose)) {
if (bFound && !s_bIsReplaceDlg && (s_pEfrData->bFindClose)) {
//~EndDialog(hwnd, LOWORD(wParam)); ~ (!) not running on own message loop
DestroyWindow(hwnd);
} else if ((LOWORD(wParam) != IDOK) && s_pEfrDataDlg->bReplaceClose) {
}
else if (bFound && s_bIsReplaceDlg && s_pEfrData->bReplaceClose) {
//~EndDialog(hwnd, LOWORD(wParam)); ~ (!) not running on own message loop
DestroyWindow(hwnd);
}
@ -6705,7 +6728,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
SetDlgItemTextW(hwnd, IDC_FINDTEXT, wszRepl);
SetDlgItemTextW(hwnd, IDC_REPLACETEXT, wszFind);
Globals.FindReplaceMatchFoundState = FND_NOP;
_SetSearchFlags(hwnd, s_pEfrDataDlg);
_SetSearchFlags(hwnd, s_pEfrData);
_DelayMarkAll(_MQ_STD);
}
break;
@ -6732,8 +6755,8 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
if (Globals.bCanSaveIniFile) {
MRU_Save(Globals.pMRUfind);
}
if (s_pEfrDataDlg) {
s_pEfrDataDlg->chFindPattern[0] = '\0';
if (s_pEfrData) {
utstring_clear(s_pEfrData->chFindPattern);
}
SetFindPattern(NULL);
while ((int)SendDlgItemMessage(hwnd, IDC_FINDTEXT, CB_DELETESTRING, 0, 0) > 0) {};
@ -6745,8 +6768,8 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
if (Globals.bCanSaveIniFile) {
MRU_Save(Globals.pMRUreplace);
}
if (s_pEfrDataDlg) {
s_pEfrDataDlg->chReplaceTemplate[0] = '\0';
if (s_pEfrData) {
utstring_clear(s_pEfrData->chReplaceTemplate);
}
while ((int)SendDlgItemMessage(hwnd, IDC_REPLACETEXT, CB_DELETESTRING, 0, 0) > 0) {};
SetDlgItemText(hwnd, IDC_REPLACETEXT, L"");
@ -6769,7 +6792,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
case IDACC_SAVEFIND:
Globals.FindReplaceMatchFoundState = FND_NOP;
SendWMCommand(Globals.hwndMain, IDM_EDIT_SAVEFIND);
ComboBox_SetTextMB2W(hwnd, IDC_FINDTEXT, s_pEfrDataDlg->chFindPattern);
ComboBox_SetTextMB2W(hwnd, IDC_FINDTEXT, utstring_body(s_pEfrData->chFindPattern));
CheckDlgButton(hwnd, IDC_FINDREGEXP, BST_UNCHECKED);
CheckDlgButton(hwnd, IDC_DOT_MATCH_ALL, BST_UNCHECKED);
CheckDlgButton(hwnd, IDC_WILDCARDSEARCH, BST_UNCHECKED);
@ -7109,7 +7132,7 @@ void EditSelectionMultiSelectAll()
void EditSelectionMultiSelectAllEx(CLPCEDITFINDREPLACE edFndRpl)
{
EDITFINDREPLACE efr;
CopyMemory(&efr, edFndRpl, sizeof(EDITFINDREPLACE));
DuplicateEFR(&efr, edFndRpl);
if (IsWindow(Globals.hwndDlgFindReplace)) {
_SetSearchFlags(Globals.hwndDlgFindReplace, &efr);
@ -7118,8 +7141,10 @@ void EditSelectionMultiSelectAllEx(CLPCEDITFINDREPLACE edFndRpl)
}
DocChangeTransactionBegin();
EditMarkAll(efr.chFindPattern, efr.fuFlags, 0, Sci_GetDocEndPosition(), true);
EditMarkAll(utstring_body(efr.chFindPattern), efr.fuFlags, 0, Sci_GetDocEndPosition(), true);
EndDocChangeTransaction();
ReleaseEFR(&efr);
}
@ -7130,14 +7155,14 @@ void EditSelectionMultiSelectAllEx(CLPCEDITFINDREPLACE edFndRpl)
static char* _GetReplaceString(HWND hwnd, CLPCEDITFINDREPLACE lpefr, int* iReplaceMsg)
{
char* pszReplace = NULL; // replace text of arbitrary size
if (StringCchCompareNIA(lpefr->chReplaceTemplate, COUNTOF(lpefr->chReplaceTemplate), "^c", 2) == 0) {
if (utstring_find(lpefr->chReplaceTemplate, 0, "^c", 2) == 0) {
*iReplaceMsg = SCI_REPLACETARGET;
pszReplace = EditGetClipboardText(hwnd, true, NULL, NULL);
} else {
size_t const cch = StringCchLenA(lpefr->chReplaceTemplate, COUNTOF(lpefr->chReplaceTemplate));
size_t const cch = utstring_len(lpefr->chReplaceTemplate);
pszReplace = (char*)AllocMem(cch + 1, HEAP_ZERO_MEMORY);
if (pszReplace) {
StringCchCopyA(pszReplace, SizeOfMem(pszReplace), lpefr->chReplaceTemplate);
StringCchCopyA(pszReplace, SizeOfMem(pszReplace), utstring_body(lpefr->chReplaceTemplate));
bool const bIsRegEx = (lpefr->fuFlags & SCFIND_REGEXP);
if (lpefr->bTransformBS || bIsRegEx) {
TransformBackslashes(pszReplace, bIsRegEx, Encoding_SciCP, iReplaceMsg);

View File

@ -35,6 +35,7 @@
#include "crypto/crypto.h"
#include "uthash/utarray.h"
#include "uthash/utlist.h"
#include "uthash/utstring.h"
#include "tinyexpr/tinyexpr.h"
#include "Encoding.h"
#include "VersionEx.h"
@ -221,6 +222,10 @@ const WCHAR* const TBBUTTON_DEFAULT_IDS_V2 = L"1 2 4 3 28 0 5 6 0 7 8 9 0 10 11
//=============================================================================
// static method declarations
// current find pattern
static UT_string* s_utCurrentFindPattern = NULL;
// undo / redo selections
static UT_icd UndoRedoSelElement_icd = { sizeof(DocPos), NULL, NULL, NULL };
@ -749,6 +754,11 @@ static void _InitGlobals()
Flags.bSettingsFileSoftLocked = DefaultFlags.bSettingsFileSoftLocked = false;
utstring_new(Settings.EFR_Data.chFindPattern);
utstring_new(Settings.EFR_Data.chReplaceTemplate);
utstring_new(Defaults.EFR_Data.chFindPattern);
utstring_new(Defaults.EFR_Data.chReplaceTemplate);
FocusedView.HideNonMatchedLines = false;
FocusedView.CodeFoldingAvailable = false;
FocusedView.ShowCodeFolding = true;
@ -774,8 +784,10 @@ static void _InitGlobals()
// --- static locals ---
ThemesItems_Init();
utstring_new(s_utCurrentFindPattern);
s_pthArgFilePath = Path_Allocate(NULL);
}
@ -852,6 +864,9 @@ static void _CleanUpResources(const HWND hwnd, bool bIsInitialized)
// --- free allocated memory ---
ReleaseEFR(&(Defaults.EFR_Data));
ReleaseEFR(&(Settings.EFR_Data));
Path_Release(Paths.CurrentFile);
Path_Release(Paths.ModuleDirectory);
Path_Release(Paths.WorkingDirectory);
@ -864,6 +879,8 @@ static void _CleanUpResources(const HWND hwnd, bool bIsInitialized)
Path_Release(s_pthArgFilePath);
utstring_free(s_utCurrentFindPattern);
ThemesItems_Release();
}
@ -1282,11 +1299,19 @@ static SIZE _StatusCalcTextSize(HWND hwnd, LPCWSTR lpsz)
//
// Set/Get FindPattern()
//
static WCHAR sCurrentFindPattern[FNDRPL_BUFFER] = { L'\0' };
bool IsFindPatternEmpty()
{
return StrIsEmpty(sCurrentFindPattern);
return utstring_is_empty(s_utCurrentFindPattern);
}
//=============================================================================
//
// GetFindPatternMB()
//
LPCSTR GetFindPatternMB()
{
return utstring_body(s_utCurrentFindPattern);
}
//=============================================================================
@ -1295,7 +1320,7 @@ bool IsFindPatternEmpty()
//
void SetFindPattern(LPCWSTR wchFindPattern)
{
StringCchCopy(sCurrentFindPattern, COUNTOF(sCurrentFindPattern), (wchFindPattern ? wchFindPattern : L""));
utstring_setw(s_utCurrentFindPattern, wchFindPattern);
}
//=============================================================================
@ -1304,27 +1329,26 @@ void SetFindPattern(LPCWSTR wchFindPattern)
//
void SetFindPatternMB(LPCSTR chFindPattern)
{
MultiByteToWideChar(Encoding_SciCP, 0, chFindPattern, -1, sCurrentFindPattern, (int)COUNTOF(sCurrentFindPattern));
utstring_clear(s_utCurrentFindPattern);
utstring_bincpy(s_utCurrentFindPattern, chFindPattern, strlen(chFindPattern));
}
//=============================================================================
//
// LengthOfFindPattern()
//
size_t LengthOfFindPattern()
{
return StringCchLen(sCurrentFindPattern, 0);
return utstring_getw(s_utCurrentFindPattern, NULL, 0) - 1;
}
//=============================================================================
//
// GetFindPattern()
// LengthOfFindPatternMB()
//
LPCWSTR GetFindPattern()
size_t LengthOfFindPatternMB()
{
return sCurrentFindPattern;
return utstring_len(s_utCurrentFindPattern);
}
@ -1334,7 +1358,7 @@ LPCWSTR GetFindPattern()
//
void CopyFindPattern(LPWSTR wchFindPattern, size_t bufferCount)
{
StringCchCopy(wchFindPattern, bufferCount, sCurrentFindPattern);
utstring_getw(s_utCurrentFindPattern, wchFindPattern, bufferCount);
}
//=============================================================================
@ -1343,22 +1367,26 @@ void CopyFindPattern(LPWSTR wchFindPattern, size_t bufferCount)
//
void CopyFindPatternMB(LPSTR chFindPattern, size_t bufferCount)
{
WideCharToMultiByte(Encoding_SciCP, 0, sCurrentFindPattern, -1, chFindPattern, (int)bufferCount, NULL, NULL);
StringCchCopyA(chFindPattern, bufferCount, utstring_body(s_utCurrentFindPattern));
}
// ----------------------------------------------------------------------------
static EDITFINDREPLACE s_FindReplaceData = INIT_EFR_DATA;
//=============================================================================
//
// SetFindReplaceData()
//
static void SetFindReplaceData()
{
s_FindReplaceData = Settings.EFR_Data; // reset
// reset
DuplicateEFR(&s_FindReplaceData, &(Settings.EFR_Data));
if (!IsFindPatternEmpty()) {
CopyFindPatternMB(s_FindReplaceData.chFindPattern, COUNTOF(s_FindReplaceData.chFindPattern));
CopyFindPatternMB(Settings.EFR_Data.chFindPattern, COUNTOF(Settings.EFR_Data.chFindPattern));
utstring_clear(Settings.EFR_Data.chFindPattern);
utstring_bincpy(Settings.EFR_Data.chFindPattern, utstring_body(s_utCurrentFindPattern), utstring_len(s_utCurrentFindPattern));
}
if (g_flagMatchText) { // cmd line
@ -5262,7 +5290,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
SetFindReplaceData(); // s_FindReplaceData
if (IsFindPatternEmpty() && !StrIsEmptyA(s_FindReplaceData.chFindPattern)) {
if (IsFindPatternEmpty() && !utstring_is_empty(s_FindReplaceData.chFindPattern)) {
if (iLoWParam != IDM_EDIT_REPLACENEXT) {
SendWMCommand(hwnd, IDM_EDIT_FIND);
} else {
@ -5314,9 +5342,9 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
case CMD_FINDPREVSEL:
case IDM_EDIT_SAVEFIND: {
if (SetCurrentSelAsFindReplaceData()) {
MRU_Add(Globals.pMRUfind, GetFindPattern(), 0, -1, -1, NULL);
WCHAR buf[8192];
CopyFindPattern(buf, COUNTOF(buf));
MRU_Add(Globals.pMRUfind, buf, 0, -1, -1, NULL);
s_FindReplaceData.fuFlags &= (~(SCFIND_REGEXP | SCFIND_POSIX));
s_FindReplaceData.bTransformBS = false;
@ -10955,7 +10983,7 @@ bool ActivatePrevInst()
params->flagMatchText = g_flagMatchText;
if (!IsFindPatternEmpty()) {
StringCchCopy(StrEnd(&params->wchData, 0) + 1, (LengthOfFindPattern() + 1), GetFindPattern());
CopyFindPattern(StrEnd(&params->wchData, 0) + 1, (LengthOfFindPattern() + 1));
}
cds.dwData = DATA_NOTEPAD3_PARAMS;
@ -11044,7 +11072,7 @@ bool ActivatePrevInst()
params->flagMatchText = g_flagMatchText;
if (!IsFindPatternEmpty()) {
StringCchCopy(StrEnd(&params->wchData, 0) + 1, (LengthOfFindPattern() + 1), GetFindPattern());
CopyFindPattern(StrEnd(&params->wchData, 0) + 1, (LengthOfFindPattern() + 1));
}
cds.dwData = DATA_NOTEPAD3_PARAMS;

View File

@ -143,13 +143,14 @@ void HandleDWellStartEnd(const DocPos position, const UINT uid);
bool HandleHotSpotURLClicked(const DocPos position, const HYPERLINK_OPS operation);
void HandleColorDefClicked(HWND hwnd, const DocPos position);
bool IsFindPatternEmpty();
void SetFindPattern(LPCWSTR wchFindPattern);
void SetFindPatternMB(LPCSTR chFindPattern);
bool IsFindPatternEmpty();
LPCSTR GetFindPatternMB();
void SetFindPattern(LPCWSTR wchFindPattern);
void SetFindPatternMB(LPCSTR chFindPattern);
size_t LengthOfFindPattern();
LPCWSTR GetFindPattern();
void CopyFindPattern(LPWSTR wchFindPattern, size_t bufferCount);
void CopyFindPatternMB(LPSTR chFindPattern, size_t bufferCount);
size_t LengthOfFindPatternMB();
void CopyFindPattern(LPWSTR wchFindPattern, size_t bufferCount);
void CopyFindPatternMB(LPSTR chFindPattern, size_t bufferCount);
bool ConsistentIndentationCheck(EditFileIOStatus* status);

View File

@ -43,6 +43,8 @@
#include <stdbool.h>
#endif
#include "uthash/utstring.h"
#include "Sci_Position.h"
#include "Scintilla.h"
@ -241,26 +243,51 @@ typedef struct _editfindreplace
bool bHideNonMatchedLines;
bool bStateChanged;
HWND hwnd;
char chFindPattern[FNDRPL_BUFFER];
char chReplaceTemplate[FNDRPL_BUFFER];
UT_string* chFindPattern; //[FNDRPL_BUFFER];
UT_string* chReplaceTemplate; //[FNDRPL_BUFFER];
} EDITFINDREPLACE, *LPEDITFINDREPLACE;
//typedef const EDITFINDREPLACE* CLPEDITFINDREPLACE;
typedef const EDITFINDREPLACE* const CLPCEDITFINDREPLACE;
#define INIT_EFR_DATA { 0, false, false, false, false, false, false, false, false, true, NULL, "", "" }
#define INIT_EFR_DATA { 0, false, false, false, false, false, false, false, false, true, NULL, NULL, NULL }
#define IDMSG_SWITCHTOFIND 300
#define IDMSG_SWITCHTOREPLACE 301
inline static void DuplicateEFR(LPEDITFINDREPLACE dst, CLPCEDITFINDREPLACE src)
{
dst->fuFlags = src->fuFlags;
dst->bTransformBS = src->bTransformBS;
dst->bFindClose = src->bFindClose;
dst->bReplaceClose = src->bReplaceClose;
dst->bNoFindWrap = src->bNoFindWrap;
dst->bRegExprSearch = src->bRegExprSearch;
dst->bWildcardSearch = src->bWildcardSearch;
dst->bMarkOccurences = src->bMarkOccurences;
dst->bHideNonMatchedLines = src->bHideNonMatchedLines;
dst->bStateChanged = src->bStateChanged;
dst->hwnd = src->hwnd;
utstring_renew(dst->chFindPattern);
utstring_bincpy(dst->chFindPattern, utstring_body(src->chFindPattern), utstring_len(src->chFindPattern));
utstring_renew(dst->chReplaceTemplate);
utstring_bincpy(dst->chReplaceTemplate, utstring_body(src->chReplaceTemplate), utstring_len(src->chReplaceTemplate));
}
inline static void ReleaseEFR(LPEDITFINDREPLACE efr)
{
utstring_free(efr->chFindPattern);
efr->chFindPattern = NULL;
utstring_free(efr->chReplaceTemplate);
efr->chReplaceTemplate = NULL;
}
// --------------------------------------------------------------------------
#define MRU_MAXITEMS 32
#define MRU_ITEMSFILE 32
#define MRU_ITEMSFNDRPL 16
#define MRU_NOCASE 1
#define MRU_UTF8 2
#define MRU_BMRK_SIZE 512
#define MRU_NOCASE 1
#define MRU_UTF8 2
#define MRU_BMRK_SIZE 512
typedef struct _mrulist
{

View File

@ -1,4 +1,4 @@
/*
/*
Copyright (c) 2008-2021, Troy D. Hanson http://troydhanson.github.com/uthash/
All rights reserved.
@ -32,11 +32,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <stringapiset.h>
#ifdef __GNUC__
#define UTSTRING_UNUSED __attribute__((__unused__))
#else
#define UTSTRING_UNUSED
#define UTSTRING_UNUSED inline
#endif
#ifdef oom
@ -67,17 +68,22 @@ do { \
} \
} while(0)
#define utstring_init(s) \
#define utstring_sanitize(s) \
do { \
(s)->n = 0; (s)->i = 0; (s)->d = NULL; \
utstring_reserve(s,100); \
(s)->d[0] = '\0'; \
(s)->i = strlen((s)->d); \
} while(0)
#define utstring_done(s) \
do { \
if ((s)->d != NULL) free((s)->d); \
(s)->n = 0; \
(s)->d = NULL; (s)->n = 0; (s)->i = 0; \
} while(0)
#define utstring_init(s) \
do { \
utstring_done(s); \
utstring_reserve(s,128); \
(s)->d[0] = '\0'; \
} while(0)
#define utstring_free(s) \
@ -92,9 +98,16 @@ do { \
if (!(s)) { \
utstring_oom(); \
} \
(s)->d = NULL; \
utstring_init(s); \
} while(0)
#define utstring_clear(s) \
do { \
(s)->d[0] = '\0'; \
(s)->i = 0; \
} while(0)
#define utstring_renew(s) \
do { \
if (s) { \
@ -104,34 +117,33 @@ do { \
} \
} while(0)
#define utstring_clear(s) \
do { \
(s)->i = 0; \
(s)->d[0] = '\0'; \
} while(0)
#define utstring_bincpy(s,b,l) \
do { \
utstring_reserve((s),(l)+1); \
if (l) memcpy(&(s)->d[(s)->i], b, l); \
if (l) memcpy(&((s)->d[(s)->i]), b, l); \
(s)->i += (l); \
(s)->d[(s)->i]='\0'; \
} while(0)
#define utstring_concat(dst,src) \
do { \
utstring_reserve((dst),((src)->i)+1); \
if ((src)->i) memcpy(&(dst)->d[(dst)->i], (src)->d, (src)->i); \
(dst)->i += (src)->i; \
(dst)->d[(dst)->i]='\0'; \
#define utstring_concat(dst,src) \
do { \
utstring_reserve((dst),((src)->i)+1); \
if ((src)->i) memcpy(&((dst)->d[(dst)->i]), (src)->d, (src)->i); \
(dst)->i += (src)->i; \
(dst)->d[(dst)->i]='\0'; \
} while(0)
#define utstring_is_empty(s) (!((s)->d) || ((s)->d[0] == '\0'))
#define utstring_len(s) ((s)->i)
#define utstring_body(s) ((s)->d)
#define utstring_alloc_len(s) ((s)->n)
UTSTRING_UNUSED static void utstring_printf_va(UT_string *s, const char *fmt, va_list ap) {
int n;
ptrdiff_t n;
va_list cp;
for (;;) {
#ifdef _WIN32
@ -139,10 +151,10 @@ UTSTRING_UNUSED static void utstring_printf_va(UT_string *s, const char *fmt, va
#else
va_copy(cp, ap);
#endif
n = vsnprintf (&s->d[s->i], s->n-s->i, fmt, cp);
n = (ptrdiff_t)vsnprintf(&s->d[s->i], s->n - s->i, fmt, cp);
va_end(cp);
if ((n > -1) && ((size_t) n < (s->n-s->i))) {
if ((n > -1) && (n < (ptrdiff_t)(s->n - s->i))) {
s->i += n;
return;
}
@ -171,14 +183,14 @@ UTSTRING_UNUSED static void utstring_printf(UT_string *s, const char *fmt, ...)
UTSTRING_UNUSED static void _utstring_BuildTable(
const char *P_Needle,
size_t P_NeedleLen,
long *P_KMP_Table)
ptrdiff_t* P_KMP_Table)
{
long i, j;
ptrdiff_t i, j;
i = 0;
j = i - 1;
P_KMP_Table[i] = j;
while (i < (long) P_NeedleLen)
while (i < (ptrdiff_t)P_NeedleLen)
{
while ( (j > -1) && (P_Needle[i] != P_Needle[j]) )
{
@ -186,7 +198,7 @@ UTSTRING_UNUSED static void _utstring_BuildTable(
}
i++;
j++;
if (i < (long) P_NeedleLen)
if (i < (ptrdiff_t)P_NeedleLen)
{
if (P_Needle[i] == P_Needle[j])
{
@ -211,16 +223,16 @@ UTSTRING_UNUSED static void _utstring_BuildTable(
UTSTRING_UNUSED static void _utstring_BuildTableR(
const char *P_Needle,
size_t P_NeedleLen,
long *P_KMP_Table)
ptrdiff_t* P_KMP_Table)
{
long i, j;
ptrdiff_t i, j;
i = P_NeedleLen - 1;
j = i + 1;
P_KMP_Table[i + 1] = j;
while (i >= 0)
{
while ( (j < (long) P_NeedleLen) && (P_Needle[i] != P_Needle[j]) )
while ((j < (ptrdiff_t)P_NeedleLen) && (P_Needle[i] != P_Needle[j]))
{
j = P_KMP_Table[j + 1];
}
@ -248,19 +260,19 @@ UTSTRING_UNUSED static void _utstring_BuildTableR(
/* Search data from left to right. ( Multiple search mode. ) */
UTSTRING_UNUSED static long _utstring_find(
UTSTRING_UNUSED static ptrdiff_t _utstring_find(
const char *P_Haystack,
size_t P_HaystackLen,
const char *P_Needle,
size_t P_NeedleLen,
long *P_KMP_Table)
ptrdiff_t* P_KMP_Table)
{
long i, j;
long V_FindPosition = -1;
ptrdiff_t i, j;
ptrdiff_t V_FindPosition = -1;
/* Search from left to right. */
i = j = 0;
while ( (j < (int)P_HaystackLen) && (((P_HaystackLen - j) + i) >= P_NeedleLen) )
while ((j < (ptrdiff_t)P_HaystackLen) && (((P_HaystackLen - j) + i) >= P_NeedleLen))
{
while ( (i > -1) && (P_Needle[i] != P_Haystack[j]) )
{
@ -268,7 +280,7 @@ UTSTRING_UNUSED static long _utstring_find(
}
i++;
j++;
if (i >= (int)P_NeedleLen)
if (i >= (ptrdiff_t)P_NeedleLen)
{
/* Found. */
V_FindPosition = j - i;
@ -281,22 +293,22 @@ UTSTRING_UNUSED static long _utstring_find(
/* Search data from right to left. ( Multiple search mode. ) */
UTSTRING_UNUSED static long _utstring_findR(
UTSTRING_UNUSED static ptrdiff_t _utstring_findR(
const char *P_Haystack,
size_t P_HaystackLen,
const char *P_Needle,
size_t P_NeedleLen,
long *P_KMP_Table)
ptrdiff_t* P_KMP_Table)
{
long i, j;
long V_FindPosition = -1;
ptrdiff_t i, j;
ptrdiff_t V_FindPosition = -1;
/* Search from right to left. */
j = (P_HaystackLen - 1);
i = (P_NeedleLen - 1);
while ( (j >= 0) && (j >= i) )
{
while ( (i < (int)P_NeedleLen) && (P_Needle[i] != P_Haystack[j]) )
while ((i < (ptrdiff_t)P_NeedleLen) && (P_Needle[i] != P_Haystack[j]))
{
i = P_KMP_Table[i + 1];
}
@ -315,16 +327,16 @@ UTSTRING_UNUSED static long _utstring_findR(
/* Search data from left to right. ( One time search mode. ) */
UTSTRING_UNUSED static long utstring_find(
UTSTRING_UNUSED static ptrdiff_t utstring_find(
UT_string *s,
long P_StartPosition, /* Start from 0. -1 means last position. */
ptrdiff_t P_StartPosition, /* Start from 0. -1 means last position. */
const char *P_Needle,
size_t P_NeedleLen)
{
long V_StartPosition;
long V_HaystackLen;
long *V_KMP_Table;
long V_FindPosition = -1;
ptrdiff_t V_StartPosition;
ptrdiff_t V_HaystackLen;
ptrdiff_t* V_KMP_Table;
ptrdiff_t V_FindPosition = -1;
if (P_StartPosition < 0)
{
@ -335,9 +347,9 @@ UTSTRING_UNUSED static long utstring_find(
V_StartPosition = P_StartPosition;
}
V_HaystackLen = s->i - V_StartPosition;
if ( (V_HaystackLen >= (long) P_NeedleLen) && (P_NeedleLen > 0) )
if ((V_HaystackLen >= (ptrdiff_t)P_NeedleLen) && (P_NeedleLen > 0))
{
V_KMP_Table = (long *)malloc(sizeof(long) * (P_NeedleLen + 1));
V_KMP_Table = (ptrdiff_t*)malloc(sizeof(ptrdiff_t) * (P_NeedleLen + 1));
if (V_KMP_Table != NULL)
{
_utstring_BuildTable(P_Needle, P_NeedleLen, V_KMP_Table);
@ -361,16 +373,16 @@ UTSTRING_UNUSED static long utstring_find(
/* Search data from right to left. ( One time search mode. ) */
UTSTRING_UNUSED static long utstring_findR(
UTSTRING_UNUSED static ptrdiff_t utstring_findR(
UT_string *s,
long P_StartPosition, /* Start from 0. -1 means last position. */
ptrdiff_t P_StartPosition, /* Start from 0. -1 means last position. */
const char *P_Needle,
size_t P_NeedleLen)
{
long V_StartPosition;
long V_HaystackLen;
long *V_KMP_Table;
long V_FindPosition = -1;
ptrdiff_t V_StartPosition;
ptrdiff_t V_HaystackLen;
ptrdiff_t* V_KMP_Table;
ptrdiff_t V_FindPosition = -1;
if (P_StartPosition < 0)
{
@ -381,9 +393,9 @@ UTSTRING_UNUSED static long utstring_findR(
V_StartPosition = P_StartPosition;
}
V_HaystackLen = V_StartPosition + 1;
if ( (V_HaystackLen >= (long) P_NeedleLen) && (P_NeedleLen > 0) )
if ((V_HaystackLen >= (ptrdiff_t)P_NeedleLen) && (P_NeedleLen > 0))
{
V_KMP_Table = (long *)malloc(sizeof(long) * (P_NeedleLen + 1));
V_KMP_Table = (ptrdiff_t*)malloc(sizeof(ptrdiff_t) * (P_NeedleLen + 1));
if (V_KMP_Table != NULL)
{
_utstring_BuildTableR(P_Needle, P_NeedleLen, V_KMP_Table);
@ -404,4 +416,21 @@ UTSTRING_UNUSED static long utstring_findR(
* end substring search functions *
******************************************************************************/
UTSTRING_UNUSED static void utstring_setw(UT_string* s, const wchar_t* wch)
{
int const len = WideCharToMultiByte(CP_UTF8, 0, wch, -1, NULL, 0, NULL, NULL);
utstring_clear(s);
if ((s)->n < len) { utstring_reserve(s, len - (s)->n); }
WideCharToMultiByte(CP_UTF8, 0, wch, -1, (s)->d, len, NULL, NULL);
(s)->i = strlen((s)->d);
}
UTSTRING_UNUSED static size_t utstring_getw(UT_string* s, wchar_t* wch, size_t count)
{
return (size_t) MultiByteToWideChar(CP_UTF8, 0, utstring_body(s), -1, wch, (int)count);
}
#endif /* UTSTRING_H */