Ticket #5757: RecentFiles2.patch

File RecentFiles2.patch, 2.1 KB (added by anonymous, 14 years ago)

Not only not adding files which failed to load but also removing the from the history if already there

  • src/org/openstreetmap/josm/actions/OpenFileAction.java

     
    243243                Collections.reverse(ims);
    244244
    245245                Set<String> fileHistory = new LinkedHashSet<String>();
     246                List<String> failedHistory = new ArrayList<String>();
    246247
    247248                for (FileImporter importer : ims) {
    248249                    List<File> files = new ArrayList<File>(map.get(importer));
    249250                    importData(importer, files);
     251                    // suppose all files will fail to load
     252                    List<File> failedFiles = new ArrayList<File>(files);
    250253
    251254                    if (recordHistory && !importer.isBatchImporter()) {
     255                        // only add those files which really have been opened successfully
     256                        files.retainAll(successfullyOpenedFiles);
     257                        // remove the files which didn't fail to load from the failed list
     258                        failedFiles.removeAll(successfullyOpenedFiles);
    252259                        for (File f : files) {
    253260                            fileHistory.add(f.getPath());
    254261                        }
     262                        for (File f : failedFiles) {
     263                            failedHistory.add(f.getPath());
     264                        }
    255265                    }
    256266                }
    257267
    258268                if (recordHistory) {
    259269                    Collection<String> oldFileHistory = Main.pref.getCollection("file-open.history");
    260270                    fileHistory.addAll(oldFileHistory);
     271                    // remove the files which failed to load from the list
     272                    fileHistory.removeAll(failedHistory);
    261273                    int maxsize = Math.max(0, Main.pref.getInteger("file-open.history.max-size", 15));
    262274                    Collection<String> trimmedFileHistory = new ArrayList<String>(Math.min(maxsize, fileHistory.size()));
    263275                    int i = 0;