* BackupFiles used for manipulating (naming rolling/deleting) backup/version files when an alignment or project file is saved.
* User configurable options are:
* BACKUPFILES_ENABLED - boolean flag as to whether to use this mechanism or act as before, including overwriting files as saved.
- * The rest of the options are now saved as BACKUPFILES_PRESET, BACKUPFILES_SAVED and BACKUPFILES_CUSTOM
- * (see BackupFilesPresetEntry)
+ * BACKUPFILES_SUFFIX - a template to insert after the file extension. Use '%n' to be replaced by a 0-led SUFFIX_DIGITS long integer.
+ * BACKUPFILES_NO_MAX - flag to turn off setting a maximum number of backup files to keep.
+ * BACKUPFILES_ROLL_MAX - the maximum number of backupfiles to keep for any one alignment or project file.
+ * BACKUPFILES_SUFFIX_DIGITS - the number of digits to insert replace %n with (e.g. BACKUPFILES_SUFFIX_DIGITS = 3 would make "001", "002", etc)
+ * BACKUPFILES_REVERSE_ORDER - if true then "logfile" style numbering and file rolling will occur. If false then ever-increasing version numbering will occur, but old files will still be deleted if there are more than ROLL_MAX backup files.
+ * BACKUPFILES_CONFIRM_DELETE_OLD - if true then prompt/confirm with the user when deleting older backup/version files.
*/
public class BackupFiles
public static final String ENABLED = NS + "_ENABLED";
+ public static final String SUFFIX = NS + "_SUFFIX";
+
+ public static final String NO_MAX = NS + "_NO_MAX";
+
+ public static final String ROLL_MAX = NS + "_ROLL_MAX";
+
+ public static final String SUFFIX_DIGITS = NS + "_SUFFIX_DIGITS";
+
public static final String NUM_PLACEHOLDER = "%n";
+ public static final String REVERSE_ORDER = NS + "_REVERSE_ORDER";
+
+ public static final String CONFIRM_DELETE_OLD = NS
+ + "_CONFIRM_DELETE_OLD";
+
private static final String DEFAULT_TEMP_FILE = "jalview_temp_file_" + NS;
private static final String TEMP_FILE_EXT = ".tmp";
// REVERSE_ORDER
public BackupFiles(File file)
{
+ this(file, ".bak" + NUM_PLACEHOLDER, false, 3, 3, false);
+ }
+
+ public BackupFiles(File file, String defaultSuffix, boolean defaultNoMax,
+ int defaultMax, int defaultDigits, boolean defaultReverseOrder)
+ {
classInit();
this.file = file;
- BackupFilesPresetEntry bfpe = BackupFilesPresetEntry.getSavedBackupEntry();
- this.suffix = bfpe.suffix;
- this.noMax = bfpe.keepAll;
- this.max = bfpe.rollMax;
- this.digits = bfpe.digits;
- this.reverseOrder = bfpe.reverse;
+ this.suffix = Cache.getDefault(SUFFIX, defaultSuffix);
+ this.noMax = Cache.getDefault(NO_MAX, defaultNoMax);
+ this.max = Cache.getDefault(ROLL_MAX, defaultMax);
+ this.digits = Cache.getDefault(SUFFIX_DIGITS, defaultDigits);
+ this.reverseOrder = Cache.getDefault(REVERSE_ORDER,
+ defaultReverseOrder);
// create a temp file to save new data in
File temp = null;
public static void classInit()
{
setEnabled(Cache.getDefault(ENABLED, !Platform.isJS()));
- BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
- .getSavedBackupEntry();
- setConfirmDelete(bfpe.confirmDelete);
+ setConfirmDelete(Cache.getDefault(CONFIRM_DELETE_OLD, true));
}
public static void setEnabled(boolean flag)
MessageManager.getString("label.delete"),
MessageManager.getString("label.rename") };
- confirmButton = JvOptionPane.showOptionDialog(Desktop.desktop,
+ confirmButton = JvOptionPane.showOptionDialog(Desktop.getDesktopPane(),
messageSB.toString(),
MessageManager.getString("label.backupfiles_confirm_delete"),
JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
MessageManager.getString("label.delete"),
MessageManager.getString("label.keep") };
- confirmButton = JvOptionPane.showOptionDialog(Desktop.desktop,
+ confirmButton = JvOptionPane.showOptionDialog(Desktop.getDesktopPane(),
messageSB.toString(),
MessageManager.getString("label.backupfiles_confirm_delete"),
JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
Long.toString(df.length()) }));
}
- int confirmButton = JvOptionPane.showConfirmDialog(Desktop.desktop,
+ int confirmButton = JvOptionPane.showConfirmDialog(Desktop.getDesktopPane(),
messageSB.toString(),
MessageManager
.getString("label.backupfiles_confirm_delete"),
"label.backupfiles_confirm_save_new_saved_file_not_ok"));
}
- int confirmButton = JvOptionPane.showConfirmDialog(Desktop.desktop,
+ int confirmButton = JvOptionPane.showConfirmDialog(Desktop.getDesktopPane(),
messageSB.toString(),
MessageManager
.getString("label.backupfiles_confirm_save_file"),