Skip to content

Commit

Permalink
Merge mark occurrences settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Aug 4, 2024
1 parent 1ec5827 commit 64b837d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 48 deletions.
18 changes: 11 additions & 7 deletions src/Edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5660,7 +5660,7 @@ void EditMarkAll::Continue(HANDLE timer) noexcept {
}
}

void EditMarkAll::MarkAll(BOOL bChanged, bool matchCase, bool wholeWord, bool bookmark) noexcept {
void EditMarkAll::MarkAll(BOOL bChanged, int option) noexcept {
// get current selection
Sci_Position iSelStart = SciCall_GetSelectionStart();
const Sci_Position iSelEnd = SciCall_GetSelectionEnd();
Expand All @@ -5676,8 +5676,11 @@ void EditMarkAll::MarkAll(BOOL bChanged, bool matchCase, bool wholeWord, bool bo
char *text = static_cast<char *>(NP2HeapAlloc(iSelCount + 1));
SciCall_GetSelText(text);

static_assert(NP2_MarkAllBookmark == MarkOccurrences_Bookmark << 10);
int findFlag = (option & MarkOccurrences_Bookmark) << 10;
// exit if selection is not a word and Match whole words only is enabled
if (wholeWord) {
if (option & MarkOccurrences_WholeWord) {
findFlag |= SCFIND_WHOLEWORD;
const UINT cpEdit = SciCall_GetCodePage();
const bool dbcs = !(cpEdit == CP_UTF8 || cpEdit == 0);
// CharClassify::SetDefaultCharClasses()
Expand All @@ -5692,15 +5695,16 @@ void EditMarkAll::MarkAll(BOOL bChanged, bool matchCase, bool wholeWord, bool bo
}
}
}
if (!matchCase) {
if (option & MarkOccurrences_MatchCase) {
findFlag |= SCFIND_MATCHCASE;
} else {
const bool sensitive = IsStringCaseSensitiveA(text);
//printf("%s sensitive=%d\n", __func__, sensitive);
matchCase = !sensitive;
if (!sensitive) {
findFlag |= SCFIND_MATCHCASE;
}
}

const int findFlag = (static_cast<int>(matchCase) * SCFIND_MATCHCASE)
| (static_cast<int>(wholeWord) * SCFIND_WHOLEWORD)
| (static_cast<int>(bookmark) * NP2_MarkAllBookmark);
Start(bChanged, findFlag, iSelCount, text);
}

Expand Down
10 changes: 9 additions & 1 deletion src/Edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ enum {
MarkerBitmask_Bookmark = 1 << MarkerNumber_Bookmark,
};

enum {
MarkOccurrences_None = 0,
MarkOccurrences_Enable = 1,
MarkOccurrences_MatchCase = 2,
MarkOccurrences_WholeWord = 4,
MarkOccurrences_Bookmark = 8,
};

struct EditMarkAll {
bool pending;
bool ignoreSelectionUpdate;
Expand All @@ -253,7 +261,7 @@ struct EditMarkAll {
void Start(BOOL bChanged, int findFlag, Sci_Position iSelCount, LPSTR text) noexcept;
void Continue(HANDLE timer) noexcept;
void Stop() noexcept;
void MarkAll(BOOL bChanged, bool matchCase, bool wholeWord, bool bookmark) noexcept;
void MarkAll(BOOL bChanged, int option) noexcept;
};

void EditToggleBookmarkAt(Sci_Position iPos) noexcept;
Expand Down
62 changes: 22 additions & 40 deletions src/Notepad4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ int iWrapColumn = 0;
int iZoomLevel = 100;
bool bShowBookmarkMargin;
static bool bShowLineNumbers;
static bool bMarkOccurrences;
static bool bMarkOccurrencesMatchCase;
static bool bMarkOccurrencesMatchWords;
static bool bMarkOccurrencesBookmark;
static int bMarkOccurrences;
EditAutoCompletionConfig autoCompletionConfig;
int iSelectOption;
static int iLineSelectionMode;
Expand Down Expand Up @@ -2618,13 +2615,13 @@ void MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) noexcept {
i = IDM_LINE_SELECTION_MODE_NONE + iLineSelectionMode;
CheckMenuRadioItem(hmenu, IDM_LINE_SELECTION_MODE_NONE, IDM_LINE_SELECTION_MODE_OLDVS, i, MF_BYCOMMAND);

UncheckCmd(hmenu, IDM_VIEW_MARKOCCURRENCES_OFF, bMarkOccurrences);
CheckCmd(hmenu, IDM_VIEW_MARKOCCURRENCES_CASE, bMarkOccurrencesMatchCase);
CheckCmd(hmenu, IDM_VIEW_MARKOCCURRENCES_WORD, bMarkOccurrencesMatchWords);
CheckCmd(hmenu, IDM_VIEW_MARKOCCURRENCES_BOOKMARK, bMarkOccurrencesBookmark);
EnableCmd(hmenu, IDM_VIEW_MARKOCCURRENCES_CASE, bMarkOccurrences);
EnableCmd(hmenu, IDM_VIEW_MARKOCCURRENCES_WORD, bMarkOccurrences);
EnableCmd(hmenu, IDM_VIEW_MARKOCCURRENCES_BOOKMARK, bMarkOccurrences);
UncheckCmd(hmenu, IDM_VIEW_MARKOCCURRENCES_OFF, bMarkOccurrences & MarkOccurrences_Enable);
CheckCmd(hmenu, IDM_VIEW_MARKOCCURRENCES_CASE, bMarkOccurrences & MarkOccurrences_MatchCase);
CheckCmd(hmenu, IDM_VIEW_MARKOCCURRENCES_WORD, bMarkOccurrences & MarkOccurrences_WholeWord);
CheckCmd(hmenu, IDM_VIEW_MARKOCCURRENCES_BOOKMARK, bMarkOccurrences & MarkOccurrences_Bookmark);
EnableCmd(hmenu, IDM_VIEW_MARKOCCURRENCES_CASE, bMarkOccurrences & MarkOccurrences_Enable);
EnableCmd(hmenu, IDM_VIEW_MARKOCCURRENCES_WORD, bMarkOccurrences & MarkOccurrences_Enable);
EnableCmd(hmenu, IDM_VIEW_MARKOCCURRENCES_BOOKMARK, bMarkOccurrences & MarkOccurrences_Enable);
i = IDM_VIEW_SHOWCALLTIP_OFF + static_cast<int>(callTipInfo.showCallTip);
CheckMenuRadioItem(hmenu, IDM_VIEW_SHOWCALLTIP_OFF, IDM_VIEW_SHOWCALLTIP_ABGR, i, MF_BYCOMMAND);

Expand Down Expand Up @@ -4094,28 +4091,20 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) {
case IDM_VIEW_MARKOCCURRENCES_OFF:
case IDM_VIEW_MARKOCCURRENCES_CASE:
case IDM_VIEW_MARKOCCURRENCES_WORD:
case IDM_VIEW_MARKOCCURRENCES_BOOKMARK:
switch (LOWORD(wParam)) {
case IDM_VIEW_MARKOCCURRENCES_OFF:
bMarkOccurrences = !bMarkOccurrences;
break;
case IDM_VIEW_MARKOCCURRENCES_CASE:
bMarkOccurrencesMatchCase = !bMarkOccurrencesMatchCase;
break;
case IDM_VIEW_MARKOCCURRENCES_WORD:
bMarkOccurrencesMatchWords = !bMarkOccurrencesMatchWords;
break;
case IDM_VIEW_MARKOCCURRENCES_BOOKMARK:
bMarkOccurrencesBookmark = !bMarkOccurrencesBookmark;
break;
case IDM_VIEW_MARKOCCURRENCES_BOOKMARK: {
const int mask = 1 << (LOWORD(wParam) - IDM_VIEW_MARKOCCURRENCES_OFF);
if (bMarkOccurrences & mask) {
bMarkOccurrences &= ~mask;
} else {
bMarkOccurrences |= mask;
}
if (bMarkOccurrences) {
editMarkAll.MarkAll(FALSE, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords, bMarkOccurrencesBookmark);
if (bMarkOccurrences & MarkOccurrences_Enable) {
editMarkAll.MarkAll(FALSE, bMarkOccurrences);
} else {
editMarkAll.Clear();
}
UpdateStatusbar();
break;
} break;

case IDM_VIEW_SHOW_FOLDING:
bShowCodeFolding = !bShowCodeFolding;
Expand Down Expand Up @@ -4896,19 +4885,19 @@ LRESULT MsgNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) {
// mark occurrences of text currently selected
if (editMarkAll.ignoreSelectionUpdate) {
editMarkAll.ignoreSelectionUpdate = false;
} else if (bMarkOccurrences) {
} else if (bMarkOccurrences & MarkOccurrences_Enable) {
if (SciCall_IsSelectionEmpty()) {
if (editMarkAll.matchCount) {
editMarkAll.Clear();
}
} else {
editMarkAll.MarkAll((scn->updated & SC_UPDATE_CONTENT), bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords, bMarkOccurrencesBookmark);
editMarkAll.MarkAll((scn->updated & SC_UPDATE_CONTENT), bMarkOccurrences);
}
}
} else if (scn->updated & SC_UPDATE_CONTENT) {
// cachedStatusItem.updateMask is already set in SCN_MODIFIED.
if (editMarkAll.matchCount) {
editMarkAll.MarkAll(TRUE, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords, bMarkOccurrencesBookmark);
editMarkAll.MarkAll(TRUE, bMarkOccurrences);
}
}
if (cachedStatusItem.updateMask) {
Expand Down Expand Up @@ -5469,11 +5458,7 @@ void LoadSettings() noexcept {
bShowBookmarkMargin = section.GetBool(L"ShowBookmarkMargin", false);
bShowLineNumbers = section.GetBool(L"ShowLineNumbers", true);
bShowCodeFolding = section.GetBool(L"ShowCodeFolding", true);

bMarkOccurrences = section.GetBool(L"MarkOccurrences", true);
bMarkOccurrencesMatchCase = section.GetBool(L"MarkOccurrencesMatchCase", false);
bMarkOccurrencesMatchWords = section.GetBool(L"MarkOccurrencesMatchWholeWords", false);
bMarkOccurrencesBookmark = section.GetBool(L"MarkOccurrencesBookmark", false);
bMarkOccurrences = section.GetInt(L"MarkOccurrences", MarkOccurrences_Enable);

bViewWhiteSpace = section.GetBool(L"ViewWhiteSpace", false);
bViewEOLs = section.GetBool(L"ViewEOLs", false);
Expand Down Expand Up @@ -5792,10 +5777,7 @@ void SaveSettings(bool bSaveSettingsNow) noexcept {
section.SetBoolEx(L"ShowBookmarkMargin", bShowBookmarkMargin, false);
section.SetBoolEx(L"ShowLineNumbers", bShowLineNumbers, true);
section.SetBoolEx(L"ShowCodeFolding", bShowCodeFolding, true);
section.SetBoolEx(L"MarkOccurrences", bMarkOccurrences, true);
section.SetBoolEx(L"MarkOccurrencesMatchCase", bMarkOccurrencesMatchCase, false);
section.SetBoolEx(L"MarkOccurrencesMatchWholeWords", bMarkOccurrencesMatchWords, false);
section.SetBoolEx(L"MarkOccurrencesBookmark", bMarkOccurrencesBookmark, false);
section.SetIntEx(L"MarkOccurrences", bMarkOccurrences, MarkOccurrences_Enable);
section.SetBoolEx(L"ViewWhiteSpace", bViewWhiteSpace, false);
section.SetBoolEx(L"ViewEOLs", bViewEOLs, false);
section.SetIntEx(L"ShowCallTip", static_cast<int>(callTipInfo.showCallTip), ShowCallTip_None);
Expand Down

0 comments on commit 64b837d

Please sign in to comment.