浏览代码

moved interface settings to separate preferences tab

Sebastian Stenzel 3 年之前
父节点
当前提交
9b00cd923c

+ 2 - 125
src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java

@@ -1,37 +1,25 @@
 package org.cryptomator.ui.preferences;
 
-import com.google.common.base.Strings;
 import org.cryptomator.common.Environment;
-import org.cryptomator.common.LicenseHolder;
 import org.cryptomator.common.settings.Settings;
-import org.cryptomator.common.settings.UiTheme;
 import org.cryptomator.integrations.autostart.AutoStartProvider;
 import org.cryptomator.integrations.autostart.ToggleAutoStartFailedException;
 import org.cryptomator.integrations.keychain.KeychainAccessProvider;
-import org.cryptomator.launcher.SupportedLanguages;
 import org.cryptomator.ui.common.FxController;
 import org.cryptomator.ui.fxapp.FxApplicationWindows;
-import org.cryptomator.ui.traymenu.TrayMenuComponent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.inject.Inject;
 import javafx.application.Application;
 import javafx.beans.binding.Bindings;
-import javafx.beans.property.ObjectProperty;
-import javafx.beans.value.ObservableValue;
 import javafx.fxml.FXML;
-import javafx.geometry.NodeOrientation;
 import javafx.scene.control.CheckBox;
 import javafx.scene.control.ChoiceBox;
-import javafx.scene.control.RadioButton;
-import javafx.scene.control.Toggle;
 import javafx.scene.control.ToggleGroup;
 import javafx.stage.Stage;
 import javafx.util.StringConverter;
-import java.util.Locale;
 import java.util.Optional;
-import java.util.ResourceBundle;
 import java.util.Set;
 
 @PreferencesScoped
