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(); } } }