From a71f8b350ee665ea4930a42ebc7a4ee293376213 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Fri, 20 Nov 2020 16:12:49 +0100 Subject: [PATCH] Show only one quit dialogue at a time --- .../cryptomator/ui/fxapp/FxApplication.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java b/main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java index 650254649..3c2db73ce 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java +++ b/main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java @@ -26,6 +26,8 @@ import javafx.application.Application; import javafx.application.Platform; import javafx.beans.binding.Bindings; import javafx.beans.binding.BooleanBinding; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; import javafx.beans.value.ObservableValue; import javafx.collections.ObservableSet; import javafx.stage.Stage; @@ -49,6 +51,9 @@ public class FxApplication extends Application { private final BooleanBinding hasVisibleStages; private final UiAppearanceListener systemInterfaceThemeListener = this::systemInterfaceThemeChanged; + private volatile boolean quitDialogueIsShowing; + private ObjectProperty quitStage; + @Inject FxApplication(Settings settings, Lazy mainWindow, Lazy preferencesWindow, Provider unlockWindowBuilderProvider, Provider quitWindowBuilderProvider, Optional trayIntegration, Optional appearanceProvider, VaultService vaultService, LicenseHolder licenseHolder, ObservableSet visibleStages) { this.settings = settings; @@ -61,6 +66,8 @@ public class FxApplication extends Application { this.vaultService = vaultService; this.licenseHolder = licenseHolder; this.hasVisibleStages = Bindings.isNotEmpty(visibleStages); + this.quitDialogueIsShowing = false; + this.quitStage = new SimpleObjectProperty<>(null); } public void start() { @@ -107,11 +114,29 @@ public class FxApplication extends Application { }); } - public void showQuitWindow(QuitResponse response) { - Platform.runLater(() -> { - quitWindowBuilderProvider.get().quitResponse(response).build().showQuitWindow(); - LOG.debug("Showing QuitWindow"); - }); + public synchronized void showQuitWindow(QuitResponse response) { + //TODO: manage a list of quit responses and execute for all the same actions? + if (quitDialogueIsShowing) { + if (quitStage.isNotNull().get()) { + Platform.runLater(() -> { + quitStage.get().requestFocus(); + LOG.debug("Focus QuitWindow"); + }); + } + } else { + quitDialogueIsShowing = true; + Platform.runLater(() -> { + var window = quitWindowBuilderProvider.get().quitResponse(response).build().showQuitWindow(); + quitStage.set(window); + var originalListener = window.getOnCloseRequest(); + window.setOnCloseRequest(windowEvent -> { + originalListener.handle(windowEvent); + quitStage.set(null); + }); + LOG.debug("Showing QuitWindow"); + }); + } + } public VaultService getVaultService() {