[nautilus/wip/antoniof/flow-box-preparation: 42/48] view-icon-controller: Implement .get_first_visible_file()




commit 5f6ec2b17b38d98f26f603ba3f789083f6b6497a
Author: António Fernandes <antoniof gnome org>
Date:   Thu Dec 9 23:45:04 2021 +0000

    view-icon-controller: Implement .get_first_visible_file()

 src/nautilus-view-icon-controller.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index 819b11e13..9333a6bd6 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -850,7 +850,33 @@ real_end_loading (NautilusFilesView *files_view,
 static char *
 real_get_first_visible_file (NautilusFilesView *files_view)
 {
-    return NULL;
+    NautilusViewIconController *self = NAUTILUS_VIEW_ICON_CONTROLLER (files_view);
+    GtkWidget *content_widget;
+    GtkAdjustment *vadjustment;
+    GtkFlowBoxChild *child;
+    gint x0;
+    gint y0;
+    gint scrolled_y;
+    NautilusViewItemModel *item;
+    gchar *uri = NULL;
+
+    content_widget = nautilus_files_view_get_content_widget (files_view);
+    vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (content_widget));
+    scrolled_y = gtk_adjustment_get_value (vadjustment);
+
+    child = gtk_flow_box_get_child_at_index (self->view_ui, 0);
+    gtk_widget_translate_coordinates (GTK_WIDGET (child),
+                                      GTK_WIDGET (self->view_ui),
+                                      0, 0, &x0, &y0);
+    child = gtk_flow_box_get_child_at_pos (self->view_ui,
+                                           x0,
+                                           MAX (y0, scrolled_y));
+    if (child != NULL)
+    {
+        item = nautilus_view_icon_item_ui_get_model (NAUTILUS_VIEW_ICON_ITEM_UI (child));
+        uri = nautilus_file_get_uri (nautilus_view_item_model_get_file (item));
+    }
+    return uri;
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]