From 318da840f9ceaa0c4f56917bb726092f8ecae2af Mon Sep 17 00:00:00 2001 From: Glavo Date: Sat, 1 Mar 2025 21:01:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AF=B9=E8=AF=9D=E6=A1=86?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E5=8A=A8=E7=94=BB=E7=BC=BA=E5=A4=B1=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#3676)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...kContainerPane.java => JFXDialogPane.java} | 16 ++++++++------ .../ui/decorator/DecoratorController.java | 21 +++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) rename HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/{StackContainerPane.java => JFXDialogPane.java} (81%) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/StackContainerPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXDialogPane.java similarity index 81% rename from HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/StackContainerPane.java rename to HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXDialogPane.java index fca0814b5..1ac4d5a81 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/StackContainerPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXDialogPane.java @@ -20,24 +20,28 @@ package org.jackhuang.hmcl.ui.construct; import javafx.scene.Node; import javafx.scene.layout.StackPane; +import java.util.ArrayList; import java.util.Optional; -import java.util.Stack; import static org.jackhuang.hmcl.util.logging.Logger.LOG; -public class StackContainerPane extends StackPane { - private final Stack stack = new Stack<>(); +public class JFXDialogPane extends StackPane { + private final ArrayList stack = new ArrayList<>(); + + public int size() { + return stack.size(); + } public Optional peek() { if (stack.isEmpty()) { return Optional.empty(); } else { - return Optional.of(stack.peek()); + return Optional.of(stack.get(stack.size() - 1)); } } public void push(Node node) { - stack.push(node); + stack.add(node); getChildren().setAll(node); LOG.info(this + " " + stack); @@ -48,7 +52,7 @@ public class StackContainerPane extends StackPane { if (stack.isEmpty()) getChildren().setAll(); else - getChildren().setAll(stack.peek()); + getChildren().setAll(stack.get(stack.size() - 1)); LOG.info(this + " " + stack + ", removed: " + flag + ", object: " + node); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java index ec12c9f25..19ece8f6e 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java @@ -51,7 +51,7 @@ import org.jackhuang.hmcl.ui.animation.ContainerAnimations; import org.jackhuang.hmcl.ui.construct.DialogAware; import org.jackhuang.hmcl.ui.construct.DialogCloseEvent; import org.jackhuang.hmcl.ui.construct.Navigator; -import org.jackhuang.hmcl.ui.construct.StackContainerPane; +import org.jackhuang.hmcl.ui.construct.JFXDialogPane; import org.jackhuang.hmcl.ui.wizard.Refreshable; import org.jackhuang.hmcl.ui.wizard.WizardProvider; import org.jetbrains.annotations.Nullable; @@ -82,7 +82,7 @@ public class DecoratorController { private final Navigator navigator; private JFXDialog dialog; - private StackContainerPane dialogPane; + private JFXDialogPane dialogPane; public DecoratorController(Stage stage, Node mainPage) { decorator = new Decorator(stage); @@ -380,7 +380,7 @@ public class DecoratorController { return; } dialog = new JFXDialog(); - dialogPane = new StackContainerPane(); + dialogPane = new JFXDialogPane(); dialog.setContent(dialogPane); decorator.capableDraggingWindow(dialog); @@ -423,18 +423,21 @@ public class DecoratorController { .ifPresent(handler -> node.removeEventHandler(DialogCloseEvent.CLOSE, (EventHandler) handler)); if (dialog != null) { - dialogPane.pop(node); + JFXDialogPane pane = dialogPane; - if (node instanceof DialogAware) { - ((DialogAware) node).onDialogClosed(); - } - - if (dialogPane.getChildren().isEmpty()) { + if (pane.size() == 1 && pane.peek().orElse(null) == node) { + dialog.setOnDialogClosed(e -> pane.pop(node)); dialog.close(); dialog = null; dialogPane = null; navigator.setDisable(false); + } else { + pane.pop(node); + } + + if (node instanceof DialogAware) { + ((DialogAware) node).onDialogClosed(); } } }