From 68748a83bdc001486ebd1acbb04696ff0ab97b40 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Wed, 28 Aug 2024 04:47:36 +0200 Subject: [PATCH] Fix the double notifications bug --- PowerEditor/src/Notepad_plus.cpp | 7 ------- PowerEditor/src/NppBigSwitch.cpp | 10 ++++++++++ .../src/WinControls/Preference/preferenceDlg.cpp | 9 +++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index e4cb4845b82e..b025ebb3c441 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -7248,13 +7248,6 @@ bool Notepad_plus::reloadLang() } _lastRecentFileList.setLangEncoding(_nativeLangSpeaker.getLangEncoding()); - - SCNotification scnN{}; - scnN.nmhdr.code = NPPN_NATIVELANGCHANGED; - scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); - scnN.nmhdr.idFrom = 0; - _pluginsManager.notify(&scnN); - return true; } diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 786086d2e52e..fca99bfd70fb 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -913,6 +913,16 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case NPPM_INTERNAL_RELOADNATIVELANG: { reloadLang(); + + bool doNotif = wParam; + if (doNotif) + { + SCNotification scnN{}; + scnN.nmhdr.code = NPPN_NATIVELANGCHANGED; + scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); + scnN.nmhdr.idFrom = 0; + _pluginsManager.notify(&scnN); + } return TRUE; } diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index 28fc980fa795..49c38febf60f 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -812,15 +812,16 @@ intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM ::SendDlgItemMessage(_hSelf, IDC_COMBO_LOCALIZATION, CB_GETLBTEXT, index, reinterpret_cast(langName)); if (langName[0]) { - // Make English as basic language - if (localizationSwitcher.switchToLang(L"English")) + // Make English as basic language, but if we switch from another language to English, we can skip it + if ((lstrcmpW(langName, L"English") != 0) && localizationSwitcher.switchToLang(L"English")) { - ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_RELOADNATIVELANG, 0, 0); + ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_RELOADNATIVELANG, FALSE, 0); } + // Change the language if (localizationSwitcher.switchToLang(langName)) { - ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_RELOADNATIVELANG, 0, 0); + ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_RELOADNATIVELANG, TRUE, 0); ::InvalidateRect(_hParent, NULL, TRUE); } }