alt: allow dragging window when a dialog is shown
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.ui.decorator;
|
package org.jackhuang.hmcl.ui.decorator;
|
||||||
|
|
||||||
|
import com.jfoenix.controls.JFXDialog;
|
||||||
import javafx.beans.property.*;
|
import javafx.beans.property.*;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
@@ -46,7 +47,7 @@ public class Decorator extends Control {
|
|||||||
private final BooleanProperty canClose = new SimpleBooleanProperty(false);
|
private final BooleanProperty canClose = new SimpleBooleanProperty(false);
|
||||||
private final BooleanProperty showCloseAsHome = new SimpleBooleanProperty(false);
|
private final BooleanProperty showCloseAsHome = new SimpleBooleanProperty(false);
|
||||||
private final Stage primaryStage;
|
private final Stage primaryStage;
|
||||||
private StackPane drawerWrapper;
|
private JFXDialog dialog;
|
||||||
|
|
||||||
public Decorator(Stage primaryStage) {
|
public Decorator(Stage primaryStage) {
|
||||||
this.primaryStage = primaryStage;
|
this.primaryStage = primaryStage;
|
||||||
@@ -58,12 +59,12 @@ public class Decorator extends Control {
|
|||||||
return primaryStage;
|
return primaryStage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StackPane getDrawerWrapper() {
|
public JFXDialog getDialog() {
|
||||||
return drawerWrapper;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDrawerWrapper(StackPane drawerWrapper) {
|
void setDialog(JFXDialog dialog) {
|
||||||
this.drawerWrapper = drawerWrapper;
|
this.dialog = dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableList<Node> getDrawer() {
|
public ObservableList<Node> getDrawer() {
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ public class DecoratorController {
|
|||||||
private final ImageView welcomeView;
|
private final ImageView welcomeView;
|
||||||
private final Navigator navigator;
|
private final Navigator navigator;
|
||||||
|
|
||||||
private JFXDialog dialog;
|
|
||||||
private StackContainerPane dialogPane;
|
private StackContainerPane dialogPane;
|
||||||
|
|
||||||
public DecoratorController(Stage stage, Node mainPage) {
|
public DecoratorController(Stage stage, Node mainPage) {
|
||||||
@@ -294,23 +293,21 @@ public class DecoratorController {
|
|||||||
public void showDialog(Node node) {
|
public void showDialog(Node node) {
|
||||||
FXUtils.checkFxUserThread();
|
FXUtils.checkFxUserThread();
|
||||||
|
|
||||||
if (dialog == null) {
|
if (decorator.getDialog() == null) {
|
||||||
if (decorator.getDrawerWrapper() == null) {
|
// Sometimes showDialog will be invoked before decorator was initialized.
|
||||||
// Sometimes showDialog will be invoked before decorator was initialized.
|
// Keep trying again.
|
||||||
// Keep trying again.
|
Platform.runLater(() -> showDialog(node));
|
||||||
Platform.runLater(() -> showDialog(node));
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dialog = new JFXDialog();
|
|
||||||
dialogPane = new StackContainerPane();
|
|
||||||
|
|
||||||
dialog.setContent(dialogPane);
|
|
||||||
dialog.setDialogContainer(decorator.getDrawerWrapper());
|
|
||||||
dialog.setOverlayClose(false);
|
|
||||||
dialog.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dialogPane == null) {
|
||||||
|
dialogPane = new StackContainerPane();
|
||||||
|
decorator.getDialog().setContent(dialogPane);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dialogPane.isEmpty())
|
||||||
|
decorator.getDialog().show();
|
||||||
|
|
||||||
dialogPane.push(node);
|
dialogPane.push(node);
|
||||||
|
|
||||||
EventHandler<DialogCloseEvent> handler = event -> closeDialog(node);
|
EventHandler<DialogCloseEvent> handler = event -> closeDialog(node);
|
||||||
@@ -319,10 +316,10 @@ public class DecoratorController {
|
|||||||
|
|
||||||
if (node instanceof DialogAware) {
|
if (node instanceof DialogAware) {
|
||||||
DialogAware dialogAware = (DialogAware) node;
|
DialogAware dialogAware = (DialogAware) node;
|
||||||
if (dialog.isVisible()) {
|
if (decorator.getDialog().isVisible()) {
|
||||||
dialogAware.onDialogShown();
|
dialogAware.onDialogShown();
|
||||||
} else {
|
} else {
|
||||||
dialog.visibleProperty().addListener(new ChangeListener<Boolean>() {
|
decorator.getDialog().visibleProperty().addListener(new ChangeListener<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
|
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
|
||||||
if (newValue) {
|
if (newValue) {
|
||||||
@@ -342,13 +339,11 @@ public class DecoratorController {
|
|||||||
Optional.ofNullable(node.getProperties().get(PROPERTY_DIALOG_CLOSE_HANDLER))
|
Optional.ofNullable(node.getProperties().get(PROPERTY_DIALOG_CLOSE_HANDLER))
|
||||||
.ifPresent(handler -> node.removeEventHandler(DialogCloseEvent.CLOSE, (EventHandler<DialogCloseEvent>) handler));
|
.ifPresent(handler -> node.removeEventHandler(DialogCloseEvent.CLOSE, (EventHandler<DialogCloseEvent>) handler));
|
||||||
|
|
||||||
if (dialog != null) {
|
if (decorator.getDialog() != null) {
|
||||||
dialogPane.pop(node);
|
dialogPane.pop(node);
|
||||||
|
|
||||||
if (dialogPane.getChildren().isEmpty()) {
|
if (dialogPane.getChildren().isEmpty()) {
|
||||||
dialog.close();
|
decorator.getDialog().close();
|
||||||
dialog = null;
|
|
||||||
dialogPane = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package org.jackhuang.hmcl.ui.decorator;
|
package org.jackhuang.hmcl.ui.decorator;
|
||||||
|
|
||||||
import com.jfoenix.controls.JFXButton;
|
import com.jfoenix.controls.JFXButton;
|
||||||
|
import com.jfoenix.controls.JFXDialog;
|
||||||
import com.jfoenix.svg.SVGGlyph;
|
import com.jfoenix.svg.SVGGlyph;
|
||||||
import javafx.beans.binding.Bindings;
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
@@ -97,7 +98,17 @@ public class DecoratorSkin extends SkinBase<Decorator> {
|
|||||||
BorderPane root = new BorderPane();
|
BorderPane root = new BorderPane();
|
||||||
root.getStyleClass().addAll("jfx-decorator");
|
root.getStyleClass().addAll("jfx-decorator");
|
||||||
wrapper.getChildren().setAll(root);
|
wrapper.getChildren().setAll(root);
|
||||||
skinnable.setDrawerWrapper(wrapper);
|
|
||||||
|
JFXDialog dialog = new JFXDialog();
|
||||||
|
dialog.setDialogContainer(wrapper);
|
||||||
|
dialog.setOverlayClose(false);
|
||||||
|
dialog.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> allowMove = true);
|
||||||
|
dialog.addEventHandler(MouseEvent.MOUSE_EXITED, e -> {
|
||||||
|
if (!isDragging) allowMove = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
skinnable.setDialog(dialog);
|
||||||
|
|
||||||
parent.getChildren().add(wrapper);
|
parent.getChildren().add(wrapper);
|
||||||
|
|
||||||
// center node with a animation layer at bottom, a container layer at middle and a "welcome" layer at top.
|
// center node with a animation layer at bottom, a container layer at middle and a "welcome" layer at top.
|
||||||
|
|||||||
Reference in New Issue
Block a user