]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/load/BabelLoadFromFile.java
Version 16.3, July 2014
[GpsPrune.git] / tim / prune / load / BabelLoadFromFile.java
index 187bb495c196ead68ad00b73a5926041267360e8..23ce909fc9dd8e9fd6089465659d980c315a7474 100644 (file)
@@ -200,6 +200,17 @@ public class BabelLoadFromFile extends BabelLoader
                return outerPanel;
        }
 
+       /**
+        * @return the suffix of the selected filename
+        */
+       private String getSelectedSuffix()
+       {
+               String filename = _inputFile.getName();
+               if (filename == null) {return "";}
+               int dotPos = filename.lastIndexOf('.');
+               return (dotPos > 0 ? filename.substring(dotPos) : "");
+       }
+
        /**
         * Initialise dialog
         */
@@ -207,13 +218,16 @@ public class BabelLoadFromFile extends BabelLoader
        {
                _inputFileLabel.setText(_inputFile.getName());
                // Get suffix of filename and compare with previous one
-               String filename = _inputFile.getName();
-               int dotPos = filename.lastIndexOf('.');
-               String suffix = (dotPos > 0 ? filename.substring(dotPos) : null);
-               if (suffix != null && !suffix.equals(".") && (_lastSuffix == null || !suffix.equalsIgnoreCase(_lastSuffix)))
+               String suffix = getSelectedSuffix();
+               if (_lastSuffix == null || !suffix.equalsIgnoreCase(_lastSuffix))
                {
-                       // New suffix chosen, so select first appropriate format (if any)
+                       // New suffix has been chosen, so select first appropriate format (if any)
                        int selIndex = BabelFileFormats.getIndexForFileSuffix(suffix);
+                       if (selIndex < 0)
+                       {
+                               // Use the previous one from the Config (if any)
+                               selIndex = Config.getConfigInt(Config.KEY_IMPORT_FILE_FORMAT);
+                       }
                        if (selIndex >= 0) {
                                _formatDropdown.setSelectedIndex(selIndex);
                        }
@@ -229,5 +243,12 @@ public class BabelLoadFromFile extends BabelLoader
                // Save the filter string, clear it if it's now blank
                final String filter = _filterPanel.getFilterString();
                Config.setConfigString(Config.KEY_GPSBABEL_FILTER, filter);
+
+               // Check if there is a standard file type for the selected suffix
+               int selIndex = BabelFileFormats.getIndexForFileSuffix(getSelectedSuffix());
+               // If there is none, then get the index which the user chose and set in the Config
+               if (selIndex < 0) {
+                       Config.setConfigInt(Config.KEY_IMPORT_FILE_FORMAT, _formatDropdown.getSelectedIndex());
+               }
        }
 }