From: Ben Soares Date: Thu, 14 Feb 2019 15:52:03 +0000 (+0000) Subject: JAL-3141 Added warning/confirmation when suffixReverse is changed without changing... X-Git-Tag: Release_2_11_0~17^2~97^2~4 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8f992e8f0ecac1cfb85903ee8dce8f3dbf73d323;p=jalview.git JAL-3141 Added warning/confirmation when suffixReverse is changed without changing suffixTemplate or suffixDigits (Bad Things might happen to previous backup files) --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 4989149..ac6cdc4 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1395,4 +1395,6 @@ label.rolled_backups = Rolled backup files label.previously_saved_scheme = Previously saved scheme label.no_backup_files = NO BACKUP FILES label.include_backup_files = Include backup files -label.cancel_changes = Cancel changes \ No newline at end of file +label.cancel_changes = Cancel changes +label.warning_confirm_change_reverse = Warning!\nIf you change the increment/decrement of the backup filename number, without changing the suffix or digits,\nthis may cause loss of backup files created with the previous backup filename scheme.\nAre you sure you wish to do this? +label.change_increment_decrement = Change increment/decrement? \ No newline at end of file diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 747b36d..49b23ea 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1392,8 +1392,10 @@ label.customise = Personalizado label.default = Defecto label.single_file = Solo uno respaldo label.keep_all_versions = Mantener todas las versiones -label.rolled_backups = Ciclos resaldos +label.rolled_backups = Ciclos respaldos label.previously_saved_scheme = Esquema previamente guardado label.no_backup_files = NO ARCHIVOS DE RESPALDOS label.include_backup_files = Incluir archivos de respaldos -label.cancel_changes = Cancelar cambios \ No newline at end of file +label.cancel_changes = Cancelar cambios +label.warning_confirm_change_reverse = ¡Advertencia!\nSi cambia el incremento/decremento del número de archivos de respaldos, sin cambiar el sufijo o los dígitos,\nesto puede causar la pérdida de los archivos de respaldos creados con el esquema anterior de nombre de archivo de respaldos.\n¿Está seguro de que desea hacer esto? +label.change_increment_decrement = ¿Cambiar de incremento/decremento? \ No newline at end of file diff --git a/src/jalview/io/BackupFiles.java b/src/jalview/io/BackupFiles.java index 65232fd..695349c 100644 --- a/src/jalview/io/BackupFiles.java +++ b/src/jalview/io/BackupFiles.java @@ -370,7 +370,6 @@ public class BackupFiles boolean delete = false; if (confirmDelete) { - // Object[] confirmMessageArray = {}; StringBuilder confirmMessage = new StringBuilder(); confirmMessage.append(MessageManager .getString("label.backupfiles_confirm_delete_old_files")); @@ -412,7 +411,8 @@ public class BackupFiles } } - private TreeMap sortBackupFilesAsTreeMap(File[] backupFiles, + private TreeMap sortBackupFilesAsTreeMap( + File[] backupFiles, String basename) { // sort the backup files (based on integer found in the suffix) using a @@ -481,12 +481,10 @@ public class BackupFiles File file = new File(fileName); - String dir = ""; File dirFile; try { dirFile = file.getParentFile(); - dir = dirFile.getCanonicalPath(); } catch (Exception e) { System.out.println( diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 8c60b36..dedcd10 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -24,7 +24,9 @@ import jalview.bin.Cache; import jalview.fts.core.FTSDataColumnPreferences; import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource; import jalview.fts.service.pdb.PDBFTSRestClient; +import jalview.gui.Desktop; import jalview.gui.JalviewBooleanRadioButtons; +import jalview.gui.JvOptionPane; import jalview.gui.JvSwingUtils; import jalview.gui.StructureViewer.ViewerType; import jalview.io.BackupFilenameParts; @@ -1716,6 +1718,23 @@ public class GPreferences extends JPanel updateBackupFilesExampleLabel(); } + private boolean warnAboutSuffixReverseChange() + { + boolean savedSuffixReverse = Cache.getDefault(BackupFiles.REVERSE_ORDER, + false); + int savedSuffixDigits = Cache.getDefault(BackupFiles.SUFFIX_DIGITS, 3); + String savedSuffixTemplate = Cache.getDefault(BackupFiles.SUFFIX, + ".bak" + BackupFiles.NUM_PLACEHOLDER); + + boolean nowSuffixReverse = suffixReverse.isSelected(); + int nowSuffixDigits = getSpinnerInt(suffixDigitsSpinner, 3); + String nowSuffixTemplate = suffixTemplate.getText(); + return nowSuffixReverse != savedSuffixReverse + && nowSuffixDigits == savedSuffixDigits + && nowSuffixTemplate != null + && nowSuffixTemplate.equals(savedSuffixTemplate); + } + /** * Initialises the Backups tabbed panel. * @@ -2054,7 +2073,22 @@ public class GPreferences extends JPanel @Override public void actionPerformed(ActionEvent e) { - updateBackupFilesExampleLabel(); + boolean okay = true; + if (warnAboutSuffixReverseChange()) + { + // Warning popup + okay = confirmSuffixReverseChange(); + } + if (okay) + { + updateBackupFilesExampleLabel(); + } + else + { + boolean savedSuffixReverse = Cache + .getDefault(BackupFiles.REVERSE_ORDER, false); + suffixReverse.setSelected(savedSuffixReverse); + } } }); @@ -2099,6 +2133,20 @@ public class GPreferences extends JPanel return suffixPanel; } + private boolean confirmSuffixReverseChange() + { + boolean ret = false; + String warningMessage = MessageManager + .getString("label.warning_confirm_change_reverse"); + int confirm = JvOptionPane.showConfirmDialog(Desktop.desktop, + warningMessage, + MessageManager.getString("label.change_increment_decrement"), + JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE); + + ret = (confirm == JvOptionPane.YES_OPTION); + return ret; + } + private JPanel initBackupsTabKeepFilesPanel() { keepfilesPanel.setBorder( @@ -2224,32 +2272,16 @@ public class GPreferences extends JPanel return; } - try - { - backupfilesRollMaxSpinner.commitEdit(); - rollMax = (Integer) backupfilesRollMaxSpinner.getValue(); - rollMax = rollMax < 1 ? 1 : rollMax; - } catch (Exception e) - { - System.out.println( - "Failed casting (Integer) backupfilesRollMaxSpinner.getValue()"); - } + rollMax = getSpinnerInt(backupfilesRollMaxSpinner, 4); + rollMax = rollMax < 1 ? 1 : rollMax; if (suffix.indexOf(BackupFiles.NUM_PLACEHOLDER) == -1) { rollMax = 1; } - try - { - suffixDigitsSpinner.commitEdit(); - digits = (Integer) suffixDigitsSpinner.getValue(); - digits = digits < 1 ? 1 : digits; - } catch (Exception e) - { - System.out.println( - "Failed casting (Integer) suffixTemplateSpinner.getValue()"); - } + digits = getSpinnerInt(suffixDigitsSpinner, 3); + digits = digits < 1 ? 1 : digits; int lowersurround = 2; int uppersurround = 0;