]> uap-core.de Git - rssreader.git/commitdiff
unify UiList and UiSourceList getSelection method main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 22 Mar 2026 18:58:01 +0000 (19:58 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 22 Mar 2026 18:58:01 +0000 (19:58 +0100)
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt
ui-java/src/main/java/de/unixwork/ui/UiList.java
ui-java/src/main/java/de/unixwork/ui/UiSourceList.java

index b2e6ef656ae9c127e5e1416ce7b14afee5ca4974..95fb68c9cfe55c6b18bcfb6bc7e445dc74146c9c 100644 (file)
@@ -22,7 +22,7 @@ class FeedList(window: MainWindow) : Document() {
 
     // 0: use feed settings
     // 1: load item description
-    // 2:
+    // 2: load item link in internal browser
     val browserSetting = integer("browserSetting")
 
     val filter = integer("filter")
index 223c0ee2004462f147e26476ad48602f06a598c8..e37dccb3accfd1aff5f32f4553a8fdd260304aa0 100644 (file)
@@ -76,9 +76,13 @@ public class UiList<T> extends ArrayList<T> {
     }
 
     public int[] getSelection() {
+        return UiList.getSelection(valuePtr);
+    }
+
+    protected static int[] getSelection(MemorySegment uiListPtr) {
         ListFuncs ui = ListFuncs.getInstance();
         try {
-            MemorySegment sel = (MemorySegment)ui.list_get_selection_allocated.invoke(valuePtr);
+            MemorySegment sel = (MemorySegment)ui.list_get_selection_allocated.invoke(uiListPtr);
             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);
index 0f17c96e22d27ba9cf02307dccad17bec487fa86..7b9323cb7d07cdd582313c881f51ae5e64a97b31 100644 (file)
@@ -99,23 +99,8 @@ 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<count; i++) {
-                selection[i] = (int)rows.getAtIndex(ValueLayout.JAVA_INT, i);
-            }
-            ui.list_selection_free.invoke(sel);
-            return selection;
-        } catch (Throwable e) {
-            throw new RuntimeException(e);
-        }
+        return UiList.getSelection(valuePtr);
     }
 
     public int getSelectedIndex() {