Browse Source

Merge branch 'develop' into feature/custom-shortening-threshold

Jan-Peter Klein 1 năm trước cách đây
mục cha
commit
1fec9781bf

+ 16 - 3
src/main/java/org/cryptomator/ui/controls/FormattedLabel.java

@@ -13,18 +13,19 @@ public class FormattedLabel extends Label {
 	private final StringProperty format = new SimpleStringProperty("");
 	private final ObjectProperty<Object> arg1 = new SimpleObjectProperty<>();
 	private final ObjectProperty<Object> arg2 = new SimpleObjectProperty<>();
-	// add arg2, arg3, ... on demand
+	private final ObjectProperty<Object> arg3 = new SimpleObjectProperty<>();
+	// add arg4, arg5, ... on demand
 
 	public FormattedLabel() {
 		textProperty().bind(createStringBinding());
 	}
 
 	protected StringBinding createStringBinding() {
-		return Bindings.createStringBinding(this::updateText, format, arg1, arg2);
+		return Bindings.createStringBinding(this::updateText, format, arg1, arg2, arg3);
 	}
 
 	private String updateText() {
-		return String.format(format.get(), arg1.get(), arg2.get());
+		return String.format(format.get(), arg1.get(), arg2.get(), arg3.get());
 	}
 
 	/* Observables */
@@ -64,4 +65,16 @@ public class FormattedLabel extends Label {
 	public void setArg2(Object arg2) {
 		this.arg2.set(arg2);
 	}
+
+	public ObjectProperty<Object> arg3Property() {
+		return arg3;
+	}
+
+	public Object getArg3() {
+		return arg3.get();
+	}
+
+	public void setArg3(Object arg3) {
+		this.arg3.set(arg3);
+	}
 }

+ 3 - 2
src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java

@@ -8,19 +8,20 @@ package org.cryptomator.ui.fxapp;
 import dagger.Module;
 import dagger.Provides;
 import org.cryptomator.ui.error.ErrorComponent;
+import org.cryptomator.ui.health.HealthCheckComponent;
 import org.cryptomator.ui.lock.LockComponent;
 import org.cryptomator.ui.mainwindow.MainWindowComponent;
 import org.cryptomator.ui.preferences.PreferencesComponent;
 import org.cryptomator.ui.quit.QuitComponent;
-
 import org.cryptomator.ui.traymenu.TrayMenuComponent;
 import org.cryptomator.ui.unlock.UnlockComponent;
+import org.cryptomator.ui.vaultoptions.VaultOptionsComponent;
 
 import javafx.scene.image.Image;
 import java.io.IOException;
 import java.io.InputStream;
 
-@Module(includes = {UpdateCheckerModule.class}, subcomponents = {TrayMenuComponent.class, MainWindowComponent.class, PreferencesComponent.class, UnlockComponent.class, LockComponent.class, QuitComponent.class, ErrorComponent.class})
+@Module(includes = {UpdateCheckerModule.class}, subcomponents = {TrayMenuComponent.class, MainWindowComponent.class, PreferencesComponent.class, VaultOptionsComponent.class, UnlockComponent.class, LockComponent.class, QuitComponent.class, ErrorComponent.class, HealthCheckComponent.class})
 abstract class FxApplicationModule {
 
 	private static Image createImageFromResource(String resourceName) throws IOException {

+ 9 - 1
src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java

@@ -13,6 +13,8 @@ import org.cryptomator.ui.preferences.SelectedPreferencesTab;
 import org.cryptomator.ui.quit.QuitComponent;
 import org.cryptomator.ui.unlock.UnlockComponent;
 import org.cryptomator.ui.unlock.UnlockWorkflow;
+import org.cryptomator.ui.vaultoptions.SelectedVaultOptionsTab;
+import org.cryptomator.ui.vaultoptions.VaultOptionsComponent;
 import org.jetbrains.annotations.Nullable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -46,10 +48,11 @@ public class FxApplicationWindows {
 	private final LockComponent.Factory lockWorkflowFactory;
 	private final ErrorComponent.Factory errorWindowFactory;
 	private final ExecutorService executor;
+	private final VaultOptionsComponent.Factory vaultOptionsWindow;
 	private final FilteredList<Window> visibleWindows;
 
 	@Inject
-	public FxApplicationWindows(@PrimaryStage Stage primaryStage, Optional<TrayIntegrationProvider> trayIntegration, Lazy<MainWindowComponent> mainWindow, Lazy<PreferencesComponent> preferencesWindow, QuitComponent.Builder quitWindowBuilder, UnlockComponent.Factory unlockWorkflowFactory, LockComponent.Factory lockWorkflowFactory, ErrorComponent.Factory errorWindowFactory, ExecutorService executor) {
+	public FxApplicationWindows(@PrimaryStage Stage primaryStage, Optional<TrayIntegrationProvider> trayIntegration, Lazy<MainWindowComponent> mainWindow, Lazy<PreferencesComponent> preferencesWindow, QuitComponent.Builder quitWindowBuilder, UnlockComponent.Factory unlockWorkflowFactory, LockComponent.Factory lockWorkflowFactory, ErrorComponent.Factory errorWindowFactory, ExecutorService executor, VaultOptionsComponent.Factory vaultOptionsWindow) {
 		this.primaryStage = primaryStage;
 		this.trayIntegration = trayIntegration;
 		this.mainWindow = mainWindow;
@@ -59,6 +62,7 @@ public class FxApplicationWindows {
 		this.lockWorkflowFactory = lockWorkflowFactory;
 		this.errorWindowFactory = errorWindowFactory;
 		this.executor = executor;
+		this.vaultOptionsWindow = vaultOptionsWindow;
 		this.visibleWindows = Window.getWindows().filtered(Window::isShowing);
 	}
 
@@ -105,6 +109,10 @@ public class FxApplicationWindows {
 		return CompletableFuture.supplyAsync(() -> preferencesWindow.get().showPreferencesWindow(selectedTab), Platform::runLater).whenComplete(this::reportErrors);
 	}
 
+	public CompletionStage<Stage> showVaultOptionsWindow(Vault vault, SelectedVaultOptionsTab tab) {
+		return showMainWindow().thenApplyAsync((window) -> vaultOptionsWindow.create(vault).showVaultOptionsWindow(tab), Platform::runLater).whenComplete(this::reportErrors);
+	}
+
 	public void showQuitWindow(QuitResponse response, boolean forced) {
 			CompletableFuture.runAsync(() -> quitWindowBuilder.build().showQuitWindow(response,forced), Platform::runLater);
 	}

+ 1 - 2
src/main/java/org/cryptomator/ui/mainwindow/MainWindowModule.java

@@ -19,7 +19,6 @@ import org.cryptomator.ui.health.HealthCheckComponent;
 import org.cryptomator.ui.migration.MigrationComponent;
 import org.cryptomator.ui.removevault.RemoveVaultComponent;
 import org.cryptomator.ui.stats.VaultStatisticsComponent;
-import org.cryptomator.ui.vaultoptions.VaultOptionsComponent;
 import org.cryptomator.ui.wrongfilealert.WrongFileAlertComponent;
 
 import javax.inject.Named;
@@ -33,7 +32,7 @@ import javafx.stage.StageStyle;
 import java.util.Map;
 import java.util.ResourceBundle;
 
-@Module(subcomponents = {AddVaultWizardComponent.class, HealthCheckComponent.class, MigrationComponent.class, RemoveVaultComponent.class, VaultOptionsComponent.class, VaultStatisticsComponent.class, WrongFileAlertComponent.class, ErrorComponent.class})
+@Module(subcomponents = {AddVaultWizardComponent.class, MigrationComponent.class, RemoveVaultComponent.class, VaultStatisticsComponent.class, WrongFileAlertComponent.class, ErrorComponent.class})
 abstract class MainWindowModule {
 
 	@Provides

+ 56 - 11
src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java

@@ -8,6 +8,7 @@ import org.cryptomator.ui.common.FxController;
 import org.cryptomator.ui.controls.FormattedLabel;
 import org.cryptomator.ui.fxapp.FxApplicationWindows;
 import org.cryptomator.ui.preferences.SelectedPreferencesTab;
+import org.cryptomator.ui.vaultoptions.SelectedVaultOptionsTab;
 
 import javax.inject.Inject;
 import javafx.fxml.FXML;
@@ -21,9 +22,10 @@ public class UnlockInvalidMountPointController implements FxController {
 
 	private final Stage window;
 	private final Vault vault;
-	private final AtomicReference<Throwable> unlockException;
 	private final FxApplicationWindows appWindows;
 	private final ResourceBundle resourceBundle;
+	private final ExceptionType exceptionType;
+	private final String exceptionMessage;
 
 	public FormattedLabel dialogDescription;
 
@@ -31,22 +33,18 @@ public class UnlockInvalidMountPointController implements FxController {
 	UnlockInvalidMountPointController(@UnlockWindow Stage window, @UnlockWindow Vault vault, @UnlockWindow AtomicReference<Throwable> unlockException, FxApplicationWindows appWindows, ResourceBundle resourceBundle) {
 		this.window = window;
 		this.vault = vault;
-		this.unlockException = unlockException;
 		this.appWindows = appWindows;
 		this.resourceBundle = resourceBundle;
+
+		var exc = unlockException.get();
+		this.exceptionType = getExceptionType(exc);
+		this.exceptionMessage = exc.getMessage();
 	}
 
 	@FXML
 	public void initialize() {
-		var e = unlockException.get();
-		var translationKey = switch (e) {
-			case MountPointNotSupportedException x -> "unlock.error.customPath.description.notSupported";
-			case MountPointNotExistsException x -> "unlock.error.customPath.description.notExists";
-			case MountPointInUseException x -> "unlock.error.customPath.description.inUse";
-			default -> "unlock.error.customPath.description.generic";
-		};
-		dialogDescription.setFormat(resourceBundle.getString(translationKey));
-		dialogDescription.setArg1(e.getMessage());
+		dialogDescription.setFormat(resourceBundle.getString(exceptionType.translationKey));
+		dialogDescription.setArg1(exceptionMessage);
 	}
 
 	@FXML
@@ -60,4 +58,51 @@ public class UnlockInvalidMountPointController implements FxController {
 		window.close();
 	}
 
+	@FXML
+	public void closeAndOpenVaultOptions() {
+		appWindows.showVaultOptionsWindow(vault, SelectedVaultOptionsTab.MOUNT);
+		window.close();
+	}
+
+	private ExceptionType getExceptionType(Throwable unlockException) {
+		return switch (unlockException) {
+			case MountPointNotSupportedException x -> ExceptionType.NOT_SUPPORTED;
+			case MountPointNotExistsException x -> ExceptionType.NOT_EXISTING;
+			case MountPointInUseException x -> ExceptionType.IN_USE;
+			default -> ExceptionType.GENERIC;
+		};
+	}
+
+	private enum ExceptionType {
+
+		NOT_SUPPORTED("unlock.error.customPath.description.notSupported", ButtonAction.SHOW_PREFERENCES),
+		NOT_EXISTING("unlock.error.customPath.description.notExists", ButtonAction.SHOW_VAULT_OPTIONS),
+		IN_USE("unlock.error.customPath.description.inUse", ButtonAction.SHOW_VAULT_OPTIONS),
+		GENERIC("unlock.error.customPath.description.generic", ButtonAction.SHOW_PREFERENCES);
+
+		private final String translationKey;
+		private final ButtonAction action;
+
+		ExceptionType(String translationKey, ButtonAction action) {
+			this.translationKey = translationKey;
+			this.action = action;
+		}
+	}
+
+	private enum ButtonAction {
+
+		SHOW_PREFERENCES,
+		SHOW_VAULT_OPTIONS;
+
+	}
+
+	/* Getter */
+
+	public boolean isShowPreferences() {
+		return exceptionType.action == ButtonAction.SHOW_PREFERENCES;
+	}
+
+	public boolean isShowVaultOptions() {
+		return exceptionType.action == ButtonAction.SHOW_VAULT_OPTIONS;
+	}
 }

+ 2 - 1
src/main/java/org/cryptomator/ui/vaultoptions/VaultOptionsComponent.java

@@ -28,12 +28,13 @@ public interface VaultOptionsComponent {
 
 	ObjectProperty<SelectedVaultOptionsTab> selectedTabProperty();
 
-	default void showVaultOptionsWindow(SelectedVaultOptionsTab selectedTab) {
+	default Stage showVaultOptionsWindow(SelectedVaultOptionsTab selectedTab) {
 		selectedTabProperty().set(selectedTab);
 		Stage stage = window();
 		stage.setScene(scene().get());
 		stage.show();
 		stage.requestFocus();
+		return stage;
 	}
 
 	@Subcomponent.Factory

+ 2 - 1
src/main/resources/fxml/unlock_invalid_mount_point.fxml

@@ -46,7 +46,8 @@
 			<ButtonBar buttonMinWidth="120" buttonOrder="+CI">
 				<buttons>
 					<Button text="%generic.button.cancel" ButtonBar.buttonData="CANCEL_CLOSE" cancelButton="true" onAction="#close"/>
-					<Button text="%hub.noKeychain.openBtn" ButtonBar.buttonData="FINISH" defaultButton="true" onAction="#closeAndOpenPreferences"/>
+					<Button text="%hub.noKeychain.openBtn" ButtonBar.buttonData="FINISH" defaultButton="true" onAction="#closeAndOpenPreferences" visible="${controller.showPreferences}" managed="${controller.showPreferences}"/>
+					<Button text="%main.vaultDetail.optionsBtn" ButtonBar.buttonData="FINISH" defaultButton="true" onAction="#closeAndOpenVaultOptions" visible="${controller.showVaultOptions}" managed="${controller.showVaultOptions}"/>
 				</buttons>
 			</ButtonBar>
 		</VBox>