Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autosaving directory for unsaved windows #480

Closed
ProgerXP opened this issue Feb 4, 2024 · 2 comments
Closed

Autosaving directory for unsaved windows #480

ProgerXP opened this issue Feb 4, 2024 · 2 comments
Assignees

Comments

@ProgerXP
Copy link
Owner

ProgerXP commented Feb 4, 2024

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.

@cshnik
Copy link
Collaborator

cshnik commented Jul 27, 2024

Done.

@cshnik cshnik assigned ProgerXP and unassigned cshnik Jul 27, 2024
@cshnik
Copy link
Collaborator

cshnik commented Jul 27, 2024

INI option UnsavedScratchPath renamed to DraftsPath.

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

No branches or pull requests

2 participants