From bd4c323d75bbe9a565e9bc31bb522133d78421a6 Mon Sep 17 00:00:00 2001 From: xomx Date: Sun, 27 Nov 2022 18:11:10 +0100 Subject: [PATCH] Fix inconsistencies at OS-forced Notepad++ (v8.4.7) exit Now if the Notepad++ will have an unsaved data and is still running at the OS restart/shutdown, there will be one universal messagebox "Windows session is about to be terminated but you have some data unsaved. Do you want to exit Notepad++ now?". When Notepad++ backup mode is ON, answer: - YES ... Notepad++ simply quits (Notepad++ backup engine silently handles all the stuff needed) - NO ... Notepad++ stays running, user is on his/her own When Notepad++ backup mode is OFF, answer: - YES ... Notepad++ behaves identically as in the case of the usual Notepad++ IDM_FILE_EXIT or WM_CLOSE messages (save dlgs appears etc., it depends on the current user Notepad++ settings) - NO ... Notepad++ stays running, user is on his/her own Fix v847 --- PowerEditor/installer/nativeLang/english.xml | 1 + PowerEditor/src/NppBigSwitch.cpp | 14 +++++++++++++- PowerEditor/src/resource.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index 184270cf2..04d503a45 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -1377,6 +1377,7 @@ Notepad++ will be restarted after all the operations are terminated. Continue?"/> + diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index f3bbca34b..3371ff533 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -2106,6 +2106,18 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return TRUE; } + case NPPM_INTERNAL_WINDOWSSESSIONEXIT: + { + int answer = _nativeLangSpeaker.messageBox("WindowsSessionExit", + _pPublicInterface->getHSelf(), + TEXT("Windows session is about to be terminated but you have some data unsaved. Do you want to exit Notepad++ now?"), + TEXT("Notepad++ - Windows session exit"), + MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL); + if (answer == IDYES) + ::PostMessage(_pPublicInterface->getHSelf(), WM_CLOSE, 0, 0); + return TRUE; + } + case WM_QUERYENDSESSION: { // app should return TRUE or FALSE immediately upon receiving this message, @@ -2176,7 +2188,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa ::SendMessage(hwnd, WM_SIZE, 0, 0); // to make window fit (specially to show tool bar.) } } - ::PostMessage(hwnd, WM_COMMAND, IDM_FILE_SAVEALL, 0); // posting will not block us here + ::PostMessage(hwnd, NPPM_INTERNAL_WINDOWSSESSIONEXIT, 0, 0); // posting will not block us here return FALSE; // request abort of the shutdown } } diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index a4d7732f9..89f1560a7 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -643,6 +643,7 @@ #define NPPM_INTERNAL_ENABLECHANGEHISTORY (NOTEPADPLUS_USER_INTERNAL + 67) #define NPPM_INTERNAL_CLEANSMARTHILITING (NOTEPADPLUS_USER_INTERNAL + 68) #define NPPM_INTERNAL_CLEANBRACEMATCH (NOTEPADPLUS_USER_INTERNAL + 69) + #define NPPM_INTERNAL_WINDOWSSESSIONEXIT (NOTEPADPLUS_USER_INTERNAL + 70) // See Notepad_plus_msgs.h //#define NOTEPADPLUS_USER (WM_USER + 1000)