DistributedProofreaders / guiguts

Perl/Tk text editor designed for editing and formatting public domain material for inclusion at Project Gutenberg
GNU General Public License v2.0
9 stars 10 forks source link

Enable Auto Save setting is periodically disabled #1305

Closed okrick closed 4 months ago

okrick commented 4 months ago

Describe the bug Guiguts keeps turning off Auto Save. I frequently double-check the settings to make sure the setting is enabled. I can't figure out why this is happening. While Auto Save is usually on when I open Guiguts, it sometimes gets disabled unexpectedly, even while working on a project. I only realize it when I notice the program hasn't automatically saved and find the Auto Save option unchecked again. I never manually turn off the setting.

To Reproduce Steps to reproduce the behavior:

  1. Open Guiguts

  2. Open the Preferences menu

  3. Scroll down to Backup then select Enable Auto Save

  4. Either work on a project for a period of time then close and reopen the program

  5. Reopen the Preferences menu

  6. Scroll down to Backup

  7. Enable Auto Save is no longer checked

  8. Or work on a project for a couple of hours before realizing that I don't recall the last time the program automatically saved

  9. Reopen the Preferences menu

  10. Scroll down to Backup

  11. Enable Auto Save is no longer checked

Expected behavior The 'Enable Auto Save' setting should remain persistent and only be disabled by the user's explicit action.

Environment Currently Running: Guiguts, Version: 1.6.2 Platform: MSWin32 Microsoft Windows [Version 10.0.19045.4529] Perl v5.32.1 Aspell 0.50.3 perl/Tk Version: 804.036 Tk patchLevel: 8.4 Tk libraries: C:/Strawberry/perl/site/lib/Tk

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Auto Save used to work reliably (stayed enabled), but sometime last year it started getting unchecked automatically. This behavior did not begin with the latest release.

Guiguts resetting Auto Save during use seems more likely than the issue being tied to opening and closing the program. This could explain why I discover the setting unchecked occasionally when I check it upon launching Guiguts, rather than consistently.

windymilla commented 4 months ago

Thanks for the report.

There is one place where Guiguts temporarily suspends autosaving, then restores it, but apart from that, I don't think it ever changes the setting (unless the user does). There are actually 2 places, because this happens while Guiguts is doing Save (or Save As) a file (since you don't want autosave to kick in and try to save the file while you're in the middle of saving the file). Looking at the code, I can't see an obvious way for it to fail and end up clearing the autosave preference, but obviously something is going wrong for you, so there must be something.

I have a potential idea for a way to make it more robust. If I manage to implement something, I'll be in touch so you can try out a patch and see if it fixes it.

Note to Self: Try scheduling a restore of the autosave setting via after_idle (as done for something in Guiguts 2)

okrick commented 4 months ago

Is it possible it disables AutoSave permanently when I manually save a file? I manually save my projects in progress occasionally, which might be why it keeps turning off. I'll try to make a conscious effort to check the AutoSave setting before and after saving manually.

windymilla commented 4 months ago

Yes, that is what I was wondering might be happening. I can't see in the code how that could happen, but suspicion is bound to fall on that code because it messes with the autosave preference flag.

I've attached a file for you to try out: FileMenu.zip If you download and unzip it, you will find it contains FileMenu.pm. Please use this to replace the FileMenu.pm that you will find in the lib/Guiguts folder under your release. You can take a safe copy of the file that is already there if you want to, so you can restore it if you think it makes things worse. The change in it is the simplest one to stop it disabling autosave temporarily during saves, so we can see if it really is what is causing the issue. If you try using the new file for long enough that you either see it has not fixed the problem, or alternatively that you become convinced that is has fixed it, then please let me know. Thanks, Nigel

okrick commented 4 months ago

Wow, that was quick. Wish I had mentioned it earlier.

Thank you, I'll let you know.

okrick commented 4 months ago

Unfortunately, replacing the file didn't resolve the issue. Within the last hour, my project stopped auto-saving.

I made several changes to the tables, manually saving after each modification to ensure they looked good. To maximize the chance of a manual and auto-save happening close together, the auto-save interval was set to just one minute. I completed work on the tables roughly an hour ago. I was currently fixing the dozens of lists for some time now which don't need verification after each major change.

windymilla commented 4 months ago

That's very odd Rick. Thanks for testing it.

Just to confirm something you said previously: It's not just that autosave stops working - the actual preference setting seems to get reset? This is important because it means the problem is not just something to do with timing or the code that repeats every 5 minutes (or whatever) - something is actually changing the global variable ($::autosave) which controls whether the "Auto Save" menu button has a check mark or not, and controls whether the autosaving happens.

