### Eclipse Workspace Patch 1.0
#P josm
diff --git src/org/openstreetmap/josm/actions/OpenFileAction.java src/org/openstreetmap/josm/actions/OpenFileAction.java
index 293f636..00241c6 100644
|
|
|
|
| 93 | 93 | } else { |
| 94 | 94 | fc = createAndOpenFileChooser(true, true, null, null, FILES_AND_DIRECTORIES, true, null); |
| 95 | 95 | } |
| 96 | | if (fc == null) |
| 97 | | return; |
| 98 | | File[] files = fc.getSelectedFiles(); |
| 99 | | OpenFileTask task = new OpenFileTask(Arrays.asList(files), fc.getFileFilter()); |
| | 96 | if (fc == null) { |
| | 97 | return; |
| | 98 | } |
| | 99 | final File[] files = fc.getSelectedFiles(); |
| | 100 | final OpenFileTask task = new OpenFileTask(Arrays.asList(files), fc.getFileFilter()); |
| 100 | 101 | task.setOptions(Options.RECORD_HISTORY); |
| 101 | 102 | MainApplication.worker.submit(task); |
| 102 | 103 | } |
| … |
… |
|
| 125 | 126 | * @since 17534 ({@link Options}) |
| 126 | 127 | */ |
| 127 | 128 | public static Future<?> openFiles(List<File> fileList, Options... options) { |
| 128 | | OpenFileTask task = new OpenFileTask(fileList, null); |
| | 129 | final OpenFileTask task = new OpenFileTask(fileList, null); |
| 129 | 130 | task.setOptions(options); |
| 130 | 131 | return MainApplication.worker.submit(task); |
| 131 | 132 | } |
| … |
… |
|
| 167 | 168 | this.files.add(file); |
| 168 | 169 | } |
| 169 | 170 | } else { |
| 170 | | String message = tr("Unable to locate file ''{0}''.", file.getPath()); |
| | 171 | final String message = tr("Unable to locate file ''{0}''.", file.getPath()); |
| 171 | 172 | Logging.warn(message); |
| 172 | 173 | new Notification(message).setIcon(JOptionPane.WARNING_MESSAGE).show(); |
| 173 | 174 | } |
| … |
… |
|
| 220 | 221 | |
| 221 | 222 | @Override |
| 222 | 223 | protected void finish() { |
| 223 | | MapFrame map = MainApplication.getMap(); |
| | 224 | final MapFrame map = MainApplication.getMap(); |
| 224 | 225 | if (map != null) { |
| 225 | 226 | map.repaint(); |
| 226 | 227 | } |
| … |
… |
|
| 275 | 276 | |
| 276 | 277 | @Override |
| 277 | 278 | protected void realRun() throws SAXException, IOException, OsmTransferException { |
| 278 | | if (Utils.isEmpty(files)) return; |
| 279 | | List<Layer> oldLayers = MainApplication.getLayerManager().getLayers(); |
| | 279 | if (Utils.isEmpty(files)) { |
| | 280 | return; |
| | 281 | } |
| | 282 | final List<Layer> oldLayers = MainApplication.getLayerManager().getLayers(); |
| 280 | 283 | |
| 281 | 284 | /* |
| 282 | 285 | * Find the importer with the chosen file filter |
| … |
… |
|
| 300 | 303 | |
| 301 | 304 | if (chosenImporter != null) { |
| 302 | 305 | // The importer was explicitly chosen, so use it. |
| 303 | | List<File> filesNotMatchingWithImporter = new LinkedList<>(); |
| 304 | | List<File> filesMatchingWithImporter = new LinkedList<>(); |
| | 306 | final List<File> filesNotMatchingWithImporter = new LinkedList<>(); |
| | 307 | final List<File> filesMatchingWithImporter = new LinkedList<>(); |
| 305 | 308 | for (final File f : files) { |
| 306 | 309 | if (!chosenImporter.acceptFile(f)) { |
| 307 | 310 | if (f.isDirectory()) { |
| … |
… |
|
| 327 | 330 | } |
| 328 | 331 | } else { |
| 329 | 332 | // find appropriate importer |
| 330 | | MultiMap<FileImporter, File> importerMap = new MultiMap<>(); |
| 331 | | List<File> filesWithUnknownImporter = new LinkedList<>(); |
| 332 | | List<File> urlFiles = new LinkedList<>(); |
| 333 | | FILES: for (File f : files) { |
| | 333 | final MultiMap<FileImporter, File> importerMap = new MultiMap<>(); |
| | 334 | final List<File> filesWithUnknownImporter = new LinkedList<>(); |
| | 335 | final List<File> urlFiles = new LinkedList<>(); |
| | 336 | for (File f : files) { |
| | 337 | boolean imported = false; |
| 334 | 338 | for (FileImporter importer : ExtensionFileFilter.getImporters()) { |
| 335 | 339 | if (importer.acceptFile(f)) { |
| 336 | 340 | importerMap.put(importer, f); |
| 337 | | continue FILES; |
| | 341 | imported = true; |
| | 342 | break; |
| 338 | 343 | } |
| 339 | 344 | } |
| | 345 | if (imported) { |
| | 346 | continue; |
| | 347 | } |
| | 348 | |
| 340 | 349 | if (URL_FILE_FILTER.accept(f)) { |
| 341 | 350 | urlFiles.add(f); |
| 342 | 351 | } else { |
| 343 | 352 | filesWithUnknownImporter.add(f); |
| 344 | 353 | } |
| 345 | 354 | } |
| | 355 | |
| 346 | 356 | if (!filesWithUnknownImporter.isEmpty()) { |
| 347 | 357 | alertFilesWithUnknownImporter(filesWithUnknownImporter); |
| 348 | 358 | } |
| 349 | | List<FileImporter> importers = new ArrayList<>(importerMap.keySet()); |
| 350 | | Collections.sort(importers); |
| 351 | | Collections.reverse(importers); |
| | 359 | final List<FileImporter> importers = new ArrayList<>(importerMap.keySet()); |
| | 360 | importers.sort(Collections.reverseOrder()); |
| 352 | 361 | |
| 353 | 362 | for (FileImporter importer : importers) { |
| 354 | 363 | importData(importer, new ArrayList<>(importerMap.get(importer))); |
| 355 | 364 | } |
| 356 | 365 | |
| 357 | | Pattern urlPattern = Pattern.compile(".*(https?://.*)"); |
| | 366 | final Pattern urlPattern = Pattern.compile(".*(https?://.*)"); |
| 358 | 367 | for (File urlFile: urlFiles) { |
| 359 | 368 | try (BufferedReader reader = Files.newBufferedReader(urlFile.toPath(), StandardCharsets.UTF_8)) { |
| 360 | 369 | String line; |
| 361 | 370 | while ((line = reader.readLine()) != null) { |
| 362 | | Matcher m = urlPattern.matcher(line); |
| | 371 | final Matcher m = urlPattern.matcher(line); |
| 363 | 372 | if (m.matches()) { |
| 364 | | String url = m.group(1); |
| | 373 | final String url = m.group(1); |
| 365 | 374 | MainApplication.getMenu().openLocation.openUrl(false, url); |
| 366 | 375 | } |
| 367 | 376 | } |
| … |
… |
|
| 374 | 383 | } |
| 375 | 384 | |
| 376 | 385 | if (this.options.contains(Options.RECORD_HISTORY)) { |
| 377 | | Collection<String> oldFileHistory = Config.getPref().getList("file-open.history"); |
| | 386 | final Collection<String> oldFileHistory = Config.getPref().getList("file-open.history"); |
| 378 | 387 | fileHistory.addAll(oldFileHistory); |
| 379 | 388 | // remove the files which failed to load from the list |
| 380 | 389 | fileHistory.removeAll(failedAll); |
| 381 | | int maxsize = Math.max(0, Config.getPref().getInt("file-open.history.max-size", 15)); |
| | 390 | final int maxsize = Math.max(0, Config.getPref().getInt("file-open.history.max-size", 15)); |
| 382 | 391 | PreferencesUtils.putListBounded(Config.getPref(), "file-open.history", maxsize, new ArrayList<>(fileHistory)); |
| 383 | 392 | } |
| 384 | 393 | if (!canceled && !GraphicsEnvironment.isHeadless()) { |
| … |
… |
|
| 390 | 399 | // We do have to wrap the EDT call in a worker call, since layers may be created in the EDT. |
| 391 | 400 | // And the layer(s) must be added to the layer list in order for the dialog to work properly. |
| 392 | 401 | MainApplication.worker.execute(() -> GuiHelper.runInEDT(() -> { |
| 393 | | List<Layer> newLayers = MainApplication.getLayerManager().getLayers(); |
| | 402 | final List<Layer> newLayers = MainApplication.getLayerManager().getLayers(); |
| 394 | 403 | // see #23728: open first image of topmost new image layer |
| 395 | 404 | for (Layer l : newLayers) { |
| 396 | | if (oldLayers.contains(l)) |
| 397 | | return; |
| | 405 | if (oldLayers.contains(l)) { |
| | 406 | return; |
| | 407 | } |
| 398 | 408 | if (l instanceof GeoImageLayer) { |
| 399 | | GeoImageLayer imageLayer = (GeoImageLayer) l; |
| | 409 | final GeoImageLayer imageLayer = (GeoImageLayer) l; |
| 400 | 410 | imageLayer.jumpToNextMarker(); |
| 401 | 411 | return; |
| 402 | 412 | } |
| … |
… |
|
| 412 | 422 | public void importData(FileImporter importer, List<File> files) { |
| 413 | 423 | importer.setOptions(this.options.toArray(new Options[0])); |
| 414 | 424 | if (importer.isBatchImporter()) { |
| 415 | | if (canceled) return; |
| 416 | | String msg = trn("Opening {0} file...", "Opening {0} files...", files.size(), files.size()); |
| | 425 | if (canceled) { |
| | 426 | return; |
| | 427 | } |
| | 428 | final String msg = trn("Opening {0} file...", "Opening {0} files...", files.size(), files.size()); |
| 417 | 429 | getProgressMonitor().setCustomText(msg); |
| 418 | 430 | getProgressMonitor().indeterminateSubTask(msg); |
| 419 | 431 | if (importer.importDataHandleExceptions(files, getProgressMonitor().createSubTaskMonitor(files.size(), false))) { |
| … |
… |
|
| 421 | 433 | } |
| 422 | 434 | } else { |
| 423 | 435 | for (File f : files) { |
| 424 | | if (canceled) return; |
| | 436 | if (canceled) { |
| | 437 | return; |
| | 438 | } |
| 425 | 439 | getProgressMonitor().indeterminateSubTask(tr("Opening file ''{0}'' ...", f.getAbsolutePath())); |
| 426 | 440 | if (importer.importDataHandleExceptions(f, getProgressMonitor().createSubTaskMonitor(1, false))) { |
| 427 | 441 | successfullyOpenedFiles.add(f); |