Warn users if a file has been edited since last saved
Issue #325
resolved
Many users are saving their entries on networked drives (or DropBox, etc.) so they can access from multiple machines. This is great unless you save from one while it's still open on another.
Comments (4)
-
-
- attached 325.patch
-
reporter Hrm… I think this heads in the wrong direction. Once you need to save, you’ve already lost data.
What I think I’d like to see:
- Scythebill should have a function to check, for any given open file, whether the modification date of that file has changed. If it has, show a popup giving the user a choice to ignore things or to reload the file from disk.
-
That function should run on:
- The windowActivated() method of WindowListener: https://docs.oracle.com/javase/8/docs/api/java/awt/event/WindowListener.html#windowActivated-java.awt.event.WindowEvent-
- And in a periodic event run once every hour, using a Swing timer (https://docs.oracle.com/javase/8/docs/api/javax/swing/Timer.html)
-
reporter - changed status to resolved
Resolve issue
#325: Warn users if a file has been edited since last saved Shows a warning alert if a file has been modified when a window is activated or the user navigates to a new part of the app. Gives the user the option of either reloading from disk, or of ignoring the changes.→ <<cset ced4b8f3a4db>>
- Log in to comment
I'm going to get hit by this sooner or later (if I haven't already), so I thought I'd take a stab at it.
Rather than reporting when the file is modified underneath Scythebill (similar to how emacs does it), it just grabs the last-modified timestamp when opening a file, then waits until the user goes to Save and compares the stored timestamp to the file's current last-modified timestamp (and saves the timestamp again after saving). I didn't see any other paths through the code to save the file to disk or to open a file (where the file's timestamp needs to be recorded), but if there are any they need to be modified to support this, too.
The dialog box has a different icon in the corner (a small penguin? instead of the Scythebill icon) than other popups have, I don't know why. I based the text off the emacs messages when a file is modified, but they should probably be rewritten in a more-Scythebill style. Sorry I can't provide Spanish translations.
When exiting, if this dialog comes up (after pressing Yes to, do you want to save: yes|no|cancel) and you press No, Scythebill just exits. Should there be a way to cancel (and avoid exiting), instead?
When you have a file open, and you File | Open... and select that same file, the file does not get reloaded from disk (that is existing behavior). Is that expected, and if so, what should the behavior be if the file was touched by some other program before it was "re-opened?" Right now, if you do that you won't get this warning when you try to save (see comment in LastModified.java).
Should probably call removeFile() when closing a file, but I never looked for the close file code paths.
Tested on Linux (Debian stable) only (I can't test on Windows or OS X):
touch file.bsxm
touch file.bsxm
#2touch file2.bsxm