From 19c82428e7cd307ed629978ea6801f3c116775be Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Sat, 1 May 2021 13:23:22 +0000 Subject: [PATCH] Optionally display parent directories This adds a configuration option to show ".." entries in directory listings. This will work correctly on all platforms, but may look out of place on non-Unix platforms, and is therefore not enabled by default. Fix: https://github.com/io7m/jwheatsheaf/issues/23 --- README-CHANGES.xml | 9 +- .../api/JWFileChooserConfigurationType.java | 13 ++ .../examples/ExampleViewController.java | 9 ++ .../io7m/jwheatsheaf/examples/example.fxml | 7 + .../JWFileChooserParentDirectoryTest.java | 129 ++++++++++++++++++ .../jwheatsheaf/tests/JWFileItemsTest.java | 9 +- .../internal/JWFileChooserViewController.java | 10 +- .../jwheatsheaf/ui/internal/JWFileItems.java | 11 +- .../JWFileSourceEntryFilesystemRoot.java | 8 +- 9 files changed, 195 insertions(+), 10 deletions(-) create mode 100644 com.io7m.jwheatsheaf.tests/src/test/java/com/io7m/jwheatsheaf/tests/JWFileChooserParentDirectoryTest.java diff --git a/README-CHANGES.xml b/README-CHANGES.xml index 72162a7..ff83777 100644 --- a/README-CHANGES.xml +++ b/README-CHANGES.xml @@ -39,7 +39,7 @@ - + @@ -81,11 +81,16 @@ - + + + + + + diff --git a/com.io7m.jwheatsheaf.api/src/main/java/com/io7m/jwheatsheaf/api/JWFileChooserConfigurationType.java b/com.io7m.jwheatsheaf.api/src/main/java/com/io7m/jwheatsheaf/api/JWFileChooserConfigurationType.java index 72160d8..57b8aa6 100644 --- a/com.io7m.jwheatsheaf.api/src/main/java/com/io7m/jwheatsheaf/api/JWFileChooserConfigurationType.java +++ b/com.io7m.jwheatsheaf.api/src/main/java/com/io7m/jwheatsheaf/api/JWFileChooserConfigurationType.java @@ -133,6 +133,19 @@ default boolean allowDirectoryCreation() return true; } + /** + * Determine whether or not to show a link to the parent directory inside + * the file listing. This entry is always called "..". + * + * @return {@code true} if the directory listing will contain ".." + */ + + @Value.Default + default boolean showParentDirectory() + { + return false; + } + /** * @return The date/time formatter used to display file times */ diff --git a/com.io7m.jwheatsheaf.examples/src/main/java/com/io7m/jwheatsheaf/examples/ExampleViewController.java b/com.io7m.jwheatsheaf.examples/src/main/java/com/io7m/jwheatsheaf/examples/ExampleViewController.java index 75704ea..9fad5c2 100644 --- a/com.io7m.jwheatsheaf.examples/src/main/java/com/io7m/jwheatsheaf/examples/ExampleViewController.java +++ b/com.io7m.jwheatsheaf.examples/src/main/java/com/io7m/jwheatsheaf/examples/ExampleViewController.java @@ -66,6 +66,8 @@ public final class ExampleViewController implements Initializable @FXML private CheckBox homeDirectory; @FXML + private CheckBox parentDirectory; + @FXML private ChoiceBox action; @FXML private TextField title; @@ -143,6 +145,12 @@ private void onHomeDirectoryChanged() } + @FXML + private void onParentDirectoryChanged() + { + + } + @FXML private void onOpenSelected() throws IOException @@ -164,6 +172,7 @@ private void onOpenSelected() final var configurationBuilder = JWFileChooserConfiguration.builder() .setAllowDirectoryCreation(this.allowDirectoryCreation.isSelected()) + .setShowParentDirectory(this.parentDirectory.isSelected()) .setFileSystem(fileSystem) .setCssStylesheet(ExampleViewController.class.getResource(this.cssSelection.getValue())) .setFileImageSet(imageSet) diff --git a/com.io7m.jwheatsheaf.examples/src/main/resources/com/io7m/jwheatsheaf/examples/example.fxml b/com.io7m.jwheatsheaf.examples/src/main/resources/com/io7m/jwheatsheaf/examples/example.fxml index 603ba7f..6fc744b 100644 --- a/com.io7m.jwheatsheaf.examples/src/main/resources/com/io7m/jwheatsheaf/examples/example.fxml +++ b/com.io7m.jwheatsheaf.examples/src/main/resources/com/io7m/jwheatsheaf/examples/example.fxml @@ -48,6 +48,13 @@ + + + + + + +