[nautilus/antonioffix-menus-and-popovers: 11/14] canvas-view: Share common code for rectangle computation



commit d301adfc6868d94786d39870c8fe99d0d4ff620f
Author: António Fernandes <antoniof gnome org>
Date:   Sun Jan 28 12:46:21 2018 +0000

    canvas-view: Share common code for rectangle computation
    
    Make internal function for both _reveal_rectangle_for_context_menu()
    and _compute_rename_popover_pointing_to() to avoid code duplication.

 src/nautilus-canvas-view.c | 68 ++++++++++++++++++++++++----------------------
 1 file changed, 35 insertions(+), 33 deletions(-)
---
diff --git a/src/nautilus-canvas-view.c b/src/nautilus-canvas-view.c
index f5392e97d..f7dc72670 100644
--- a/src/nautilus-canvas-view.c
+++ b/src/nautilus-canvas-view.c
@@ -934,29 +934,47 @@ nautilus_canvas_view_reveal_selection (NautilusFilesView *view)
     nautilus_file_list_free (selection);
 }
 
+static GdkRectangle *
+get_rectangle_for_data (NautilusFilesView      *view,
+                        NautilusCanvasIconData *data)
+{
+    NautilusCanvasContainer *container;
+    GdkRectangle *rectangle;
+
+    container = get_canvas_container (NAUTILUS_CANVAS_VIEW (view));
+    rectangle = nautilus_canvas_container_get_icon_bounding_box (container, data);
+    if (rectangle != NULL)
+    {
+        GtkWidget *context_widget;
+        GtkAdjustment *vadjustment;
+        GtkAdjustment *hadjustment;
+
+        context_widget = nautilus_files_view_get_content_widget (view);
+        vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (context_widget));
+        hadjustment = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (context_widget));
+
+        rectangle->x -= gtk_adjustment_get_value (hadjustment);
+        rectangle->y -= gtk_adjustment_get_value (vadjustment);
+    }
+    return rectangle;
+}
+
 static GdkRectangle *
 nautilus_canvas_view_compute_rename_popover_pointing_to (NautilusFilesView *view)
 {
-    GArray *bounding_boxes;
-    GdkRectangle *bounding_box;
-    NautilusCanvasContainer *canvas_container;
-    GtkAdjustment *vadjustment, *hadjustment;
-    GtkWidget *parent_container;
+    GList *selection;
+    NautilusCanvasIconData *data;
 
-    canvas_container = get_canvas_container (NAUTILUS_CANVAS_VIEW (view));
-    bounding_boxes = nautilus_canvas_container_get_selected_icons_bounding_box (canvas_container);
-    /* We only allow renaming one item at once */
-    bounding_box = &g_array_index (bounding_boxes, GdkRectangle, 0);
-    parent_container = nautilus_files_view_get_content_widget (view);
-    vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (parent_container));
-    hadjustment = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (parent_container));
+    g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), NULL);
 
-    bounding_box->x -= gtk_adjustment_get_value (hadjustment);
-    bounding_box->y -= gtk_adjustment_get_value (vadjustment);
+    selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+    g_return_val_if_fail (selection != NULL, NULL);
 
-    g_array_free (bounding_boxes, FALSE);
+    /* We only allow renaming one item at once */
+    data = NAUTILUS_CANVAS_ICON_DATA (selection->data);
+    nautilus_file_list_free (selection);
 
-    return bounding_box;
+    return get_rectangle_for_data (view, data);
 }
 
 static GdkRectangle *
@@ -965,7 +983,6 @@ nautilus_canvas_view_reveal_rectangle_for_context_menu (NautilusFilesView *view)
     GList *selection;
     NautilusCanvasContainer *container;
     NautilusCanvasIconData *data;
-    GdkRectangle *rectangle;
 
     g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), NULL);
 
@@ -989,22 +1006,7 @@ nautilus_canvas_view_reveal_rectangle_for_context_menu (NautilusFilesView *view)
 
     nautilus_canvas_container_reveal (container, data);
 
-    rectangle = nautilus_canvas_container_get_icon_bounding_box (container, data);
-    if (rectangle != NULL)
-    {
-        GtkScrolledWindow *parent_container;
-        GtkAdjustment *vadjustment;
-        GtkAdjustment *hadjustment;
-
-        parent_container = GTK_SCROLLED_WINDOW (nautilus_files_view_get_content_widget (view));
-        vadjustment = gtk_scrolled_window_get_vadjustment (parent_container);
-        hadjustment = gtk_scrolled_window_get_hadjustment (parent_container);
-
-        rectangle->x -= gtk_adjustment_get_value (hadjustment);
-        rectangle->y -= gtk_adjustment_get_value (vadjustment);
-    }
-
-    return rectangle;
+    return get_rectangle_for_data (view, data);
 }
 
 static void


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