@@ -301,39 +301,46 @@ object CsvValidatorUi extends SimpleSwingApplication {
301301 }
302302
303303 private def lastCsvPath : File =
304- loadSettings match {
305- case Some (settings) => settings.lastCsvPath.toFile
306- case None => userDir.toFile
307- }
304+ loadSettings.flatMap { settings =>
305+ List (settings.lastCsvPath.toFile, settings.lastCsvSchemaPath.toFile, settings.lastReportPath.toFile).find(_ != userDir.toFile)
306+ }.getOrElse(userDir.toFile)
308307
309308 private val csvFileChooser = new FileChooser (lastCsvPath)
310309 csvFileChooser.multiSelectionEnabled = false
311310 csvFileChooser.title = " Select a .csv file"
312311 csvFileChooser.fileFilter = new FileNameExtensionFilter (" CSV file (*.csv)" , " csv" )
313312 private val btnChooseCsvFile = new Button (" ..." )
314313
315- private def setPathToLastCsvPath (fileChooser : FileChooser ): Unit = fileChooser.selectedFile = lastCsvPath
316-
317314 btnChooseCsvFile.reactions += onClick {
318- setPathToLastCsvPath( csvFileChooser)
315+ csvFileChooser.selectedFile = lastCsvPath
319316 chooseFileOrDir(csvFileChooser, txtCsvFile, btnChooseCsvFile)
320- updateLastPath(csvFileChooser, path => Settings (path, path, path))
317+ updateLastPath(csvFileChooser, path => loadSettings match {
318+ case Some (s) => s.copy(lastCsvPath = path)
319+ case None => Settings (path, path, path)
320+ })
321321 }
322322
323323 private val lblCsvSchemaFile = new Label (" CSV Schema file:" )
324324
325325 txtCsvSchemaFile.setTransferHandler(fileHandler)
326- private val csvSchemaFileChooser = new FileChooser (lastCsvPath)
326+ private def lastCsvSchemaPath : File =
327+ loadSettings.flatMap { settings =>
328+ List (settings.lastCsvSchemaPath.toFile, settings.lastCsvPath.toFile, settings.lastReportPath.toFile).find(_ != userDir.toFile)
329+ }.getOrElse(userDir.toFile)
330+ private val csvSchemaFileChooser = new FileChooser (lastCsvSchemaPath)
327331 csvSchemaFileChooser.multiSelectionEnabled = false
328332 csvSchemaFileChooser.title = " Select a .csvs file"
329333 csvSchemaFileChooser.fileFilter = new FileNameExtensionFilter (" CSV Schema file (*.csvs)" , " csvs" +
330334 " " )
331335
332336 private val btnChooseCsvSchemaFile = new Button (" ..." )
333337 btnChooseCsvSchemaFile.reactions += onClick {
334- setPathToLastCsvPath( csvSchemaFileChooser)
338+ csvSchemaFileChooser.selectedFile = lastCsvSchemaPath
335339 chooseFileOrDir(csvSchemaFileChooser, txtCsvSchemaFile, btnChooseCsvSchemaFile)
336- updateLastPath(csvSchemaFileChooser, path => Settings (path, path, path))
340+ updateLastPath(csvSchemaFileChooser, path => loadSettings match {
341+ case Some (s) => s.copy(lastCsvSchemaPath = path)
342+ case None => Settings (path, path, path)
343+ })
337344 }
338345
339346 private val separator1 = new Separator
@@ -422,18 +429,26 @@ object CsvValidatorUi extends SimpleSwingApplication {
422429 private val btnClose = new Button (" Close" )
423430 btnClose.reactions += onClick(quit())
424431
425- private val reportFileChooser = new FileChooser (lastCsvPath)
432+ private def lastReportPath : File =
433+ loadSettings.flatMap { settings =>
434+ List (settings.lastReportPath.toFile, settings.lastCsvSchemaPath.toFile, settings.lastCsvPath.toFile).find(_ != userDir.toFile)
435+ }.getOrElse(userDir.toFile)
436+
437+ private val reportFileChooser = new FileChooser (lastReportPath)
426438 reportFileChooser.multiSelectionEnabled = false
427- val dateFormat = new SimpleDateFormat (" dd-mm-yy_HH-mm-ss" )
428- reportFileChooser.selectedFile = new File (s " csv_validator_report_ ${dateFormat.format(new Date ())}.txt " )
429439
430440 val saveLabel = " Save Results"
431441 reportFileChooser.title = saveLabel
432442 private val btnSave = new Button (saveLabel)
443+
444+ val dateFormat = new SimpleDateFormat (" dd-mm-yy_HH-mm-ss" )
433445 btnSave.reactions += onClick {
434- setPathToLastCsvPath( reportFileChooser)
446+ reportFileChooser.selectedFile = Paths .get(lastReportPath.toString, s " csv_validator_report_ ${dateFormat.format( new Date ())} .txt " ).toFile
435447 saveFile(reportFileChooser, saveToFile(txtArReport.text, _), btnSave, btnSave.text)
436- updateLastPath(reportFileChooser, path => Settings (path, path, path))
448+ updateLastPath(reportFileChooser, path => loadSettings match {
449+ case Some (s) => s.copy(lastReportPath = path)
450+ case None => Settings (path, path, path)
451+ })
437452 }
438453
439454 private val lblVersion = new Label (s " Version: ${getShortVersion}" )
0 commit comments