diff --git a/app/gui-javafx/src/main/java/org/applecommander/javafx/AppleCommanderFX.java b/app/gui-javafx/src/main/java/org/applecommander/javafx/AppleCommanderFX.java index 9aabf3c0..59d9b1bf 100644 --- a/app/gui-javafx/src/main/java/org/applecommander/javafx/AppleCommanderFX.java +++ b/app/gui-javafx/src/main/java/org/applecommander/javafx/AppleCommanderFX.java @@ -35,6 +35,7 @@ import java.util.prefs.Preferences; public class AppleCommanderFX extends Application { private static final String IMAGE_DIRECTORY_KEY = "image_directory"; private static final String THEME_SELECTION = "theme_selection"; + private static final String EXPORT_OPTION = "export_option"; @Override public void start(Stage stage) throws Exception { @@ -97,6 +98,19 @@ public class AppleCommanderFX extends Application { prefs.put(THEME_SELECTION, themeSelection.name()); } + public static Optional getExportOption() { + Preferences prefs = Preferences.userNodeForPackage(AppleCommanderFX.class); + String exportName = prefs.get(EXPORT_OPTION, null); + if (exportName == null || exportName.isBlank()) { + return Optional.of(ExportOption.RAW_BINARY); + } + return Optional.of(ExportOption.valueOf(exportName)); + } + public static void setExportOption(ExportOption exportOption) { + Preferences prefs = Preferences.userNodeForPackage(AppleCommanderFX.class); + prefs.put(EXPORT_OPTION, exportOption.name()); + } + public enum ThemeSelection { MODENA("Modena (JavaFX default)", Application.STYLESHEET_MODENA), CASPIAN("Caspian (JavaFX legacy)", Application.STYLESHEET_CASPIAN), @@ -128,4 +142,20 @@ public class AppleCommanderFX extends Application { return this != DRACULA; } } + + public enum ExportOption { + RAW_BINARY("Raw Binary (filename)"), + APPLE_SINGLE("AppleSingle (filename.as)"), + ATTRIBUTE_PRESERVATION("ProDOS Attribute Preservation (filename#TTAAAA)"); + + private final String description; + + ExportOption(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + } } diff --git a/app/gui-javafx/src/main/java/org/applecommander/javafx/SettingsDialog.java b/app/gui-javafx/src/main/java/org/applecommander/javafx/SettingsDialog.java index 8b103d9b..60af0dd9 100644 --- a/app/gui-javafx/src/main/java/org/applecommander/javafx/SettingsDialog.java +++ b/app/gui-javafx/src/main/java/org/applecommander/javafx/SettingsDialog.java @@ -14,10 +14,11 @@ import javafx.stage.Window; import java.util.Objects; import java.util.Optional; +import static org.applecommander.javafx.AppleCommanderFX.*; import static org.applecommander.javafx.FxUtils.createGenericSelectionPage; public class SettingsDialog { - private final ObjectProperty themeSelection = new SimpleObjectProperty<>(); + private final ObjectProperty themeSelection = new SimpleObjectProperty<>(); private final ObjectProperty exportOption = new SimpleObjectProperty<>(); private final Dialog dialog; @@ -25,8 +26,8 @@ public class SettingsDialog { public SettingsDialog() { Tab themeTab = new Tab("Theme"); themeTab.setClosable(false); - themeTab.setContent(createGenericSelectionPage("Please choose a theme:", AppleCommanderFX.ThemeSelection.values(), - AppleCommanderFX.ThemeSelection::getDescription, themeSelection)); + themeTab.setContent(createGenericSelectionPage("Please choose a theme:", ThemeSelection.values(), + ThemeSelection::getDescription, themeSelection)); Tab exportTab = new Tab("Export"); exportTab.setClosable(false); @@ -39,15 +40,23 @@ public class SettingsDialog { dialog = new Dialog<>(); dialog.setTitle("Settings"); - dialog.setHeaderText("AppleCommanderFX Settings"); + dialog.setHeaderText("Settings"); dialog.getDialogPane().setContent(tabPane); dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CLOSE, ButtonType.APPLY); + + themeSelection.addListener((_, _, newValue) -> { + // This gives users a preview when clicking the radio buttons + if (newValue != null) { + newValue.apply(); + } + }); } public void showAndWait(Stage parent) { Objects.requireNonNull(parent); - AppleCommanderFX.getThemeSelection().ifPresent(themeSelection::set); + getThemeSelection().ifPresent(themeSelection::set); + getExportOption().ifPresent(exportOption::set); Window window = dialog.getDialogPane().getScene().getWindow(); @@ -70,26 +79,15 @@ public class SettingsDialog { Optional button = dialog.showAndWait(); button.ifPresent(result -> { if (result == ButtonType.APPLY) { - AppleCommanderFX.ThemeSelection theme = themeSelection.get(); - AppleCommanderFX.setThemeSelection(theme); - theme.apply(); + if (themeSelection.isNotNull().get()) { + setThemeSelection(themeSelection.get()); + } + if (exportOption.isNotNull().get()) { + setExportOption(exportOption.get()); + } } }); - } - - enum ExportOption { - RAW_BINARY("Raw Binary (filename)"), - APPLE_SINGLE("AppleSingle (filename.as)"), - ATTRIBUTE_PRESERVATION("ProDOS Attribute Preservation (filename#TTAAAA)"); - - private final String description; - - ExportOption(String description) { - this.description = description; - } - - public String getDescription() { - return description; - } + // Always go back to what we've set + getThemeSelection().ifPresent(ThemeSelection::apply); } }