[nautilus] list-view: Don't hardcode expander padding



commit bfae80c628f9446778fa9d66296105f00394f122
Author: Alexandru Fazakas <alex fazakas97 yahoo com>
Date:   Thu Feb 22 00:50:45 2018 +0200

    list-view: Don't hardcode expander padding
    
    In list-view, there is a 9 year old TODO saying why the magic number was used
    introduced in commit c2305aff9607cce8f83f226d80e0e79e504f852f.
    In this patch, we decide if an expander was clicked exploring the fact that
    the expander is outside of the cell area.
    
    Aside from that, we fixed an internationalization bug, as now RTL languages can also use the folder 
expanders (which wasn't an option before).
    
    Finally, hard-coding values is not a good practice and the code looks cleaner
    this way.

 src/nautilus-list-view.c | 53 +++++++++++++++++++++---------------------------
 1 file changed, 23 insertions(+), 30 deletions(-)
---
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index d98fe962b..113df3358 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -505,6 +505,7 @@ button_press_callback (GtkWidget      *widget,
     NautilusListView *view;
     GtkTreeView *tree_view;
     GtkTreePath *path;
+    GtkTreeViewColumn *column;
     GtkTreeSelection *selection;
     GtkWidgetClass *tree_view_class;
     gint64 current_time;
@@ -567,7 +568,7 @@ button_press_callback (GtkWidget      *widget,
 
     /* No item at this position */
     if (!gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y,
-                                        &path, NULL, NULL, NULL))
+                                        &path, &column, NULL, NULL))
     {
         if (is_simple_click)
         {
@@ -598,17 +599,20 @@ button_press_callback (GtkWidget      *widget,
 
     if (show_expanders)
     {
-        int expander_size, horizontal_separator;
-        gtk_widget_style_get (widget,
-                              "expander-size", &expander_size,
-                              "horizontal-separator", &horizontal_separator,
-                              NULL);
-        /* TODO we should not hardcode this extra padding. It is
-         * EXPANDER_EXTRA_PADDING from GtkTreeView.
-         */
-        expander_size += 4;
-        on_expander = (event->x <= horizontal_separator / 2 +
-                       gtk_tree_path_get_depth (path) * expander_size);
+        GdkRectangle cell_area;
+
+        gtk_tree_view_get_cell_area (tree_view, path, column, &cell_area);
+
+        /* We assume that the cell area exclude the expander itself. */
+
+        if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+        {
+            on_expander = event->x > (cell_area.x + cell_area.width);
+        }
+        else
+        {
+            on_expander = event->x < cell_area.x;
+        }
     }
 
     /* Keep track of path of last click so double clicks only happen
@@ -745,29 +749,18 @@ button_press_callback (GtkWidget      *widget,
         }
     }
 
-    if (is_simple_click)
+    if (is_simple_click &&
+        g_strcmp0 (gtk_tree_view_column_get_title (column), "Star") == 0)
     {
-        GtkTreeViewColumn *column = NULL;
         gdouble cell_middle_x;
 
-        gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view->details->tree_view),
-                                       event->x,
-                                       event->y,
-                                       NULL,
-                                       &column,
-                                       NULL,
-                                       NULL);
+        cell_middle_x = gtk_tree_view_column_get_width (column) / 2 +
+                        gtk_tree_view_column_get_x_offset (column);
 
-        if (g_strcmp0 (gtk_tree_view_column_get_title (column), "Star") == 0)
+        if (event->x > cell_middle_x - 10 &&
+            event->x < cell_middle_x + 10)
         {
-            cell_middle_x = gtk_tree_view_column_get_width (column) / 2 +
-                            gtk_tree_view_column_get_x_offset (column);
-
-            if (event->x > cell_middle_x - 10 &&
-                event->x < cell_middle_x + 10)
-            {
-                on_star_cell_renderer_clicked (path, view);
-            }
+            on_star_cell_renderer_clicked (path, view);
         }
     }
 


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