@@ -41,39 +29,23 @@ public class GeneralPreferencesController implements FxController {
 
 	private final Stage window;
 	private final Settings settings;
-	private final boolean trayMenuInitialized;
-	private final boolean trayMenuSupported;
 	private final Optional<AutoStartProvider> autoStartProvider;
-	private final ObjectProperty<SelectedPreferencesTab> selectedTabProperty;
-	private final LicenseHolder licenseHolder;
-	private final ResourceBundle resourceBundle;
 	private final Application application;
 	private final Environment environment;
 	private final Set<KeychainAccessProvider> keychainAccessProviders;
 	private final FxApplicationWindows appWindows;
-	public ChoiceBox<UiTheme> themeChoiceBox;
 	public ChoiceBox<KeychainAccessProvider> keychainBackendChoiceBox;
-	public CheckBox showMinimizeButtonCheckbox;
-	public CheckBox showTrayIconCheckbox;
 	public CheckBox startHiddenCheckbox;
-	public ChoiceBox<String> preferredLanguageChoiceBox;
 	public CheckBox debugModeCheckbox;
 	public CheckBox autoStartCheckbox;
 	public ToggleGroup nodeOrientation;
-	public RadioButton nodeOrientationLtr;
-	public RadioButton nodeOrientationRtl;
 
 	@Inject
-	GeneralPreferencesController(@PreferencesWindow Stage window, Settings settings, TrayMenuComponent trayMenu, Optional<AutoStartProvider> autoStartProvider, Set<KeychainAccessProvider> keychainAccessProviders, ObjectProperty<SelectedPreferencesTab> selectedTabProperty, LicenseHolder licenseHolder, ResourceBundle resourceBundle, Application application, Environment environment, FxApplicationWindows appWindows) {
+	GeneralPreferencesController(@PreferencesWindow Stage window, Settings settings, Optional<AutoStartProvider> autoStartProvider, Set<KeychainAccessProvider> keychainAccessProviders, Application application, Environment environment, FxApplicationWindows appWindows) {
 		this.window = window;
 		this.settings = settings;
-		this.trayMenuInitialized = trayMenu.isInitialized();
-		this.trayMenuSupported = trayMenu.isSupported();
 		this.autoStartProvider = autoStartProvider;
 		this.keychainAccessProviders = keychainAccessProviders;
-		this.selectedTabProperty = selectedTabProperty;
-		this.licenseHolder = licenseHolder;
-		this.resourceBundle = resourceBundle;
 		this.application = application;
 		this.environment = environment;
 		this.appWindows = appWindows;
@@ -81,32 +53,12 @@ public class GeneralPreferencesController implements FxController {
 
 	@FXML
 	public void initialize() {
-		themeChoiceBox.getItems().addAll(UiTheme.applicableValues());
-		if (!themeChoiceBox.getItems().contains(settings.theme().get())) {
-			settings.theme().set(UiTheme.LIGHT);
-		}
-		themeChoiceBox.valueProperty().bindBidirectional(settings.theme());
-		themeChoiceBox.setConverter(new UiThemeConverter(resourceBundle));
-
-		showMinimizeButtonCheckbox.selectedProperty().bindBidirectional(settings.showMinimizeButton());
-
-		showTrayIconCheckbox.selectedProperty().bindBidirectional(settings.showTrayIcon());
-
 		startHiddenCheckbox.selectedProperty().bindBidirectional(settings.startHidden());
 
-		preferredLanguageChoiceBox.getItems().add(null);
-		preferredLanguageChoiceBox.getItems().addAll(SupportedLanguages.LANGUAGAE_TAGS);
-		preferredLanguageChoiceBox.valueProperty().bindBidirectional(settings.languageProperty());
-		preferredLanguageChoiceBox.setConverter(new LanguageTagConverter(resourceBundle));
-
 		debugModeCheckbox.selectedProperty().bindBidirectional(settings.debugMode());
 
 		autoStartProvider.ifPresent(autoStart -> autoStartCheckbox.setSelected(autoStart.isEnabled()));
 
-		nodeOrientationLtr.setSelected(settings.userInterfaceOrientation().get() == NodeOrientation.LEFT_TO_RIGHT);
-		nodeOrientationRtl.setSelected(settings.userInterfaceOrientation().get() == NodeOrientation.RIGHT_TO_LEFT);
-		nodeOrientation.selectedToggleProperty().addListener(this::toggleNodeOrientation);
-
 		var keychainSettingsConverter = new KeychainProviderClassNameConverter(keychainAccessProviders);
 		keychainBackendChoiceBox.getItems().addAll(keychainAccessProviders);
 		keychainBackendChoiceBox.setValue(keychainSettingsConverter.fromString(settings.keychainProvider().get()));
@@ -114,29 +66,10 @@ public class GeneralPreferencesController implements FxController {
 		Bindings.bindBidirectional(settings.keychainProvider(), keychainBackendChoiceBox.valueProperty(), keychainSettingsConverter);
 	}
 
-
-	public boolean isTrayMenuInitialized() {
-		return trayMenuInitialized;
-	}
-
-	public boolean isTrayMenuSupported() {
-		return trayMenuSupported;
-	}
-
 	public boolean isAutoStartSupported() {
 		return autoStartProvider.isPresent();
 	}
 
-	private void toggleNodeOrientation(@SuppressWarnings("unused") ObservableValue<? extends Toggle> observable, @SuppressWarnings("unused") Toggle oldValue, Toggle newValue) {
-		if (nodeOrientationLtr.equals(newValue)) {
-			settings.userInterfaceOrientation().set(NodeOrientation.LEFT_TO_RIGHT);
-		} else if (nodeOrientationRtl.equals(newValue)) {
-			settings.userInterfaceOrientation().set(NodeOrientation.RIGHT_TO_LEFT);
-		} else {
-			LOG.warn("Unexpected toggle option {}", newValue);
-		}
-	}
-
 	@FXML
 	public void toggleAutoStart() {
 		autoStartProvider.ifPresent(autoStart -> {
@@ -155,16 +88,6 @@ public class GeneralPreferencesController implements FxController {
 		});
 	}
 
-	public LicenseHolder getLicenseHolder() {
-		return licenseHolder;
-	}
-
-
-	@FXML
-	public void showContributeTab() {
-		selectedTabProperty.set(SelectedPreferencesTab.CONTRIBUTE);
-	}
-
 	@FXML
 	public void showLogfileDirectory() {
 		environment.getLogDir().ifPresent(logDirPath -> application.getHostServices().showDocument(logDirPath.toUri().toString()));
@@ -172,53 +95,7 @@ public class GeneralPreferencesController implements FxController {
 
 	/* Helper classes */
 
-	private static class UiThemeConverter extends StringConverter<UiTheme> {
-
-		private final ResourceBundle resourceBundle;
-
-		UiThemeConverter(ResourceBundle resourceBundle) {
-			this.resourceBundle = resourceBundle;
-		}
-
-		@Override
-		public String toString(UiTheme impl) {
-			return resourceBundle.getString(impl.getDisplayName());
-		}
-
-		@Override
-		public UiTheme fromString(String string) {
-			throw new UnsupportedOperationException();
-		}
-
-	}
-
-	private static class LanguageTagConverter extends StringConverter<String> {
-
-		private final ResourceBundle resourceBundle;
-
-		LanguageTagConverter(ResourceBundle resourceBundle) {
-			this.resourceBundle = resourceBundle;
-		}
-
-		@Override
-		public String toString(String tag) {
-			if (tag == null) {
-				return resourceBundle.getString("preferences.general.language.auto");
-			} else {
-				var locale = Locale.forLanguageTag(tag);
-				var lang = locale.getDisplayLanguage(locale);
-				var region = locale.getDisplayCountry(locale);
-				return lang + (Strings.isNullOrEmpty(region) ? "" : " (" + region + ")");
-			}
-		}
-
-		@Override
-		public String fromString(String displayLanguage) {
-			throw new UnsupportedOperationException();
-		}
-	}
-
-	private class KeychainProviderDisplayNameConverter extends StringConverter<KeychainAccessProvider> {
+	private static class KeychainProviderDisplayNameConverter extends StringConverter<KeychainAccessProvider> {
 
 		@Override
 		public String toString(KeychainAccessProvider provider) {

+ 156 - 0
src/main/java/org/cryptomator/ui/preferences/InterfacePreferencesController.java

@@ -0,0 +1,156 @@
+package org.cryptomator.ui.preferences;
+
+import com.google.common.base.Strings;
+import org.cryptomator.common.LicenseHolder;
+import org.cryptomator.common.settings.Settings;
+import org.cryptomator.common.settings.UiTheme;
+import org.cryptomator.launcher.SupportedLanguages;
+import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.traymenu.TrayMenuComponent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import javafx.beans.property.ObjectProperty;
+import javafx.beans.value.ObservableValue;
+import javafx.fxml.FXML;
+import javafx.geometry.NodeOrientation;
+import javafx.scene.control.CheckBox;
+import javafx.scene.control.ChoiceBox;
+import javafx.scene.control.RadioButton;
+import javafx.scene.control.Toggle;
+import javafx.scene.control.ToggleGroup;
+import javafx.util.StringConverter;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+@PreferencesScoped
+public class InterfacePreferencesController implements FxController {
+
+	private static final Logger LOG = LoggerFactory.getLogger(InterfacePreferencesController.class);
+
+	private final Settings settings;
+	private final boolean trayMenuInitialized;
+	private final boolean trayMenuSupported;
+	private final ObjectProperty<SelectedPreferencesTab> selectedTabProperty;
+	private final LicenseHolder licenseHolder;
+	private final ResourceBundle resourceBundle;
+	public ChoiceBox<UiTheme> themeChoiceBox;
+	public CheckBox showMinimizeButtonCheckbox;
+	public CheckBox showTrayIconCheckbox;
+	public ChoiceBox<String> preferredLanguageChoiceBox;
+	public ToggleGroup nodeOrientation;
+	public RadioButton nodeOrientationLtr;
+	public RadioButton nodeOrientationRtl;
+
+	@Inject
+	InterfacePreferencesController(Settings settings, TrayMenuComponent trayMenu, ObjectProperty<SelectedPreferencesTab> selectedTabProperty, LicenseHolder licenseHolder, ResourceBundle resourceBundle) {
+		this.settings = settings;
+		this.trayMenuInitialized = trayMenu.isInitialized();
+		this.trayMenuSupported = trayMenu.isSupported();
+		this.selectedTabProperty = selectedTabProperty;
+		this.licenseHolder = licenseHolder;
+		this.resourceBundle = resourceBundle;
+	}
+
+	@FXML
+	public void initialize() {
+		themeChoiceBox.getItems().addAll(UiTheme.applicableValues());
+		if (!themeChoiceBox.getItems().contains(settings.theme().get())) {
+			settings.theme().set(UiTheme.LIGHT);
+		}
+		themeChoiceBox.valueProperty().bindBidirectional(settings.theme());
+		themeChoiceBox.setConverter(new UiThemeConverter(resourceBundle));
+
+		showMinimizeButtonCheckbox.selectedProperty().bindBidirectional(settings.showMinimizeButton());
+
+		showTrayIconCheckbox.selectedProperty().bindBidirectional(settings.showTrayIcon());
+
+		preferredLanguageChoiceBox.getItems().add(null);
+		preferredLanguageChoiceBox.getItems().addAll(SupportedLanguages.LANGUAGAE_TAGS);
+		preferredLanguageChoiceBox.valueProperty().bindBidirectional(settings.languageProperty());
+		preferredLanguageChoiceBox.setConverter(new LanguageTagConverter(resourceBundle));
+
+		nodeOrientationLtr.setSelected(settings.userInterfaceOrientation().get() == NodeOrientation.LEFT_TO_RIGHT);
+		nodeOrientationRtl.setSelected(settings.userInterfaceOrientation().get() == NodeOrientation.RIGHT_TO_LEFT);
+		nodeOrientation.selectedToggleProperty().addListener(this::toggleNodeOrientation);
+	}
+
+
+	public boolean isTrayMenuInitialized() {
+		return trayMenuInitialized;
+	}
+
+	public boolean isTrayMenuSupported() {
+		return trayMenuSupported;
+	}
+
+	private void toggleNodeOrientation(@SuppressWarnings("unused") ObservableValue<? extends Toggle> observable, @SuppressWarnings("unused") Toggle oldValue, Toggle newValue) {
+		if (nodeOrientationLtr.equals(newValue)) {
+			settings.userInterfaceOrientation().set(NodeOrientation.LEFT_TO_RIGHT);
+		} else if (nodeOrientationRtl.equals(newValue)) {
+			settings.userInterfaceOrientation().set(NodeOrientation.RIGHT_TO_LEFT);
+		} else {
+			LOG.warn("Unexpected toggle option {}", newValue);
+		}
+	}
+
+	public LicenseHolder getLicenseHolder() {
+		return licenseHolder;
+	}
+
+
+	@FXML
+	public void showContributeTab() {
+		selectedTabProperty.set(SelectedPreferencesTab.CONTRIBUTE);
+	}
+
+	/* Helper classes */
+
+	private static class UiThemeConverter extends StringConverter<UiTheme> {
+
+		private final ResourceBundle resourceBundle;
+
+		UiThemeConverter(ResourceBundle resourceBundle) {
+			this.resourceBundle = resourceBundle;
+		}
+
+		@Override
+		public String toString(UiTheme impl) {
+			return resourceBundle.getString(impl.getDisplayName());
+		}
+
+		@Override
+		public UiTheme fromString(String string) {
+			throw new UnsupportedOperationException();
+		}
+
+	}
+
+	private static class LanguageTagConverter extends StringConverter<String> {
+
+		private final ResourceBundle resourceBundle;
+
+		LanguageTagConverter(ResourceBundle resourceBundle) {
+			this.resourceBundle = resourceBundle;
+		}
+
+		@Override
+		public String toString(String tag) {
+			if (tag == null) {
+				return resourceBundle.getString("preferences.general.language.auto");
+			} else {
+				var locale = Locale.forLanguageTag(tag);
+				var lang = locale.getDisplayLanguage(locale);
+				var region = locale.getDisplayCountry(locale);
+				return lang + (Strings.isNullOrEmpty(region) ? "" : " (" + region + ")");
+			}
+		}
+
+		@Override
+		public String fromString(String displayLanguage) {
+			throw new UnsupportedOperationException();
+		}
+	}
+
+}

+ 4 - 2
src/main/java/org/cryptomator/ui/preferences/PreferencesController.java

@@ -24,6 +24,7 @@ public class PreferencesController implements FxController {
 	private final BooleanBinding updateAvailable;
 	public TabPane tabPane;
 	public Tab generalTab;
+	public Tab interfaceTab;
 	public Tab volumeTab;
 	public Tab updatesTab;
 	public Tab contributeTab;
@@ -50,10 +51,11 @@ public class PreferencesController implements FxController {
 
 	private Tab getTabToSelect(SelectedPreferencesTab selectedTab) {
 		return switch (selectedTab) {
-			case UPDATES -> updatesTab;
+			case GENERAL -> generalTab;
+			case INTERFACE -> interfaceTab;
 			case VOLUME -> volumeTab;
+			case UPDATES -> updatesTab;
 			case CONTRIBUTE -> contributeTab;
-			case GENERAL -> generalTab;
 			case ABOUT -> aboutTab;
 			case ANY -> updateAvailable.get() ? updatesTab : generalTab;
 		};

+ 5 - 0
src/main/java/org/cryptomator/ui/preferences/PreferencesModule.java

@@ -64,6 +64,11 @@ abstract class PreferencesModule {
 	@FxControllerKey(GeneralPreferencesController.class)
 	abstract FxController bindGeneralPreferencesController(GeneralPreferencesController controller);
 
+	@Binds
+	@IntoMap
+	@FxControllerKey(InterfacePreferencesController.class)
+	abstract FxController bindInterfacePreferencesController(InterfacePreferencesController controller);
+
 	@Binds
 	@IntoMap
 	@FxControllerKey(UpdatesPreferencesController.class)

+ 5 - 0
src/main/java/org/cryptomator/ui/preferences/SelectedPreferencesTab.java

@@ -11,6 +11,11 @@ public enum SelectedPreferencesTab {
 	 */
 	GENERAL,
 
+	/**
+	 * Show interface tab
+	 */
+	INTERFACE,
+
 	/**
 	 * Show volume tab
 	 */

+ 8 - 0
src/main/resources/fxml/preferences.fxml

@@ -22,6 +22,14 @@
 				<fx:include source="preferences_general.fxml"/>
 			</content>
 		</Tab>
+		<Tab fx:id="interfaceTab" id="INTERFACE" text="%preferences.interface">
+			<graphic>
+				<FontAwesome5IconView glyph="EYE"/>
+			</graphic>
+			<content>
+				<fx:include source="preferences_interface.fxml"/>
+			</content>
+		</Tab>
 		<Tab fx:id="volumeTab" id="VOLUME" text="%preferences.volume">
 			<graphic>
 				<FontAwesome5IconView glyph="HDD"/>

+ 0 - 21
src/main/resources/fxml/preferences_general.fxml

@@ -20,29 +20,8 @@
 		<Insets topRightBottomLeft="12"/>
 	</padding>
 	<children>
-		<HBox spacing="6" alignment="CENTER_LEFT">
-			<Label text="%preferences.general.theme"/>
-			<ChoiceBox fx:id="themeChoiceBox" disable="${!controller.licenseHolder.validLicense}"/>
-			<Hyperlink styleClass="hyperlink-underline,hyperlink-muted" text="%preferences.general.unlockThemes" onAction="#showContributeTab" visible="${!controller.licenseHolder.validLicense}" managed="${!controller.licenseHolder.validLicense}"/>
-		</HBox>
-
-		<HBox spacing="6" alignment="CENTER_LEFT">
-			<Label text="%preferences.general.interfaceOrientation" HBox.hgrow="NEVER"/>
-			<RadioButton fx:id="nodeOrientationLtr" text="%preferences.general.interfaceOrientation.ltr" alignment="CENTER_LEFT" toggleGroup="${nodeOrientation}"/>
-			<RadioButton fx:id="nodeOrientationRtl" text="%preferences.general.interfaceOrientation.rtl" alignment="CENTER_RIGHT" toggleGroup="${nodeOrientation}"/>
-		</HBox>
-
-		<CheckBox fx:id="showMinimizeButtonCheckbox" text="%preferences.general.showMinimizeButton" visible="${controller.trayMenuInitialized}" managed="${controller.trayMenuInitialized}"/>
-
-		<CheckBox fx:id="showTrayIconCheckbox" text="%preferences.general.showTrayIcon" visible="${controller.trayMenuSupported}" managed="${controller.trayMenuSupported}"/>
-
 		<CheckBox fx:id="startHiddenCheckbox" text="%preferences.general.startHidden" />
 
-		<HBox spacing="6" alignment="CENTER_LEFT">
-			<Label text="%preferences.general.language"/>
-			<ChoiceBox fx:id="preferredLanguageChoiceBox"/>
-		</HBox>
-
 		<HBox spacing="6" alignment="CENTER_LEFT">
 			<CheckBox fx:id="debugModeCheckbox" text="%preferences.general.debugLogging"/>
 			<Hyperlink styleClass="hyperlink-underline" text="%preferences.general.debugDirectory" onAction="#showLogfileDirectory"/>

+ 44 - 0
src/main/resources/fxml/preferences_interface.fxml

@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import javafx.geometry.Insets?>
+<?import javafx.scene.control.CheckBox?>
+<?import javafx.scene.control.ChoiceBox?>
+<?import javafx.scene.control.Hyperlink?>
+<?import javafx.scene.control.Label?>
+<?import javafx.scene.control.RadioButton?>
+<?import javafx.scene.control.ToggleGroup?>
+<?import javafx.scene.layout.HBox?>
+<?import javafx.scene.layout.VBox?>
+<VBox xmlns:fx="http://javafx.com/fxml"
+	  xmlns="http://javafx.com/javafx"
+	  fx:controller="org.cryptomator.ui.preferences.InterfacePreferencesController"
+	  spacing="6">
+	<fx:define>
+		<ToggleGroup fx:id="nodeOrientation"/>
+	</fx:define>
+	<padding>
+		<Insets topRightBottomLeft="12"/>
+	</padding>
+	<children>
+		<HBox spacing="6" alignment="CENTER_LEFT">
+			<Label text="%preferences.general.theme"/>
+			<ChoiceBox fx:id="themeChoiceBox" disable="${!controller.licenseHolder.validLicense}"/>
+			<Hyperlink styleClass="hyperlink-underline,hyperlink-muted" text="%preferences.general.unlockThemes" onAction="#showContributeTab" visible="${!controller.licenseHolder.validLicense}" managed="${!controller.licenseHolder.validLicense}"/>
+		</HBox>
+
+		<HBox spacing="6" alignment="CENTER_LEFT">
+			<Label text="%preferences.general.interfaceOrientation" HBox.hgrow="NEVER"/>
+			<RadioButton fx:id="nodeOrientationLtr" text="%preferences.general.interfaceOrientation.ltr" alignment="CENTER_LEFT" toggleGroup="${nodeOrientation}"/>
+			<RadioButton fx:id="nodeOrientationRtl" text="%preferences.general.interfaceOrientation.rtl" alignment="CENTER_RIGHT" toggleGroup="${nodeOrientation}"/>
+		</HBox>
+
+		<CheckBox fx:id="showMinimizeButtonCheckbox" text="%preferences.general.showMinimizeButton" visible="${controller.trayMenuInitialized}" managed="${controller.trayMenuInitialized}"/>
+
+		<CheckBox fx:id="showTrayIconCheckbox" text="%preferences.general.showTrayIcon" visible="${controller.trayMenuSupported}" managed="${controller.trayMenuSupported}"/>
+
+		<HBox spacing="6" alignment="CENTER_LEFT">
+			<Label text="%preferences.general.language"/>
+			<ChoiceBox fx:id="preferredLanguageChoiceBox"/>
+		</HBox>
+	</children>
+</VBox>

+ 2 - 0
src/main/resources/i18n/strings.properties

@@ -208,6 +208,8 @@ preferences.general.keychainBackend=Store passwords with
 preferences.general.interfaceOrientation=Interface Orientation
 preferences.general.interfaceOrientation.ltr=Left to Right
 preferences.general.interfaceOrientation.rtl=Right to Left
+## Interface
+preferences.interface=Interface
 ## Volume
 preferences.volume=Virtual Drive
 preferences.volume.type=Volume Type