@@ -283,54 +283,38 @@ object CsvValidatorUi extends SimpleSwingApplication {
283283 }
284284 }
285285
286- private val csvFileChooser = new FileChooser (loadSettings match {
287- case Some (s) =>
288- s.lastCsvPath.toFile
289- case None =>
290- userDir.toFile
291- })
286+ private def lastCsvPath : File =
287+ loadSettings match {
288+ case Some (settings) => settings.lastCsvPath.toFile
289+ case None => userDir.toFile
290+ }
291+
292+ private val csvFileChooser = new FileChooser (lastCsvPath)
292293 csvFileChooser.title = " Select a .csv file"
293294 csvFileChooser.fileFilter = new FileNameExtensionFilter (" CSV file (*.csv)" , " csv" )
294295 private val btnChooseCsvFile = new Button (" ..." )
295296
297+ private def setPathToLastCsvPath (fileChooser : FileChooser ): Unit = fileChooser.selectedFile = lastCsvPath
298+
296299 btnChooseCsvFile.reactions += onClick {
300+ setPathToLastCsvPath(csvFileChooser)
297301 chooseFile(csvFileChooser, txtCsvFile, btnChooseCsvFile)
298- updateLastPath(csvFileChooser, {
299- path =>
300- loadSettings match {
301- case Some (s) =>
302- s.copy(lastCsvPath = path)
303- case None =>
304- Settings (path, path, path)
305- }
306- })
302+ updateLastPath(csvFileChooser, path => Settings (path, path, path))
307303 }
308304
309305 private val lblCsvSchemaFile = new Label (" CSV Schema file:" )
310306
311307 txtCsvSchemaFile.setTransferHandler(fileHandler)
312- private val csvSchemaFileChooser = new FileChooser (loadSettings match {
313- case Some (s) =>
314- s.lastCsvSchemaPath.toFile
315- case None =>
316- userDir.toFile
317- })
308+ private val csvSchemaFileChooser = new FileChooser (lastCsvPath)
318309 csvSchemaFileChooser.title = " Select a .csvs file"
319310 csvSchemaFileChooser.fileFilter = new FileNameExtensionFilter (" CSV Schema file (*.csvs)" , " csvs" +
320311 " " )
321312
322313 private val btnChooseCsvSchemaFile = new Button (" ..." )
323314 btnChooseCsvSchemaFile.reactions += onClick {
315+ setPathToLastCsvPath(csvSchemaFileChooser)
324316 chooseFile(csvSchemaFileChooser, txtCsvSchemaFile, btnChooseCsvSchemaFile)
325- updateLastPath(csvSchemaFileChooser, {
326- path =>
327- loadSettings match {
328- case Some (s) =>
329- s.copy(lastCsvSchemaPath = path)
330- case None =>
331- Settings (path, path, path)
332- }
333- })
317+ updateLastPath(csvSchemaFileChooser, path => Settings (path, path, path))
334318 }
335319
336320 private val separator1 = new Separator
@@ -417,29 +401,17 @@ object CsvValidatorUi extends SimpleSwingApplication {
417401 private val btnClose = new Button (" Close" )
418402 btnClose.reactions += onClick(quit())
419403
420- private val reportFileChooser = new FileChooser (loadSettings match {
421- case Some (s) =>
422- s.lastReportPath.toFile
423- case None =>
424- userDir.toFile
425- })
404+ private val reportFileChooser = new FileChooser (lastCsvPath)
426405 val dateFormat = new SimpleDateFormat (" dd-mm-yy_HH-mm-ss" )
427406 reportFileChooser.selectedFile = new File (s " csv_validator_report_ ${dateFormat.format(new Date ())}.txt " )
428407
429408 val saveLabel = " Save Results"
430409 reportFileChooser.title = saveLabel
431410 private val btnSave = new Button (saveLabel)
432411 btnSave.reactions += onClick {
412+ setPathToLastCsvPath(reportFileChooser)
433413 saveFile(reportFileChooser, saveToFile(txtArReport.text, _), btnSave, btnSave.text)
434- updateLastPath(reportFileChooser, {
435- path =>
436- loadSettings match {
437- case Some (s) =>
438- s.copy(lastReportPath = path)
439- case None =>
440- Settings (path, path, path)
441- }
442- })
414+ updateLastPath(reportFileChooser, path => Settings (path, path, path))
443415 }
444416
445417 private val lblVersion = new Label (s " Version: ${getShortVersion}" )
@@ -469,8 +441,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
469441
470442 def updateLastPath (fileChooser : FileChooser , sink : Path => Settings ) : Unit = {
471443 Option (fileChooser.selectedFile) match {
472- case Some (selection) =>
473- saveSettings(sink(selection.toPath.getParent))
444+ case Some (selection) => saveSettings(sink(selection.toPath))
474445 case None =>
475446 }
476447 }
0 commit comments