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

[Save Actions] Keep popping up question window of "try to resave the file" after deleting the file #3291

Open
zhaolinlau opened this issue Sep 14, 2022 · 13 comments
Labels
saveactions Related to the buil-in Save Actions plugin

Comments

@zhaolinlau
Copy link

OS: Windows 11
Geany Version: 1.38.0

2022-09-14.15-44-12.mp4
@elextr
Copy link
Member

elextr commented Sep 14, 2022

What happens is that when you enable autosave the timer goes off and that calls document_save() which does a disk check, which finds the file is missing and pops a dialog to ask if you want to save the document to the same file (this is the normal behaviour of document saving, if the file isn't there its not clear that the user wants to save the document in the same place).

But because you have set the save timeout so short by the time you dismiss the dialog the timer has gone off again and calls document_save() which does a disk check, which finds the file is missing and pops a dialog to ask if you want to save the document to the same file ... etc etc etc

@zhaolinlau
Copy link
Author

What happens is that when you enable autosave the timer goes off and that calls document_save() which does a disk check, which finds the file is missing and pops a dialog to ask if you want to save the document to the same file (this is the normal behaviour of document saving, if the file isn't there its not clear that the user wants to save the document in the same place).

But because you have set the save timeout so short by the time you dismiss the dialog the timer has gone off again and calls document_save() which does a disk check, which finds the file is missing and pops a dialog to ask if you want to save the document to the same file ... etc etc etc

Then I would like to request a new feature which is only autosave the file when the file is created/existing and won't autosave if the file is deleted or not existing.

@zhaolinlau
Copy link
Author

Then I would like to request a new feature which is only autosave the file when the file is created/existing and won't autosave if the file is deleted or not existing.

Besides, most of the text editors are working like that, which is only autosave the existing files and won't pop up anything if the files are deleted or not created. So it would be more convenient if Geany could have this.

@elextr
Copy link
Member

elextr commented Sep 14, 2022

most of the text editors are working like that, won't pop up anything if the files are deleted or not created

Autosave is about safety, making sure the document is saved if something goes wrong with Geany, the system, or the file system. So, what this says is when the file is deleted, these other apps won't save, and won't tell the user that they are not doing so? How terribly safe ... not. Especially when the file has disappeared, so the document has no on-disk presence, great, just the time to stop saving and not tell anyone.

Clearly I don't think much of those apps approach 😉

Saving a file is a surprisingly complex process with all the transformations at save, encoding, trailing space removal, multiple ways of actually writing the data to disk, etc. So its not surprising that the plugin uses the Geany document_save() rather than re-creating that functionality, but document_save() is intended for use in an interactive environment, it has several places where it has potential user interaction so its not really the best solution for automatic functionality.

It may be possible to refactor to separate the interactive parts from the actual saving process, but I am not sure without actual analysis that it can be done without creating or increasing race conditions (where something is tested in one place, eg the file exists, and is assumed later to be true, the further those are separated the greater the possibility of something changing externally, eg the file being deleted between test and save).

Anyway if somebody wants to propose something it can be considered.

@zhaolinlau
Copy link
Author

zhaolinlau commented Sep 14, 2022

For safety, there is already a function which is autosave when losing focus. Plus, as far as I know this is the only way to fix a bug which I just opened an issue just now but not sure if someone deleted my issue(issue#1198) or it's GitHub problem. Anyway, another issue from save actions plugin that I opened is even I'm not deleting the files, it will also keep popping up the save file window after I just picked a new template file.

@eht16 eht16 transferred this issue from geany/geany-plugins Sep 14, 2022
@eht16 eht16 added the saveactions Related to the buil-in Save Actions plugin label Sep 14, 2022
@eht16
Copy link
Member

eht16 commented Sep 14, 2022

I transferred the issue to the geany project as Save Actions is a core plugin.

@elextr
Copy link
Member

elextr commented Sep 15, 2022

@zhaolinlau Sorry about the delete, after the transfer it looked like you had accidentally posted the same thing twice, but anyway the templates is the same issue, when there is no file it produces a dialog, just another way of getting to that state.

Saving when focus lost is mainly for convenience when the user goes to do something else, saving on a timer is primarily for safety, minimising what may be lost if something goes wrong when typing.

The plugin use-case does not require saving delays of 1 sec, 30 secs is plenty (20-30 secs is what things like Google apps use, and they run over the internet). So in the meantime you can set the delay higher as a workaround.

As I said above the options are:

  1. duplicate file saving from Geany in the save actions plugin without user interaction, a lot of work and any changes in Geany file saving need to be duplicated
  2. refactor file saving in Geany, a lot of work and the possibility of different problems due to possible races

And another option might be for the plugin to check the return from document_save() and if its false stop trying to save that file for the rest of the session, will still get one dialog so the user is warned, but loses the safety net for that file. But is less work (the plugin just keeps a "don't save" list and checks every document against it).

But somebody has to do it1

Footnotes

  1. trademark @eht16

@zhaolinlau
Copy link
Author

I transferred the issue to the geany project as Save Actions is a core plugin.

Alright alright

@zhaolinlau
Copy link
Author

Okay, I understand. I just propose my suggestion, because it would be very convenient if it could autosave every second. So we don't need to manually save the file by pressing ctrl+s. And I'm always work on web dev that's why I put the saving delays to only 1 second, because I want to speed up my workflow which is I just need to press alt+tab to switch to the browser and refresh to see the latest result without saving the web dev files.

@elextr
Copy link
Member

elextr commented Sep 15, 2022

And I'm always work on web dev that's why I put the saving delays to only 1 second, because I want to speed up my workflow which is I just need to press alt+tab to switch to the browser and refresh to see the latest result without saving the web dev files.

Whilst thats a perfectly good use-case, its not the one the autosave plugin was written to address, thats why it is only a partial fit.

There used to be a plugin in Geany-plugins, "web-helper", that had a built-in web page preview, but that never got converted to webkitgtk2 and nobody ships webkitgtk1 any more. Webdevs could perhaps resurrect it.

Or somebody could write a new plugin that does a simplified save, for example assuming utf-8 and doing none of the other transforms or checks. It could possibly also trigger the browser to save you the reload.

@zhaolinlau
Copy link
Author

There used to be a plugin in Geany-plugins, "web-helper", that had a built-in web page preview, but that never got converted to webkitgtk2 and nobody ships webkitgtk1 any more. Webdevs could perhaps resurrect it.

I see

@eht16
Copy link
Member

eht16 commented Sep 16, 2022

Okay, I understand. I just propose my suggestion, because it would be very convenient if it could autosave every second. So we don't need to manually save the file by pressing ctrl+s.

I cannot imagine you seriously want to save the current file every second, read every second?!
Apart from the weird behaviour of the plugin in this specific use case, isn't this what you a huge waste of resources? It requires CPU and IO power and significantly reduce the lifetime of your disk (even if it's a SSD), so you need to replace it early than with a somewhat more normal behaviour.

As @elextr said, something like 30 seconds is probably a good compromise, it doesn't trigger that specific bug and more importantly it saves the planet and your money!

@zhaolinlau
Copy link
Author

Okay, I understand. I just propose my suggestion, because it would be very convenient if it could autosave every second. So we don't need to manually save the file by pressing ctrl+s.

I cannot imagine you seriously want to save the current file every second, read every second?!
Apart from the weird behaviour of the plugin in this specific use case, isn't this what you a huge waste of resources? It requires CPU and IO power and significantly reduce the lifetime of your disk (even if it's a SSD), so you need to replace it early than with a somewhat more normal behaviour.

As @elextr said, something like 30 seconds is probably a good compromise, it doesn't trigger that specific bug and more importantly it saves the planet and your money!

Most of the ides like eclipse, netbeans, microsoft visual studio and text editors like vscodium, notepad++, neovim now do support autosave in 1 second and 1 second is their default timer. So ya I'm serious because it's about convenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
saveactions Related to the buil-in Save Actions plugin
Projects
None yet
Development

No branches or pull requests

3 participants