Skip to content

Add session snapshot feature to preserve unsaved files on exit#1062

Open
chen3feng wants to merge 2 commits into
dail8859:masterfrom
chen3feng:feature/session-snapshot
Open

Add session snapshot feature to preserve unsaved files on exit#1062
chen3feng wants to merge 2 commits into
dail8859:masterfrom
chen3feng:feature/session-snapshot

Conversation

@chen3feng
Copy link
Copy Markdown

Summary

This PR implements Notepad++'s session snapshot feature — unsaved "New N" files and modified files are automatically preserved on exit and restored on next launch. No more data loss from accidental closes.

Changes

  • Add EnableSessionSnapshot setting (default on) as a master safety-net toggle
  • Change all three session restore settings defaults to true
  • Always save UnsavedFile and TempFile content regardless of restore settings (safety net)
  • Filter session loading based on per-type restore preferences
  • Reduce auto-save interval from 60s to 7s (matching Notepad++)
  • Trigger session backup on editor tab switches for extra safety
  • Remove "experimental" warning from Preferences dialog
  • Add "Previously open files" restore checkbox to Preferences UI

Behavior

  • Default: close without save prompts, content auto-preserved, restored on relaunch
  • Opt-out: uncheck "Enable Session Snapshot" in Preferences → reverts to old behavior with save prompts
  • Fine control: keep master ON, uncheck individual restore options (e.g., don't restore temp files but still back them up)

Files Changed

File Change
src/ApplicationSettings.h Add EnableSessionSnapshot setting
src/ApplicationSettings.cpp New default true; all restore defaults → true
src/NotepadNextApplication.cpp Snapshot gate; timer 60→7s; tab-switch backup; initialize session manager before load
src/SessionManager.cpp Always save UnsavedFile/TempFile; filter load by flags; willFileGetStoredInSession unconditional for unsaved/temp
src/dialogs/PreferencesDialog.cpp Wire master switch; remove experimental warning; enable/disable logic
src/dialogs/PreferencesDialog.ui Add checkBoxSessionSnapshot; restructure restore group box

Closes #81, Closes #178

Add a master switch "Enable Session Snapshot" (default on) that
automatically persists unsaved and temporary file content to disk so
no data is lost when exiting the application. Existing restore settings
now control only what gets restored on startup.

- Add EnableSessionSnapshot setting (default true) as safety net toggle
- Change session restore defaults to true for all three file types
- Always save UnsavedFile/TempFile content regardless of restore settings
- Filter session loading based on per-type restore preferences
- Reduce auto-save interval from 60s to 7s (matching Notepad++)
- Trigger session backup on editor tab switches
- Fix loadSession to call getSessionManager() first to initialize file types
- Remove "experimental" warning from Preferences dialog
- Add "Previously open files" restore checkbox to Preferences UI

Closes dail8859#81, Closes dail8859#178
@chen3feng
Copy link
Copy Markdown
Author

The build (windows-latest, 6.5) failure is unrelated to this PR. All other CI jobs pass, including Windows with Qt 6.8 and 6.10.

Root cause: GitHub recently upgraded windows-latest from windows-2022 to windows-2025-vs2026. The new MSVC 2026 compiler removed stdext types that Qt 6.5's qvarlengtharray.h depends on:

error C3861: 'stdext': identifier not found
  → qvarlengtharray.h(379)

This is a pre-existing incompatibility between Qt 6.5 and the new compiler toolchain, not caused by any changes in this PR.

Fix options (for a separate PR):

  1. Pin the Windows 6.5 job to windows-2022 explicitly in the CI matrix
  2. Drop Qt 6.5 Windows CI since Qt 6.8+ builds fine

Switch to chen3feng/SingleApplication which adds isProcessRunning()
check to verify the recorded primary PID is still alive. If the
primary instance was force-killed, the new instance takes over
instead of exiting as a stale secondary.

Also set QT_DEFAULT_MAJOR_VERSION=6 for the updated SingleApplication
CMakeLists.
@dail8859
Copy link
Copy Markdown
Owner

This PR implements Notepad++'s session snapshot feature — unsaved "New N" files and modified files are automatically preserved on exit and restored on next launch.

Maybe I'm a bit confused here...but doesn't the application have this capability already? The two issues you referenced are closed. You can restore the previous session along with unsaved files and temp files.

What exact set of steps demonstrate the functionality added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: Auto save & load unnamed documents [Feature Request] Close without saving modified files

2 participants