mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-04-23 08:00:56 -04:00
Dialog fixes
This commit is contained in:
@@ -13,11 +13,14 @@ import io.xpipe.app.util.PlatformThread;
|
||||
import io.xpipe.core.process.OsType;
|
||||
|
||||
import javafx.animation.Animation;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Duration;
|
||||
|
||||
import atlantafx.base.util.Animations;
|
||||
@@ -26,6 +29,10 @@ import java.time.Instant;
|
||||
|
||||
public class AppMainWindowContentComp extends SimpleComp {
|
||||
|
||||
private final Stage stage;
|
||||
|
||||
public AppMainWindowContentComp(Stage stage) {this.stage = stage;}
|
||||
|
||||
@Override
|
||||
protected Region createSimple() {
|
||||
var overlay = AppDialog.getModalOverlay();
|
||||
@@ -81,9 +88,21 @@ public class AppMainWindowContentComp extends SimpleComp {
|
||||
}
|
||||
});
|
||||
|
||||
overlay.addListener((ListChangeListener<? super ModalOverlay>) c -> {
|
||||
if (c.next() && c.wasAdded()) {
|
||||
stage.requestFocus();
|
||||
}
|
||||
});
|
||||
|
||||
loaded.addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue != null) {
|
||||
stage.requestFocus();
|
||||
}
|
||||
});
|
||||
|
||||
return pane;
|
||||
});
|
||||
var modal = new ModalOverlayComp(bg, overlay);
|
||||
var modal = new ModalOverlayStackComp(bg, overlay);
|
||||
return modal.createRegion();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ModalOverlay {
|
||||
}
|
||||
|
||||
public void show() {
|
||||
AppDialog.show(this, false, true);
|
||||
AppDialog.show(this, false);
|
||||
}
|
||||
|
||||
public void showAndWait() {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package io.xpipe.app.comp.base;
|
||||
|
||||
import io.xpipe.app.comp.Comp;
|
||||
import io.xpipe.app.comp.SimpleComp;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.layout.Region;
|
||||
|
||||
public class ModalOverlayStackComp extends SimpleComp {
|
||||
|
||||
private final Comp<?> background;
|
||||
private final ObservableList<ModalOverlay> modalOverlay;
|
||||
|
||||
public ModalOverlayStackComp(Comp<?> background, ObservableList<ModalOverlay> modalOverlay) {
|
||||
this.background = background;
|
||||
this.modalOverlay = modalOverlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Region createSimple() {
|
||||
var current = background;
|
||||
for (var i = 0; i < 5; i++) {
|
||||
current = buildModalOverlay(current, i);
|
||||
}
|
||||
return current.createRegion();
|
||||
}
|
||||
|
||||
private Comp<?> buildModalOverlay(Comp<?> current, int index) {
|
||||
var prop = new SimpleObjectProperty<ModalOverlay>();
|
||||
modalOverlay.subscribe(() -> {
|
||||
prop.set(modalOverlay.size() > index ? modalOverlay.get(index) : null);
|
||||
});
|
||||
prop.addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue == null) {
|
||||
modalOverlay.remove(oldValue);
|
||||
}
|
||||
});
|
||||
var comp = new ModalOverlayComp(current, prop);
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
@@ -173,17 +173,15 @@ public class StoreEntryWrapper {
|
||||
notes.setValue(new StoreNotes(entry.getNotes(), entry.getNotes()));
|
||||
customIcon.setValue(entry.getIcon());
|
||||
iconFile.setValue(entry.getEffectiveIconFile());
|
||||
|
||||
busy.setValue(entry.getBusyCounter().get() != 0);
|
||||
deletable.setValue(entry.getConfiguration().isDeletable());
|
||||
sessionActive.setValue(entry.getStore() instanceof SingletonSessionStore<?> ss
|
||||
&& entry.getStore() instanceof ShellStore
|
||||
&& ss.isSessionRunning());
|
||||
|
||||
category.setValue(StoreViewState.get()
|
||||
.getCategoryWrapper(DataStorage.get()
|
||||
.getStoreCategoryIfPresent(entry.getCategoryUuid())
|
||||
.orElseThrow()));
|
||||
category.setValue(StoreViewState.get().getCategories().getList().stream()
|
||||
.filter(storeCategoryWrapper -> storeCategoryWrapper.getCategory().getUuid()
|
||||
.equals(entry.getCategoryUuid())).findFirst().orElse(StoreViewState.get()
|
||||
.getAllConnectionsCategory()));
|
||||
perUser.setValue(!category.getValue().getRoot().equals(StoreViewState.get().getAllIdentitiesCategory()) && entry.isPerUserStore());
|
||||
|
||||
if (!entry.getValidity().isUsable()) {
|
||||
|
||||
@@ -13,6 +13,9 @@ import javafx.animation.PauseTransition;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.util.Duration;
|
||||
@@ -24,7 +27,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
public class AppDialog {
|
||||
|
||||
@Getter
|
||||
private static final ObjectProperty<ModalOverlay> modalOverlay = new SimpleObjectProperty<>();
|
||||
private static final ObservableList<ModalOverlay> modalOverlay = FXCollections.observableArrayList();
|
||||
|
||||
private static void showMainWindow() {
|
||||
PlatformInit.init(true);
|
||||
@@ -32,69 +35,44 @@ public class AppDialog {
|
||||
}
|
||||
|
||||
public static void closeDialog(ModalOverlay overlay) {
|
||||
if (modalOverlay.get() == overlay) {
|
||||
modalOverlay.setValue(null);
|
||||
}
|
||||
modalOverlay.remove(overlay);
|
||||
}
|
||||
|
||||
public static void waitForClose() {
|
||||
while (modalOverlay.getValue() != null) {
|
||||
while (!modalOverlay.isEmpty()) {
|
||||
ThreadHelper.sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
public static void showAndWait(ModalOverlay o) {
|
||||
showMainWindow();
|
||||
waitForClose();
|
||||
if (!Platform.isFxApplicationThread()) {
|
||||
PlatformThread.runLaterIfNeededBlocking(() -> {
|
||||
modalOverlay.setValue(o);
|
||||
});
|
||||
waitForClose();
|
||||
ThreadHelper.sleep(200);
|
||||
} else {
|
||||
var key = new Object();
|
||||
PlatformThread.runLaterIfNeededBlocking(() -> {
|
||||
modalOverlay.setValue(o);
|
||||
modalOverlay.addListener((observable, oldValue, newValue) -> {
|
||||
if (oldValue == o && newValue == null) {
|
||||
var transition = new PauseTransition(Duration.millis(200));
|
||||
transition.setOnFinished(e -> {
|
||||
Platform.exitNestedEventLoop(key, null);
|
||||
});
|
||||
transition.play();
|
||||
}
|
||||
});
|
||||
});
|
||||
Platform.enterNestedEventLoop(key);
|
||||
waitForClose();
|
||||
}
|
||||
show(o, true);
|
||||
}
|
||||
|
||||
public static void show(ModalOverlay o, boolean wait, boolean replaceExisting) {
|
||||
public static void show(ModalOverlay o, boolean wait) {
|
||||
showMainWindow();
|
||||
if (!replaceExisting) {
|
||||
waitForClose();
|
||||
}
|
||||
if (!Platform.isFxApplicationThread()) {
|
||||
PlatformThread.runLaterIfNeededBlocking(() -> {
|
||||
modalOverlay.setValue(o);
|
||||
modalOverlay.add(o);
|
||||
});
|
||||
waitForClose();
|
||||
ThreadHelper.sleep(200);
|
||||
} else {
|
||||
var key = new Object();
|
||||
PlatformThread.runLaterIfNeededBlocking(() -> {
|
||||
modalOverlay.setValue(o);
|
||||
modalOverlay.addListener((observable, oldValue, newValue) -> {
|
||||
if (oldValue == o && newValue == null) {
|
||||
var transition = new PauseTransition(Duration.millis(200));
|
||||
transition.setOnFinished(e -> {
|
||||
if (wait) {
|
||||
Platform.exitNestedEventLoop(key, null);
|
||||
}
|
||||
});
|
||||
transition.play();
|
||||
modalOverlay.add(o);
|
||||
modalOverlay.addListener(new ListChangeListener<>() {
|
||||
@Override
|
||||
public void onChanged(Change<? extends ModalOverlay> c) {
|
||||
if (!c.getList().contains(o)) {
|
||||
var transition = new PauseTransition(Duration.millis(200));
|
||||
transition.setOnFinished(e -> {
|
||||
if (wait) {
|
||||
Platform.exitNestedEventLoop(key, null);
|
||||
}
|
||||
});
|
||||
transition.play();
|
||||
modalOverlay.removeListener(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -86,7 +86,7 @@ public class AppMainWindow {
|
||||
var stage = App.getApp().getStage();
|
||||
INSTANCE = new AppMainWindow(stage);
|
||||
|
||||
var content = new AppMainWindowContentComp().createRegion();
|
||||
var content = new AppMainWindowContentComp(stage).createRegion();
|
||||
content.opacityProperty()
|
||||
.bind(Bindings.createDoubleBinding(
|
||||
() -> {
|
||||
|
||||
@@ -161,7 +161,6 @@ public class ErrorHandlerComp extends SimpleComp {
|
||||
var layout = new VBox();
|
||||
layout.getChildren().add(content);
|
||||
layout.getStyleClass().add("error-handler-comp");
|
||||
layout.getStyleClass().add("background");
|
||||
|
||||
if (event.getThrowable() != null) {
|
||||
content.getChildren().add(new Separator(Orientation.HORIZONTAL));
|
||||
|
||||
@@ -57,6 +57,6 @@ public class ErrorHandlerDialog {
|
||||
}
|
||||
});
|
||||
|
||||
AppDialog.show(modal.get(), true, false);
|
||||
AppDialog.show(modal.get(), true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user