Add a new setting: DraftsPath. If set, must point to an existing folder (after expanding %variables%), causing Notepad 2e to save small files there (as File > Save Copy but never doing Ensure consistent line endings and Strip trailing blanks) after 1 minute of a changed window becoming unfocused.
When application becomes inactive (loses focus), current buffer is dirty, wasn't autosaved since last change and its size is <= FileLoadWarningMB then set up WM_TIMER for 1 minute.
The timer is cancelled when it's triggered, application becomes active or other conditions don't hold (e.g. buffer is no longer dirty or was Undo'ed to the dirty state that was already autosaved - although for simplicity this is not implemented).
For simplicity, the timer can be always running, with the condition moved inside it, or the condition may be split (e.g. timer set upon losing focus, with dirtyness check inside).
The timer saves current buffer under a unique PID-counter.txt file name, generated before first autosaving (it's the same for the same process but not for others).
Windows reuses process IDs so PID alone isn't enough but adding it prevents another process from taking over this process' draft file name (scenario: process A runs, autosaves to 1.txt, then becomes non-dirty, removes 1.txt, process B runs, sees there's no 1.txt and autosaves there so now both A and B autosave to 1.txt). Since two processes with the same ID cannot simultaneously exist, name generation is very simple and doesn't have to be multiprocess-safe. At the same time, two draft files with the same PID prefix may exist (if Notepad 2e has crashed and a new instance received the same PID).
After buffer ceases to be dirty (user did a successful File > Save or Save As, opened a new file or used File > New) or the process terminates cleanly (File > Exit), remove the draft file.
When doing File > Open, replying No to the save prompt and cancelling the file selection dialog (remaining with the old unsaved buffer), current implementation deletes the autosaved file and saves it again in 1 minute after losing focus.
As a result, DraftsPath will only contain files corresponding to either currently running or unexpectedly closed processes.
Add a new setting:
DraftsPath
. If set, must point to an existing folder (after expanding%variables%
), causing Notepad 2e to save small files there (as File > Save Copy but never doing Ensure consistent line endings and Strip trailing blanks) after 1 minute of a changed window becoming unfocused.<= FileLoadWarningMB
then set upWM_TIMER
for 1 minute.PID-counter.txt
file name, generated before first autosaving (it's the same for the same process but not for others).PID
alone isn't enough but adding it prevents another process from taking over this process' draft file name (scenario: process A runs, autosaves to1.txt
, then becomes non-dirty, removes1.txt
, process B runs, sees there's no1.txt
and autosaves there so now both A and B autosave to1.txt
). Since two processes with the same ID cannot simultaneously exist, name generation is very simple and doesn't have to be multiprocess-safe. At the same time, two draft files with the samePID
prefix may exist (if Notepad 2e has crashed and a new instance received the same PID).As a result,
DraftsPath
will only contain files corresponding to either currently running or unexpectedly closed processes.