JAL-1988 added a saveInProgress stack to BackupFiles
[jalview.git] / src / jalview / io / BackupFiles.java
index 2039d3c..05a1ac4 100644 (file)
@@ -105,6 +105,37 @@ public class BackupFiles
 
   private static final String oldTempFileSuffix = "_oldfile_tobedeleted";
 
+  private static ArrayList<File> savesInProgress = new ArrayList<>();
+
+  private boolean addSaveInProgress()
+  {
+    if (savesInProgress.contains(file))
+    {
+      return false;
+    }
+    else
+    {
+      savesInProgress.add(file);
+      return true;
+    }
+  }
+
+  private boolean removeSaveInProgress()
+  {
+    if (savesInProgress.contains(file))
+    {
+      // remove all occurrences
+      while (savesInProgress.remove(file))
+      {
+      }
+      return true;
+    }
+    else
+    {
+      return false;
+    }
+  }
+
   public BackupFiles(String filename)
   {
     this(new File(filename));
@@ -116,6 +147,10 @@ public class BackupFiles
   {
     classInit();
     this.file = file;
+
+    // add this file from the save in progress stack
+    addSaveInProgress();
+
     BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
             .getSavedBackupEntry();
     this.suffix = bfpe.suffix;
@@ -819,6 +854,9 @@ public class BackupFiles
       tidyUpFiles();
     }
 
+    // remove this file from the save in progress stack
+    removeSaveInProgress();
+
     return rename;
   }