The only remaining place in the code that assigns to that $::autosave variable is in the toolbar. I don't know if you normally have that showing (Preferences-->Toolbar-->Enable Toolbar). If you do, you should see the "Save" icon has a green background when Auto Save is enabled, and it flashes yellow for a few seconds just before it does an Auto Save. If you don't have that toolbar visible usually, you could try showing it (you can choose whether to put it top, bottom, left or right in the Prefs menu) and it might enable you to spot exactly when the background switches to not being green.

Since Shift+right-clicking on that Save icon is the only other way in the code (other than the Prefs menu) to turn Auto Save on and off, I have also disabled that Shift+right-click bit of code. So now the only places in the code that change that $::autosave variable are where it is loaded from the setting.rc file when the program starts, and if you click the Auto Save button in the Prefs-->Backup menu. So, please could you unzip the attached file and copy the Utilities.pm file it contains into your release, as you did with FileMenu.pm (also keep the new version of FileMenu.pm in your release). Then we will know there is logically no way for that variable to get reset accidentally.

Many thanks for your perseverance with this.

Utilities.zip

okrick commented 4 months ago

Yes, I confirm that it is the autosave preference that periodically gets cleared.

I have the toolbar visible and use the Save icon to manually save files. Honestly, I didn't realize right-clicking the Save icon would affect autosave rather than just saving the current file. I've never intentionally right-clicked it. I think it would be more intuitive to only manage settings to preferences through the dedicated Preferences menu.

I'll definitely let you know if the Utilities.zip file fixes the problem.

PS: [I've noticed a huge speed improvement in search and replace with "\n" somewhere in the regex search criteria from the FileMenu.pm installation. The wait was over 15 minutes (typical with files > 1M) before anything happened and it is now only about 2 minutes. I don't know if you did something for the speed improvement but many thanks.]

windymilla commented 4 months ago

Thanks Rick.

I can't claim any credit for speeding up S&R. The only explanation I can think of is that Guiguts has always had to load the whole file into memory when doing a regex search containing "\n" - that is what causes the delay. It is entirely possible that if you had been running Guiguts for quite a while that it had gobbled up some memory each time you did a regex search, and ended up making it run slowly. The speed up is possibly just because you've been forced to quit Guiguts and restart it. Maybe next time you find it's ridiculously slow, you could try saving, exiting, and restarting?

I agree that a setting like AutoSave should only be in the Prefs menu - it's been like it is now for many years - before I was involved. I think some settings, like AutoImg, are OK to have in the toolbar as well, because a user might want to turn those on and off quite frequently, unlike AutoSave. Also, I suspect 99% of users didn't even know that Right-click resets the AutoSave timer, and Shift-Right-Click turns off AutoSave completely.

I look forward to hearing (or not hearing!) of any issues with the new version.

okrick commented 4 months ago

While the "close-then-restart" trick offers a slight speed boost (around 20%) for massive files, it's not ideal. Ideally, version 2 would allow regex searches with carriage returns without needing to load the entire file into RAM.

To estimate the impact of a replace operation, I usually do a preliminary count. However, on large files, this becomes counterproductive because the count takes just as long as the actual search and replace. It's surprising how long these operations can take – a 10MB file search on a 16GB RAM system can take over an hour!

windymilla commented 4 months ago

Ideally, version 2 would allow regex searches with carriage returns without needing to load the entire file into RAM.

It does (sort of). The underlying "Tcl/Tk" widget that the whole thing is based on (both GG1 and GG2) has limitations in its regex ability. So, I can do searches for regexes with "\n", but there are some regexes it can't cope with. There may have to be an "advanced regex" button that you just turn on if the normal regex engine can't cope.

a 10MB file search on a 16GB RAM system can take over an hour!

Wow - you're very dedicated to tolerate that without tearing your hair out. At some point, you might find Guiguts 2 already has some things that would be useful to you, but I wouldn't want to upset the system you have if it works for you.

windymilla commented 4 months ago

@okrick - I just did a quick test in Guiguts 2.

okrick commented 4 months ago

I'm impressed. Can't wait to begin using it.

okrick commented 4 months ago

It appears that the Utilities.zip corrected the issue.

windymilla commented 4 months ago

Thanks Rick - will contact you separately about GG2

okrick commented 4 months ago

Absolutely, count me in! My eagle eyes can spot a software oddity a mile away. You might even question if my help is a bug or a feature. :)

windymilla commented 4 months ago

Problem is solved