From 88bc3955e92025fa6721a620a5fc897d035b652e Mon Sep 17 00:00:00 2001 From: PeterCJ Date: Sat, 8 Mar 2025 12:40:51 -0800 Subject: [PATCH] Fix SQL Backslash Escape preference not taking effect immediately Refresh SQL lexer(s) on preference change. With new internal message, able to send the SQL property to the each SQL buffer. Fix #16244, close #16258 --- PowerEditor/src/NppBigSwitch.cpp | 38 +++++++++++++++++++ .../WinControls/Preference/preferenceDlg.cpp | 2 + PowerEditor/src/resource.h | 1 + 3 files changed, 41 insertions(+) diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 19b26bda2..306d9a214 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -4144,6 +4144,44 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return TRUE; } + case NPPM_INTERNAL_SQLBACKSLASHESCAPE: + { + // Go through all open files, and if there are any SQL files open, make sure the sql.backslash.escapes propery + // is updated for each of the SQL buffers' Scintilla wrapper. + // This message will only be called on the rare circumstance when the backslash-is-escape-for-sql preference is toggled, so this loop won't be run very often. + const bool kbBackSlash = NppParameters::getInstance().getNppGUI()._backSlashIsEscapeCharacterForSql; + Document oldDoc = _invisibleEditView.execute(SCI_GETDOCPOINTER); + Buffer* oldBuf = _invisibleEditView.getCurrentBuffer(); + + DocTabView* pTab[2] = { &_mainDocTab, &_subDocTab }; + ScintillaEditView* pView[2] = { &_mainEditView, &_subEditView }; + + Buffer* pBuf = NULL; + for (size_t v = 0; v < 2; ++v) + { + for (size_t i = 0, len = pTab[v]->nbItem(); i < len; ++i) + { + pBuf = MainFileManager.getBufferByID(pTab[v]->getBufferByIndex(i)); + + if (pBuf->getLangType() == L_SQL) + { + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); + _invisibleEditView.setCurrentBuffer(pBuf); + + _invisibleEditView.execute(SCI_SETPROPERTY, reinterpret_cast("sql.backslash.escapes"), reinterpret_cast(kbBackSlash ? "1" : "0")); + + if (pBuf == pView[v]->getCurrentBuffer()) + { + pView[v]->defineDocType(L_SQL); + } + } + } + } + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc); + _invisibleEditView.setCurrentBuffer(oldBuf); + return TRUE; + } + default: { if (message == WDN_NOTIFY) diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index dbf20b4b1..304f95532 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -3900,6 +3900,8 @@ intptr_t CALLBACK LanguageSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA case IDC_CHECK_BACKSLASHISESCAPECHARACTERFORSQL: { nppGUI._backSlashIsEscapeCharacterForSql = isCheckedOrNot(IDC_CHECK_BACKSLASHISESCAPECHARACTERFORSQL); + HWND hwndNPP = GetParent(_hParent); + ::SendMessage(hwndNPP, NPPM_INTERNAL_SQLBACKSLASHESCAPE, 0, reinterpret_cast(hwndNPP)); return TRUE; } diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index 842a04afb..71655deae 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -747,6 +747,7 @@ #define NPPM_INTERNAL_CHECKDOCSTATUS (NOTEPADPLUS_USER_INTERNAL + 106) #define NPPM_INTERNAL_HIDEMENURIGHTSHORTCUTS (NOTEPADPLUS_USER_INTERNAL + 107) #define NPPM_INTERNAL_RELOADFUNCTIONLIST (NOTEPADPLUS_USER_INTERNAL + 108) + #define NPPM_INTERNAL_SQLBACKSLASHESCAPE (NOTEPADPLUS_USER_INTERNAL + 109)