Add a close button to close all pages

This commit is contained in:
huanghongxun
2018-09-20 22:54:41 +08:00
parent 8b52c46664
commit 923924638e
2 changed files with 11 additions and 5 deletions

View File

@@ -66,6 +66,11 @@ public class Navigator extends StackPane {
close(stack.peek()); close(stack.peek());
} }
public void clear() {
while (stack.size() > 1)
close(stack.peek());
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void close(Node from) { public void close(Node from) {
FXUtils.checkFxUserThread(); FXUtils.checkFxUserThread();

View File

@@ -204,10 +204,12 @@ public class DecoratorController {
if (navigator.getCurrentPage() instanceof DecoratorPage) { if (navigator.getCurrentPage() instanceof DecoratorPage) {
DecoratorPage page = (DecoratorPage) navigator.getCurrentPage(); DecoratorPage page = (DecoratorPage) navigator.getCurrentPage();
page.onForceToClose(); if (page.canForceToClose()) {
} else { page.onForceToClose();
navigator.close(); return;
}
} }
navigator.clear();
} }
private void back() { private void back() {
@@ -249,14 +251,13 @@ public class DecoratorController {
if (to instanceof DecoratorPage) { if (to instanceof DecoratorPage) {
decorator.drawerTitleProperty().bind(((DecoratorPage) to).titleProperty()); decorator.drawerTitleProperty().bind(((DecoratorPage) to).titleProperty());
decorator.canCloseProperty().set(((DecoratorPage) to).canForceToClose());
} else { } else {
decorator.drawerTitleProperty().unbind(); decorator.drawerTitleProperty().unbind();
decorator.drawerTitleProperty().set(""); decorator.drawerTitleProperty().set("");
decorator.canCloseProperty().set(false);
} }
decorator.canBackProperty().set(navigator.canGoBack()); decorator.canBackProperty().set(navigator.canGoBack());
decorator.canCloseProperty().set(navigator.canGoBack());
if (navigator.canGoBack()) { if (navigator.canGoBack()) {
decorator.setContentBackground(new Background(new BackgroundFill(Color.rgb(244, 244, 244, 0.5), CornerRadii.EMPTY, Insets.EMPTY))); decorator.setContentBackground(new Background(new BackgroundFill(Color.rgb(244, 244, 244, 0.5), CornerRadii.EMPTY, Insets.EMPTY)));