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




commit 27254b2b961674829498e994c866cd32eddb5716
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 | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index a65ba4b6b..e67b88e68 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -914,7 +914,34 @@ 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 = g_list_model_get_item (G_LIST_MODEL (self->model),
+                                      gtk_flow_box_child_get_index (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]