From 8752832bf45ed780abb933c20fb54ed61b834897 Mon Sep 17 00:00:00 2001 From: Steven Yi Date: Sat, 29 Sep 2018 22:58:10 -0400 Subject: [PATCH] fix default directory and file not being set [fixes #401] --- ChangeLog | 3 ++ .../blue/ui/utilities/FileChooserManager.java | 28 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9da556d7e..bfe691855 100755 --- a/ChangeLog +++ b/ChangeLog @@ -67,6 +67,9 @@ FIX * Fix resizing of timeline on movement or resizing of Score Objects, whether by mouse or by ScoreObject Properties window +* Issue #401: Fix setting of default/last directory/file path for open/save + file dialogs + > Notes for 2.7.3 < [release 2017.12.15] diff --git a/blue-ui-utilities/src/blue/ui/utilities/FileChooserManager.java b/blue-ui-utilities/src/blue/ui/utilities/FileChooserManager.java index 910c38c97..33ff1e225 100644 --- a/blue-ui-utilities/src/blue/ui/utilities/FileChooserManager.java +++ b/blue-ui-utilities/src/blue/ui/utilities/FileChooserManager.java @@ -99,31 +99,42 @@ public List showOpenDialog(Object fileChooserId, Component parent) { if (temp.directoriesOnly) { DirectoryChooser chooser = new DirectoryChooser(); chooser.setTitle(temp.dialogTitle); + + if(temp.currentDirectory != null) { + chooser.setInitialDirectory(temp.currentDirectory); + } + File f = chooser.showDialog(s); if (f != null) { retVal.add(f); + temp.currentDirectory = f; } } else { FileChooser f = new FileChooser(); f.setTitle(temp.dialogTitle); f.getExtensionFilters().addAll(temp.filters); f.getExtensionFilters().add(allFilter); - if (temp.selectedFile != null) { - f.setInitialFileName(temp.selectedFile.getName()); - } + if (temp.currentDirectory != null) { f.setInitialDirectory(temp.currentDirectory); + } else if(temp.selectedFile != null){ + f.setInitialDirectory(temp.selectedFile.getParentFile()); + } + if (temp.selectedFile != null) { + f.setInitialFileName(temp.selectedFile.getName()); } if (temp.isMultiSelect) { temp.selectedFile = null; List found = f.showOpenMultipleDialog(s); if (found != null) { + temp.currentDirectory = found.get(0).getParentFile(); retVal.addAll(found); } } else { File ret = f.showOpenDialog(s); if (ret != null) { + temp.currentDirectory = ret.getParentFile(); retVal.add(ret); } } @@ -180,15 +191,19 @@ public File showSaveDialog(Object fileChooserId, Component parent) { f.setTitle(temp.dialogTitle); f.getExtensionFilters().addAll(temp.filters); - if (temp.selectedFile != null) { - f.setInitialFileName(temp.selectedFile.getName()); - } if (temp.currentDirectory != null) { f.setInitialDirectory(temp.currentDirectory); + } else if(temp.selectedFile != null) { + f.setInitialDirectory(temp.selectedFile.getParentFile()); + } + if (temp.selectedFile != null) { + f.setInitialFileName(temp.selectedFile.getName()); } File ret = f.showSaveDialog(s); if (ret != null) { + temp.currentDirectory = null; + temp.selectedFile = ret; retVal.set(ret); } @@ -214,6 +229,7 @@ private DialogInfoSet getDialogInfoSet(Object fileChooserId) { DialogInfoSet temp = new DialogInfoSet(); temp.selectedFile = new File(System.getProperty("user.home")); + temp.currentDirectory = new File(System.getProperty("user.home")); dialogInfoSets.put(fileChooserId, temp);