diff --git a/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java b/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java index 721b62cc7..7d45f4d3f 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java @@ -26,6 +26,7 @@ import javafx.scene.layout.VBox; import lombok.Setter; import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; public class ListBoxViewComp extends Comp> { @@ -60,10 +61,26 @@ public class ListBoxViewComp extends Comp> { vbox.setFocusTraversable(false); var scroll = new ScrollPane(vbox); - refresh(scroll, vbox, shown, all, cache, false, false); - - shown.addListener((ListChangeListener) (c) -> { - refresh(scroll, vbox, c.getList(), all, cache, true, true); + var l = (ListChangeListener) (c) -> { + Platform.runLater(() -> { + refresh(scroll, vbox, c.getList(), all, cache, true); + }); + }; + scroll.sceneProperty().subscribe(scene -> { + if (scene != null) { + shown.addListener(l); + } else { + shown.removeListener(l); + } + }); + scroll.sceneProperty().addListener((observableValue, oldScene, newScene) -> { + // Apply changes made since init and scene assign + if (oldScene == null && newScene != null) { + refresh(scroll, vbox, shown, all, cache, true); + } + if (oldScene != null && newScene == null) { + cache.clear(); + } }); if (scrollBar) { @@ -228,7 +245,6 @@ public class ListBoxViewComp extends Comp> { List shown, List all, Map cache, - boolean asynchronous, boolean refreshVisibilities) { Runnable update = () -> { synchronized (cache) { @@ -237,7 +253,9 @@ public class ListBoxViewComp extends Comp> { set.addAll(shown); set.addAll(all); // Clear cache of unused values - cache.keySet().removeIf(t -> !set.contains(t)); + cache.keySet().removeIf(t -> { + return !set.contains(t); + }); } // Create copy to reduce chances of concurrent modification @@ -245,6 +263,12 @@ public class ListBoxViewComp extends Comp> { var newShown = shownCopy.stream() .map(v -> { if (!cache.containsKey(v)) { + // System.out.println("cache miss: " + v); + if (scroll.getScene() == null) { + // System.out.println("Ignored " + v); + return null; + } + var comp = compFunction.apply(v); if (comp != null) { var r = comp.createRegion(); @@ -280,11 +304,6 @@ public class ListBoxViewComp extends Comp> { updateVisibilities(scroll, listView); } }; - - if (asynchronous) { - Platform.runLater(update); - } else { - PlatformThread.runLaterIfNeeded(update); - } + update.run(); } } diff --git a/version b/version index 68df27709..8ede0276f 100644 --- a/version +++ b/version @@ -1 +1 @@ -15.7-2 +15.7-3