sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 04/10: Make "File > open" menu tolerant to directory that do not exist anymore.
Date Wed, 29 Jul 2020 16:18:57 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 1c27174757b5056848a7e07850a1e0821363bfd3
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Jul 29 14:42:15 2020 +0200

    Make "File > open" menu tolerant to directory that do not exist anymore.
---
 .../main/java/org/apache/sis/internal/gui/RecentChoices.java   | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/RecentChoices.java
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/RecentChoices.java
index 70332e2..e8d7e8c 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/RecentChoices.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/RecentChoices.java
@@ -74,12 +74,20 @@ public final class RecentChoices {
 
     /**
      * Returns the directory to show in "Open" dialog.
+     * If the directory does not exist anymore, its parent directory is returned instead.
      *
      * @return the initial open directory, or {@code null} if none.
      */
     public static File getOpenDirectory() {
         final String value = NODE.get(OPEN, null);
-        return (value != null) ? new File(value) : null;
+        if (value != null) {
+            File file = new File(value);
+            do {
+                if (file.isDirectory()) return file;
+                file = file.getParentFile();
+            } while (file != null);
+        }
+        return null;
     }
 
     /**


Mime
View raw message