diff src/name/blackcap/imageprep/Menus.kt @ 5:884f1415a330

Rationalized directory management.
author David Barts <n5jrn@me.com>
date Fri, 17 Jul 2020 17:11:43 -0700
parents 09dcd475d1bf
children 801cdc780ca8
line wrap: on
line diff
--- a/src/name/blackcap/imageprep/Menus.kt	Fri Jul 17 14:51:41 2020 -0700
+++ b/src/name/blackcap/imageprep/Menus.kt	Fri Jul 17 17:11:43 2020 -0700
@@ -28,6 +28,9 @@
  * the Mac gives us a gratuitous menu bar entry for handling some stuff.
  */
 class MyMenuBar: JMenuBar() {
+    var currentInputDirectory = File(System.getProperty("user.dir"))
+    var currentOutputDirectory = File(Settings.outputTo)
+
     init {
         add(JMenu("File").apply {
             add(JMenuItem("Open & Scaleā€¦").apply {
@@ -75,9 +78,11 @@
 
     private fun doOpen() {
         val chooser = JFileChooser().apply {
+            currentDirectory = currentInputDirectory
             fileFilter = FileNameExtensionFilter("Image Files", *ImageIO.getReaderFileSuffixes())
         }
         if (chooser.showOpenDialog(Application.mainFrame) == JFileChooser.APPROVE_OPTION) {
+            currentInputDirectory = chooser.selectedFile.canonicalFile.parentFile
             RotateDialog.makeDialog(chooser.selectedFile)
         }
     }
@@ -100,18 +105,18 @@
         }
         val outName = splitext(w.file.name).first + Settings.outputSuffix + ".jpg"
         val chooser = JFileChooser().apply {
-            selectedFile = File(
-                if (Settings.outputToInputDir) w.file.parent else Settings.outputTo,
-                outName)
+            currentDirectory = currentOutputDirectory
+            selectedFile = File(currentOutputDirectory, outName)
         }
         if (chooser.showSaveDialog(Application.mainFrame) != JFileChooser.APPROVE_OPTION) {
             return
         }
+        currentOutputDirectory = chooser.selectedFile.canonicalFile.parentFile
         val (name, ext) = splitext(chooser.selectedFile.name)
         val file = if (ext.toLowerCase() in setOf(".jpg", ".jpeg")) {
             chooser.selectedFile
         } else {
-            File(chooser.selectedFile.parent, name + ".jpg")
+            File(currentOutputDirectory, name + ".jpg")
         }
         if (file.exists() && JOptionPane.showConfirmDialog(w, "File ${file.name} already exists. Overwrite?", "Confirm Overwrite", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
             return