Skip to content

Commit a925252

Browse files
committed
Persist wrap and purge state in INI file
1 parent 43b5a59 commit a925252

File tree

3 files changed

+30
-34
lines changed

3 files changed

+30
-34
lines changed

src/MultiReplacePanel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9956,6 +9956,8 @@ void MultiReplace::saveSettingsToIni(const std::wstring& iniFilePath) {
99569956
outFile << Encoding::wstringToUtf8(L"UseVariables=" + std::to_wstring(useVariables) + L"\n");
99579957
outFile << Encoding::wstringToUtf8(L"ButtonsMode=" + std::to_wstring(ButtonsMode) + L"\n");
99589958
outFile << Encoding::wstringToUtf8(L"UseList=" + std::to_wstring(useList) + L"\n");
9959+
outFile << Encoding::wstringToUtf8(L"DockWrap=" + std::to_wstring(ResultDock::wrapEnabled()) + L"\n");
9960+
outFile << Encoding::wstringToUtf8(L"DockPurge=" + std::to_wstring(ResultDock::purgeEnabled()) + L"\n");
99599961
outFile << Encoding::wstringToUtf8(L"HighlightMatch=" + std::to_wstring(highlightMatchEnabled ? 1 : 0) + L"\n");
99609962
outFile << Encoding::wstringToUtf8(L"ExportToBash=" + std::to_wstring(exportToBashEnabled ? 1 : 0) + L"\n");
99619963
outFile << Encoding::wstringToUtf8(L"Tooltips=" + std::to_wstring(tooltipsEnabled ? 1 : 0) + L"\n");
@@ -10150,6 +10152,9 @@ void MultiReplace::loadSettingsFromIni() {
1015010152
useListEnabled = CFG.readBool(L"Options", L"UseList", true);
1015110153
updateUseListState(false);
1015210154

10155+
ResultDock::setWrapEnabled(CFG.readBool(L"Options", L"DockWrap", false));
10156+
ResultDock::setPurgeEnabled(CFG.readBool(L"Options", L"DockPurge", false));
10157+
1015310158
highlightMatchEnabled = CFG.readBool(L"Options", L"HighlightMatch", true);
1015410159
exportToBashEnabled = CFG.readBool(L"Options", L"ExportToBash", false);
1015510160
alertNotFoundEnabled = CFG.readBool(L"Options", L"AlertNotFound", true);

src/ResultDock.cpp

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ ResultDock& ResultDock::instance()
5757
return s;
5858
}
5959

60-
6160
std::vector<std::wstring> ResultDock::extractPaths(const std::wstring& sel)
6261
{
6362
std::vector<std::wstring> out;
@@ -80,7 +79,6 @@ std::vector<std::wstring> ResultDock::extractPaths(const std::wstring& sel)
8079
return out;
8180
}
8281

83-
8482
void ResultDock::ensureCreatedAndVisible(const NppData& npp)
8583
{
8684
// 1) first-time creation
@@ -685,6 +683,8 @@ void ResultDock::create(const NppData& npp)
685683
static_cast<WPARAM>(NppDarkMode::dmfInit),
686684
reinterpret_cast<LPARAM>(_hDock));
687685

686+
::SendMessage(_hSci, SCI_SETWRAPMODE, wrapEnabled() ? SC_WRAP_WORD : SC_WRAP_NONE, 0);
687+
688688
// 8) Initialise folding and apply syntax colours that match current N++ theme
689689
initFolding();
690690
applyTheme();
@@ -697,36 +697,32 @@ void ResultDock::initFolding() const
697697
auto S = [this](UINT msg, WPARAM w = 0, LPARAM l = 0)
698698
{ return ::SendMessage(_hSci, msg, w, l); };
699699

700-
/* 1) configure margin #2 for folding symbols ----------------- */
700+
// 1) configure margin #2 for folding symbols -----------------
701701
constexpr int M_FOLD = 2;
702702
S(SCI_SETMARGINTYPEN, M_FOLD, SC_MARGIN_SYMBOL);
703703
S(SCI_SETMARGINMASKN, M_FOLD, SC_MASK_FOLDERS);
704704

705-
/* 2) width: 16‑px box + 4 px stem so nothing is clipped ------ */
705+
// 2) width: 16‑px box + 4 px stem so nothing is clipped ------
706706
const int h = static_cast<int>(S(SCI_TEXTHEIGHT));
707707
S(SCI_SETMARGINWIDTHN, M_FOLD, h + 4);
708708

709-
/* 3) hide margins 0/1 (line‑numbers & bookmarks) ------------- */
709+
// 3) hide margins 0/1 (line‑numbers & bookmarks) -------------
710710
S(SCI_SETMARGINWIDTHN, 0, 0);
711711
S(SCI_SETMARGINWIDTHN, 1, 0);
712712

713-
/* -------------------------------------------------------------
714-
* 4) header markers
715-
* – root header boxes: BOXPLUS / BOXMINUS (no top stem)
716-
* – nested headers: BOXPLUSCONNECTED / …MINUS… (with stem)
717-
* ---------------------------------------------------------- */
713+
// 4) header markers
718714
S(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_BOXPLUS);
719715
S(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_BOXMINUS);
720716

721717
S(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_BOXMINUSCONNECTED);
722718
S(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_BOXPLUSCONNECTED);
723719

724-
/* 5) guide‑line markers (│ ├ └) ------------------------------ */
720+
// 5) guide‑line markers (│ ├ └) ------------------------------
725721
S(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_VLINE);
726722
S(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_TCORNER);
727723
S(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_LCORNER);
728724

729-
/* 6) placeholder colour – themed colours set in applyTheme() */
725+
// 6) placeholder colour – themed colours set in applyTheme()
730726
constexpr COLORREF placeholder = RGB(200, 200, 200);
731727
for (int id : {
732728
SC_MARKNUM_FOLDER,
@@ -740,10 +736,9 @@ void ResultDock::initFolding() const
740736
S(SCI_MARKERSETBACK, id, placeholder);
741737
}
742738

743-
/* 7) enable mouse interaction & auto‑fold updates ------------ */
739+
// 7) enable mouse interaction & auto‑fold updates ------------
744740
S(SCI_SETMARGINSENSITIVEN, M_FOLD, TRUE);
745-
S(SCI_SETAUTOMATICFOLD,
746-
SC_AUTOMATICFOLD_CLICK );
741+
S(SCI_SETAUTOMATICFOLD, SC_AUTOMATICFOLD_CLICK );
747742

748743
S(SCI_SETFOLDFLAGS, SC_FOLDFLAG_LINEAFTER_CONTRACTED);
749744

@@ -965,20 +960,16 @@ LRESULT CALLBACK ResultDock::sciSubclassProc(HWND hwnd, UINT msg, WPARAM wp, LPA
965960
extern NppData nppData;
966961
const std::string marker = "Line ";
967962

968-
switch (msg)
969-
{
970-
case WM_NOTIFY:
971-
{
963+
switch (msg) {
964+
case WM_NOTIFY: {
972965
NMHDR* hdr = reinterpret_cast<NMHDR*>(lp);
973-
if (hdr->code == DMN_CLOSE)
974-
{
966+
if (hdr->code == DMN_CLOSE) {
975967
::SendMessage(nppData._nppHandle, NPPM_DMMHIDE, 0, reinterpret_cast<LPARAM>(hwnd));
976968
return TRUE;
977969
}
978970

979971
SCNotification* scn = reinterpret_cast<SCNotification*>(lp);
980-
if (scn->nmhdr.code == SCN_MARGINCLICK && scn->margin == 2)
981-
{
972+
if (scn->nmhdr.code == SCN_MARGINCLICK && scn->margin == 2) {
982973
int line = (int)::SendMessage(hwnd, SCI_LINEFROMPOSITION, scn->position, 0);
983974
::SendMessage(hwnd, SCI_TOGGLEFOLD, line, 0);
984975
return 0;
@@ -1001,8 +992,7 @@ LRESULT CALLBACK ResultDock::sciSubclassProc(HWND hwnd, UINT msg, WPARAM wp, LPA
1001992

1002993
// --- Toggle fold if the clicked line is a header ----------
1003994
int level = (int)::SendMessage(hwnd, SCI_GETFOLDLEVEL, dispLine, 0);
1004-
if (level & SC_FOLDLEVELHEADERFLAG)
1005-
{
995+
if (level & SC_FOLDLEVELHEADERFLAG) {
1006996
::SendMessage(hwnd, SCI_TOGGLEFOLD, dispLine, 0);
1007997
// --- remove double‑click word selection & keep scroll ----------
1008998
Sci_Position linePos = (Sci_Position)::SendMessage(
@@ -1025,8 +1015,7 @@ LRESULT CALLBACK ResultDock::sciSubclassProc(HWND hwnd, UINT msg, WPARAM wp, LPA
10251015

10261016
// 5) Count *all* previous "Line " occurrences to get our hitIndex
10271017
int hitIndex = -1;
1028-
for (int i = 0; i <= dispLine; ++i)
1029-
{
1018+
for (int i = 0; i <= dispLine; ++i) {
10301019
int len = (int)::SendMessage(hwnd, SCI_LINELENGTH, i, 0);
10311020
std::string buf(len, '\0');
10321021
::SendMessage(hwnd, SCI_GETLINE, i, (LPARAM)&buf[0]);
@@ -1045,8 +1034,7 @@ LRESULT CALLBACK ResultDock::sciSubclassProc(HWND hwnd, UINT msg, WPARAM wp, LPA
10451034
int wlen = ::MultiByteToWideChar(CP_UTF8, 0,
10461035
hit.fullPathUtf8.c_str(), -1,
10471036
nullptr, 0);
1048-
if (wlen > 0)
1049-
{
1037+
if (wlen > 0) {
10501038
wpath.resize(wlen - 1);
10511039
::MultiByteToWideChar(CP_UTF8, 0, hit.fullPathUtf8.c_str(), -1, &wpath[0], wlen);
10521040
}
@@ -1229,9 +1217,6 @@ LRESULT CALLBACK ResultDock::sciSubclassProc(HWND hwnd, UINT msg, WPARAM wp, LPA
12291217
// ResultDock – Menu actions (copy / open lines & paths) – C++17
12301218
// ==========================================================================
12311219

1232-
bool ResultDock::_wrapEnabled = false;
1233-
bool ResultDock::_purgeOnNextSearch = false;
1234-
12351220
namespace {
12361221

12371222
// --------------------------------------------------------------------------

src/ResultDock.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ class ResultDock final
9696
std::wstring& outText,
9797
std::vector<Hit>& outHits) const;
9898

99+
static bool wrapEnabled() { return _wrapEnabled; }
100+
static bool purgeEnabled() { return _purgeOnNextSearch; }
101+
static void setWrapEnabled(bool v) { _wrapEnabled = v; }
102+
static void setPurgeEnabled(bool v) { _purgeOnNextSearch = v; }
103+
99104
private:
100105
// --------------------- Theme Colors ------------------------
101106
// Holds all relevant colors for the dock panel (light/dark)
@@ -178,8 +183,9 @@ class ResultDock final
178183
void collapseOldSearches();
179184

180185
// ‑‑‑ persistent UI flags ‑‑‑
181-
static bool _wrapEnabled;
182-
static bool _purgeOnNextSearch;
186+
187+
inline static bool _wrapEnabled = false;
188+
inline static bool _purgeOnNextSearch = false;
183189

184190
HWND _hScintilla = nullptr; // handle for Scintilla control
185191
std::wstring _content; // dock display text

0 commit comments

Comments
 (0)