From 335d8b6b184c60944edf609bb86e08a12a355a73 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 12 Sep 2024 14:12:59 +0100 Subject: [PATCH] JAL-4461 Change labelling of All-known-alignment-files to Select-format-from-extension for Save-as file chooser --- resources/lang/Messages.properties | 1 + resources/lang/Messages_es.properties | 1 + src/jalview/gui/AlignFrame.java | 2 +- src/jalview/io/JalviewFileChooser.java | 47 ++++++++++++++++++++++++-------- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 7af6c7f..4576252 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1479,6 +1479,7 @@ action.cluster_matrix = Cluster matrix action.clustering_matrix_for = Calculating tree for matrix {0} and clustering at {1} action.cluster_matrix_tooltip = Computes an average distance tree for the matrix and displays it label.all_known_alignment_files = All known alignment files +label.select_format_from_extension = Select format from filename extension label.command_line_arguments = Command Line Arguments warning.using_old_command_line_arguments = It looks like you are using old command line arguments. These are now deprecated and will be removed in a future release of Jalview.\nFind out about the new command line arguments at\n warning.using_mixed_command_line_arguments = Jalview cannot use both old (-arg) and new (--arg) command line arguments. Please check your command line arguments.\ne.g. {0} and {1} diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index a8ac583..f87b195 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1444,6 +1444,7 @@ label.nothing_selected = Nada seleccionado prompt.analytics_title = Jalview Estadísticas de Uso prompt.analytics = ¿Quiere ayudar a mejorar Jalview habilitando la recopilación de estadísticas de uso con análisis Plausible?\nPuede habilitar o deshabilitar el seguimiento de uso en las preferencias. label.all_known_alignment_files = Todos los archivos de alineación conocidos +label.select_format_from_extension = Seleccione el formato de la extensión del archivo label.command_line_arguments = Argumentos de línea de comando warning.using_old_command_line_arguments = Parece que estás utilizando argumentos antiguos de línea de comando. Estos ahora están en desuso y se eliminarán en una versión futura de Jalview.\nObtenga más información sobre los nuevos argumentos de la línea de comando en\n warning.using_mixed_command_line_arguments = Jalview no puede utilizar argumentos de línea de comando antiguos (-arg) y nuevos (--arg). Verifique los argumentos de su línea de comando.\ne.g. {0} y {1} diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index c225afe..7f32ad3 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1187,7 +1187,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, String format = currentFileFormat == null ? null : currentFileFormat.getName(); JalviewFileChooser chooser = JalviewFileChooser - .forWrite(Cache.getProperty("LAST_DIRECTORY"), format); + .forWrite(Cache.getProperty("LAST_DIRECTORY"), format, true); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle( diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index e38c94e..b2dcd11 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -134,6 +134,12 @@ public class JalviewFileChooser extends JFileChooser public static JalviewFileChooser forWrite(String directory, String selected) { + return forWrite(directory, selected, false); + } + + public static JalviewFileChooser forWrite(String directory, + String selected, boolean addSelectFormatFromFileExtension) + { // TODO in Java 8, forRead and forWrite can be a single method // with a lambda expression parameter for isReadable/isWritable List extensions = new ArrayList<>(); @@ -148,7 +154,8 @@ public class JalviewFileChooser extends JFileChooser } return new JalviewFileChooser(directory, extensions.toArray(new String[extensions.size()]), - descs.toArray(new String[descs.size()]), selected, false); + descs.toArray(new String[descs.size()]), selected, false, false, + addSelectFormatFromFileExtension); } public JalviewFileChooser(String dir) @@ -185,6 +192,14 @@ public class JalviewFileChooser extends JFileChooser public JalviewFileChooser(String dir, String[] extensions, String[] descs, String selected, boolean acceptAny, boolean allowBackupFiles) { + this(dir, extensions, descs, selected, acceptAny, allowBackupFiles, + false); + } + + public JalviewFileChooser(String dir, String[] extensions, String[] descs, + String selected, boolean acceptAny, boolean allowBackupFiles, + boolean addSelectFormatFromExtension) + { super(safePath(dir)); if (extensions.length == descs.length) { @@ -193,7 +208,8 @@ public class JalviewFileChooser extends JFileChooser { formats.add(new String[] { extensions[i], descs[i] }); } - init(formats, selected, acceptAny, allowBackupFiles); + init(formats, selected, acceptAny, allowBackupFiles, + addSelectFormatFromExtension); } else { @@ -260,6 +276,12 @@ public class JalviewFileChooser extends JFileChooser void init(List formats, String selected, boolean acceptAny, boolean allowBackupFiles) { + init(formats, selected, acceptAny, allowBackupFiles, false); + } + + void init(List formats, String selected, boolean acceptAny, + boolean allowBackupFiles, boolean addSelectFormatFromExtension) + { JalviewFileFilter chosen = null; @@ -280,13 +302,15 @@ public class JalviewFileChooser extends JFileChooser } } } - - if (acceptAny) + allExtensions.sort(null); + // only add "All known alignment files" if acceptAny is allowed + if (acceptAny || addSelectFormatFromExtension) { - allExtensions.sort(null); + String label = MessageManager.getString(addSelectFormatFromExtension + ? "label.select_format_from_extension" + : "label.all_known_alignment_files"); JalviewFileFilter alljvf = new JalviewFileFilter( - allExtensions.toArray(new String[] {}), - MessageManager.getString("label.all_known_alignment_files")); + allExtensions.toArray(new String[] {}), label); alljvf.setMultiFormat(true); alljvf.setExtensionListInDescription(false); addChoosableFileFilter(alljvf); @@ -316,10 +340,11 @@ public class JalviewFileChooser extends JFileChooser setFileFilter(chosen); } + JPanel multi = new JPanel(); + multi.setLayout(new BoxLayout(multi, BoxLayout.PAGE_AXIS)); + multi.add(new RecentlyOpened()); if (allowBackupFiles) { - JPanel multi = new JPanel(); - multi.setLayout(new BoxLayout(multi, BoxLayout.PAGE_AXIS)); if (backupfilesCheckBox == null) { try @@ -364,17 +389,15 @@ public class JalviewFileChooser extends JFileChooser } }); } - multi.add(new RecentlyOpened()); multi.add(backupfilesCheckBox); - setAccessory(multi); } else { // set includeBackupFiles=false to avoid other file choosers from picking // up backup files (Just In Case) includeBackupFiles = false; - setAccessory(new RecentlyOpened()); } + setAccessory(multi); } @Override -- 1.7.10.2