Changeset 7453 in josm for trunk/src


Ignore:
Timestamp:
2014-08-28T19:43:57+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #10433 - Files not saved to "Open Recent ->" menu if opened with a file filter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java

    r7315 r7453  
    4242
    4343/**
    44  * Open a file chooser dialog and select an file to import. Then call the gpx-import driver. Finally
    45  * open an internal frame into the main window with the gpx data shown.
     44 * Open a file chooser dialog and select a file to import.
    4645 *
    4746 * @author imi
     47 * @since 1146
    4848 */
    4949public class OpenFileAction extends DiskAccessAction {
     
    9494
    9595    public static class OpenFileTask extends PleaseWaitRunnable {
    96         private List<File> files;
    97         private List<File> successfullyOpenedFiles = new ArrayList<>();
    98         private FileFilter fileFilter;
     96        private final List<File> files;
     97        private final List<File> successfullyOpenedFiles = new ArrayList<>();
     98        private final Set<String> fileHistory = new LinkedHashSet<>();
     99        private final Set<String> failedAll = new HashSet<>();
     100        private final FileFilter fileFilter;
    99101        private boolean canceled;
    100102        private boolean recordHistory = false;
     
    269271                Collections.reverse(importers);
    270272
    271                 Set<String> fileHistory = new LinkedHashSet<>();
    272                 Set<String> failedAll = new HashSet<>();
    273 
    274273                for (FileImporter importer : importers) {
    275                     List<File> files = new ArrayList<>(importerMap.get(importer));
    276                     importData(importer, files);
    277                     // suppose all files will fail to load
    278                     List<File> failedFiles = new ArrayList<>(files);
    279 
    280                     if (recordHistory && !importer.isBatchImporter()) {
    281                         // remove the files which didn't fail to load from the failed list
    282                         failedFiles.removeAll(successfullyOpenedFiles);
    283                         for (File f : successfullyOpenedFiles) {
    284                             fileHistory.add(f.getCanonicalPath());
    285                         }
    286                         for (File f : failedFiles) {
    287                             failedAll.add(f.getCanonicalPath());
    288                         }
    289                     }
     274                    importData(importer, new ArrayList<>(importerMap.get(importer)));
    290275                }
    291276
     
    304289                    }
    305290                }
    306 
    307                 if (recordHistory) {
    308                     Collection<String> oldFileHistory = Main.pref.getCollection("file-open.history");
    309                     fileHistory.addAll(oldFileHistory);
    310                     // remove the files which failed to load from the list
    311                     fileHistory.removeAll(failedAll);
    312                     int maxsize = Math.max(0, Main.pref.getInteger("file-open.history.max-size", 15));
    313                     Main.pref.putCollectionBounded("file-open.history", maxsize, fileHistory);
    314                 }
     291            }
     292
     293            if (recordHistory) {
     294                Collection<String> oldFileHistory = Main.pref.getCollection("file-open.history");
     295                fileHistory.addAll(oldFileHistory);
     296                // remove the files which failed to load from the list
     297                fileHistory.removeAll(failedAll);
     298                int maxsize = Math.max(0, Main.pref.getInteger("file-open.history.max-size", 15));
     299                Main.pref.putCollectionBounded("file-open.history", maxsize, fileHistory);
    315300            }
    316301        }
     
    334319                }
    335320            }
     321            if (recordHistory && !importer.isBatchImporter()) {
     322                for (File f : files) {
     323                    try {
     324                        if (successfullyOpenedFiles.contains(f)) {
     325                            fileHistory.add(f.getCanonicalPath());
     326                        } else {
     327                            failedAll.add(f.getCanonicalPath());
     328                        }
     329                    } catch (IOException e) {
     330                        Main.warn(e);
     331                    }
     332                }
     333            }
    336334        }
    337335
Note: See TracChangeset for help on using the changeset viewer.