novelWriter icon indicating copy to clipboard operation
novelWriter copied to clipboard

close without saving

Open snden opened this issue 1 year ago • 5 comments

Sometimes I need to close Novelwriter without saving the changes to disk. But the exit dialog allows to just stay in the project or close Novelwriter and save the project. Is it possible to give option to quit Novelwriter without saving?

snden avatar Jul 07 '23 07:07 snden

This is a duplicate of #533, so I will close it. But I'll elaborate anyway.

The changes are already saved to disk, which is part of the core functionality of novelWriter. It treats your project as individual documents, so each time you edit a document, it is saved. I made a deliberate choice against keeping a project entirely in memory between saves. This is a specifically designed feature, but the disadvantage is that you cannot treat the project as if it was a single document (like in LibreOffice) and choose to not save it.

When I add the single project file option, it would be possible to discard changes, as there will be a distinction between the copy you're editing and the copy saved in your storage area (you cannot perform dynamic read/write operations on a zip file). I can possibly add a discard changes option when I implement this. See feature #977.

vkbo avatar Jul 07 '23 07:07 vkbo

Sorry for duplicating the topic. Thanks for the explanation, the benefits of this system are obvious.

Of course, the decision is up to you. Anyway, let me offer a solution. If you are considering using the .zip format, it would be possible to create a temporary .zip copy of the project every time the user opens it, and use that when selecting Close without saving. And to update this backup copy only when saving manually while working, not when saving automatically. Once the project was closed, the temporary copy would be deleted.

snden avatar Jul 07 '23 10:07 snden

Sorry for duplicating the topic. Thanks for the explanation, the benefits of this system are obvious.

No problem. I've referenced this request in the single file format implementation so the specifics discussed here can be taken into account still.

Of course, the decision is up to you. Anyway, let me offer a solution. If you are considering using the .zip format, it would be possible to create a temporary .zip copy of the project every time the user opens it, and use that when selecting Close without saving. And to update this backup copy only when saving manually while working, not when saving automatically. Once the project was closed, the temporary copy would be deleted.

So, the thing about zip files is that they are archives. They are sort of multi-read, single-write. I say sort of, because you can append to them. However, you cannot practically use them for repeated writing. The way to work with them as storage for project or large document data (as LibreOffice and I think also MS Office does) is generally to extract them and keep them all in memory.

Since I want to preserve the continuous writing feature of novelWriter, which is a safety feature, I will extract the zip file when a project is opened. Then novelWriter will work against the extracted copy, and only create zip archives when the project is either manually saved (Ctrl+Shift+S) or when it is closed. The runtime vs stored location functionality, and the writing of the zip archive is already written into the current version of novelWriter. The former feature is not yet in use, and the latter is only currently used for backups.

Now, I haven't decided where to extract the archive. I want to either extract it to a temporary folder somewhere in the user's app directory (this is where novelWriter already stores other user-specific data), or I can extract the zip archive in the same location where the zip file is saved. I.e. If you open myproject.nwx a folder named for instance .myproject.tmp will be created. When a project is opened, and this folder exists, you will be offered the option to continue last unsaved session or discard it. The benefit of the in-place option is that it will also pass through file sync. I've seen other applications do exactly this, so it's a fairly neat solution. I may let the user choose between the two in some advanced settings tab.

In theory, I can also offer this solution for users using the folder based storage, as duplicating a folder isn't practically any different than extracting an archive. However, people who want to stay with the folder based projects will likely do so because they are already using a version control system, so they already have full control of the version history, and can easily just undo the changes they want to get rid of.

vkbo avatar Jul 07 '23 11:07 vkbo

You know what? The discussion here, and my own mind dump, is more up to date and in line with the current direction of where novelWriter is going, so I will reopen this and keep it as a feature linked to #533 and #977.

vkbo avatar Jul 07 '23 11:07 vkbo

It might help (at least it helps me) to think about this not as "close without saving", but as "revert to previous version", the previous version being the last one saved manually.

awqk avatar May 22 '24 21:05 awqk