mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-07-08 11:30:42 +00:00
Modal overlay fixes
This commit is contained in:
@@ -98,6 +98,6 @@ public class ModalOverlay {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
AppDialog.closeDialog(this);
|
||||
AppDialog.hide(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,22 +30,12 @@ public class ModalOverlayStackComp extends SimpleRegionBuilder {
|
||||
}
|
||||
|
||||
private BaseRegionBuilder<?, ?> buildModalOverlay(BaseRegionBuilder<?, ?> current, int index) {
|
||||
AtomicInteger currentIndex = new AtomicInteger(index);
|
||||
var prop = new SimpleObjectProperty<>(modalOverlay.size() > index ? modalOverlay.get(index) : null);
|
||||
modalOverlay.addListener((ListChangeListener<? super ModalOverlay>) c -> {
|
||||
var ex = prop.get();
|
||||
// Don't shift just for an index change
|
||||
if (ex != null && c.getList().contains(ex)) {
|
||||
currentIndex.set(c.getList().indexOf(ex));
|
||||
return;
|
||||
} else {
|
||||
currentIndex.set(index);
|
||||
}
|
||||
|
||||
prop.set(modalOverlay.size() > index ? modalOverlay.get(index) : null);
|
||||
});
|
||||
prop.addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue == null && modalOverlay.indexOf(oldValue) == currentIndex.get()) {
|
||||
if (newValue == null) {
|
||||
modalOverlay.remove(oldValue);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -37,14 +37,6 @@ public class AppDialog {
|
||||
return Optional.of(modalOverlays.getLast());
|
||||
}
|
||||
|
||||
public static void closeDialog(ModalOverlay overlay) {
|
||||
PlatformThread.runLaterIfNeeded(() -> {
|
||||
synchronized (modalOverlays) {
|
||||
modalOverlays.remove(overlay);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void waitForAllDialogsClose() {
|
||||
while (!modalOverlays.isEmpty()) {
|
||||
ThreadHelper.sleep(10);
|
||||
@@ -63,7 +55,18 @@ public class AppDialog {
|
||||
|
||||
public static void hide(ModalOverlay o) {
|
||||
PlatformThread.runLaterIfNeeded(() -> {
|
||||
modalOverlays.remove(o);
|
||||
var firstElement = o.equals(modalOverlays.stream()
|
||||
.filter(modalOverlay -> modalOverlay != null)
|
||||
.findFirst().orElse(null));
|
||||
var lastElement = modalOverlays.getLast().equals(o);
|
||||
// Prevent indices from being moved when closing a modal in the back
|
||||
if (firstElement && !lastElement) {
|
||||
modalOverlays.set(modalOverlays.indexOf(o), null);
|
||||
} else if (firstElement && lastElement) {
|
||||
modalOverlays.clear();
|
||||
} else {
|
||||
modalOverlays.remove(o);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class ErrorHandlerDialog {
|
||||
try {
|
||||
var modal = new AtomicReference<ModalOverlay>();
|
||||
var comp = new ErrorHandlerComp(event, () -> {
|
||||
AppDialog.closeDialog(modal.get());
|
||||
AppDialog.hide(modal.get());
|
||||
});
|
||||
comp.prefWidth(event.getThrowable() != null ? 600 : 500);
|
||||
var headerId = event.isTerminal() ? "terminalErrorOccured" : "errorOccured";
|
||||
|
||||
Reference in New Issue
Block a user