Skip to content

Commit

Permalink
rename gDontSavePrefs => gDontSaveSettings and move the check to Save…
Browse files Browse the repository at this point in the history
…Settings()
  • Loading branch information
kjk committed Aug 9, 2024
1 parent ad17f6c commit 0e805bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
11 changes: 11 additions & 0 deletions src/AppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@

#include "utils/Log.h"

// workaround for OnMenuExit
// if this flag is set, CloseWindow will not save prefs before closing the window.
bool gDontSaveSettings = false;

// SumatraPDF.cpp
extern void RememberDefaultWindowPosition(MainWindow* win);

Expand Down Expand Up @@ -340,6 +344,13 @@ static void RememberSessionState() {
// added or removed from gFileHistory (in order to keep
// the list of recently opened documents in sync)
bool SaveSettings() {
if (!gDontSaveSettings) {
// if we are exiting the application by File->Exit,
// OnMenuExit will have called SaveSettings() already
// and we skip the call here to avoid saving incomplete session info
// (because some windows might have been closed already)
}

// don't save preferences without the proper permission
if (!HasPermission(Perm::SavePreferences)) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/AppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ enum {
WIN_STATE_MINIMIZED,
};

extern bool gDontSaveSettings;

TempStr GetSettingsPathTemp();
TempStr GetSettingsFileNameTemp();

Expand Down
19 changes: 5 additions & 14 deletions src/SumatraPDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ static StrVec gAllowedLinkProtocols;
// on an in-document link); examples: "audio", "video", ...
static StrVec gAllowedFileTypes;

// workaround for OnMenuExit
// if this flag is set, CloseWindow will not save prefs before closing the window.
static bool gDontSavePrefs = false;

static void CloseDocumentInCurrentTab(MainWindow*, bool keepUIEnabled, bool deleteModel);
static void OnSidebarSplitterMove(Splitter::MoveEvent*);
static void OnFavSplitterMove(Splitter::MoveEvent*);
Expand Down Expand Up @@ -2258,7 +2254,7 @@ static void OnMenuExit() {
// CloseWindow() must not save the session state every time
// (or we will end up with just the last window)
SaveSettings();
gDontSavePrefs = true;
gDontSaveSettings = true;

// CloseWindow removes the MainWindow from gWindows,
// so use a stable copy for iteration
Expand Down Expand Up @@ -2750,13 +2746,7 @@ void CloseWindow(MainWindow* win, bool quitIfLast, bool forceClose) {
if (!lastWindow || quitIfLast) {
ShowWindow(win->hwndFrame, SW_HIDE);
}
if (!gDontSavePrefs) {
// if we are exiting the application by File->Exit,
// OnMenuExit will have called SaveSettings() already
// and we skip the call here to avoid saving incomplete session info
// (because some windows might have been closed already)
SaveSettings();
}
SaveSettings();
TabsOnCloseWindow(win);

if (forceClose) {
Expand Down Expand Up @@ -5863,9 +5853,9 @@ static LRESULT FrameOnCommand(MainWindow* win, HWND hwnd, UINT msg, WPARAM wp, L
}

case CmdCloseCurrentDocument: {
gDontSavePrefs = true;
gDontSaveSettings = true;
CloseCurrentTab(win, true /* quitIfLast */);
gDontSavePrefs = false;
gDontSaveSettings = false;
SaveSettings();
break;
}
Expand Down Expand Up @@ -6200,6 +6190,7 @@ LRESULT CALLBACK WndProcSumatraFrame(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
case WM_ENDSESSION:
// TODO: check for unfinished print jobs in WM_QUERYENDSESSION?
SaveSettings();
gDontSaveSettings = true;
if (wp == TRUE) {
// we must quit so that we restore opened files on start.
DestroyWindow(hwnd);
Expand Down

0 comments on commit 0e805bf

Please sign in to comment.