From 889e520ecc0608ceed5cd6536f756dc2e22be0e4 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Thu, 27 Nov 2025 19:54:37 +0100 Subject: [PATCH] keep sourcelist selection when updating it --- .../de/unixwork/rssreader/FeedSourceList.kt | 6 +++ .../de/unixwork/rssreader/MainWindow.kt | 4 +- .../java/de/unixwork/ui/UiSourceList.java | 46 +++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt index cb3c696..5d837bf 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt @@ -124,4 +124,10 @@ class FeedSourceList : Document() { } } + + fun updateFeeds() { + val selection = feeds.selectedIndex + feeds.update() + feeds.selectedIndex = selection + } } \ No newline at end of file diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt index d01738d..cd6211b 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt @@ -83,7 +83,7 @@ class MainWindow() { } catch (e: Exception) { e.printStackTrace() } - sourceList.feeds.update() + sourceList.updateFeeds() } } separator() @@ -247,7 +247,7 @@ class MainWindow() { } feedList.items.selected?.let { feedList.selectItem(it) - sourceList.feeds.update() + sourceList.updateFeeds() } }, getstyle = { elm, col, style -> diff --git a/ui-java/src/main/java/de/unixwork/ui/UiSourceList.java b/ui-java/src/main/java/de/unixwork/ui/UiSourceList.java index f644889..0f17c96 100644 --- a/ui-java/src/main/java/de/unixwork/ui/UiSourceList.java +++ b/ui-java/src/main/java/de/unixwork/ui/UiSourceList.java @@ -99,6 +99,52 @@ public class UiSourceList { } } + // TODO: the selection code is almost identical to the UiList selection code -> refactor + public int[] getSelection() { + ListFuncs ui = ListFuncs.getInstance(); + try { + MemorySegment sel = (MemorySegment)ui.list_get_selection_allocated.invoke(valuePtr); + int count = (int)ui.list_selection_get_count.invoke(sel); + int[] selection = new int[count]; + MemorySegment rows = (MemorySegment)ui.list_selection_get_rows.invoke(sel); + rows = rows.reinterpret(count * ValueLayout.JAVA_INT.byteSize()); + for(int i=0; i