[nautilus/wip/antoniof/gtk4-preparation-step-event-controllers: 5/22] list-view: Rearrange code




commit 08fe40c0d88b3048192536d907446ceff4a77dc9
Author: António Fernandes <antoniof gnome org>
Date:   Thu Aug 5 22:51:04 2021 +0100

    list-view: Rearrange code
    
    Use early returns instead of big conditional blocks.
    (Changes extracted from the Ernestas's version of the previous commit,
    so, credit to him).

 src/nautilus-list-view.c | 85 +++++++++++++++++++++++++-----------------------
 1 file changed, 44 insertions(+), 41 deletions(-)
---
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index c5771617e..939365b48 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -325,38 +325,38 @@ on_event_controller_motion_motion (GtkEventControllerMotion *controller,
 {
     NautilusListView *view;
     GtkWidget *widget;
+    GtkTreePath *old_hover_path;
 
-    view = user_data;
-
-    if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
+    if (get_click_policy () != NAUTILUS_CLICK_POLICY_SINGLE)
     {
-        GtkTreePath *old_hover_path;
+        return;
+    }
 
-        widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (controller));
-        old_hover_path = view->details->hover_path;
+    view = user_data;
+    widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (controller));
+    old_hover_path = view->details->hover_path;
 
-        gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
-                                       x, y,
-                                       &view->details->hover_path,
-                                       NULL, NULL, NULL);
+    gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
+                                   x, y,
+                                   &view->details->hover_path,
+                                   NULL, NULL, NULL);
 
-        if ((old_hover_path != NULL) != (view->details->hover_path != NULL))
+    if ((old_hover_path != NULL) != (view->details->hover_path != NULL))
+    {
+        if (view->details->hover_path != NULL)
         {
-            if (view->details->hover_path != NULL)
-            {
-                gdk_window_set_cursor (gtk_widget_get_window (widget), hand_cursor);
-            }
-            else
-            {
-                gdk_window_set_cursor (gtk_widget_get_window (widget), NULL);
-            }
+            gdk_window_set_cursor (gtk_widget_get_window (widget), hand_cursor);
         }
-
-        if (old_hover_path != NULL)
+        else
         {
-            gtk_tree_path_free (old_hover_path);
+            gdk_window_set_cursor (gtk_widget_get_window (widget), NULL);
         }
     }
+
+    if (old_hover_path != NULL)
+    {
+        gtk_tree_path_free (old_hover_path);
+    }
 }
 
 static void
@@ -367,12 +367,14 @@ on_event_controller_motion_leave (GtkEventControllerMotion *controller,
 
     view = user_data;
 
-    if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE &&
-        view->details->hover_path != NULL)
+    if (get_click_policy () != NAUTILUS_CLICK_POLICY_SINGLE ||
+        view->details->hover_path == NULL)
     {
-        gtk_tree_path_free (view->details->hover_path);
-        view->details->hover_path = NULL;
+        return;
     }
+
+    gtk_tree_path_free (view->details->hover_path);
+    view->details->hover_path = NULL;
 }
 
 static void
@@ -384,25 +386,26 @@ on_event_controller_motion_enter (GtkEventControllerMotion *controller,
     NautilusListView *view;
     GtkWidget *widget;
 
-    view = user_data;
+    if (get_click_policy () != NAUTILUS_CLICK_POLICY_SINGLE)
+    {
+        return;
+    }
 
-    if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
+    view = user_data;
+    if (view->details->hover_path != NULL)
     {
-        if (view->details->hover_path != NULL)
-        {
-            gtk_tree_path_free (view->details->hover_path);
-        }
-        widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (controller));
+        gtk_tree_path_free (view->details->hover_path);
+    }
+    widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (controller));
 
-        gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
-                                       x, y,
-                                       &view->details->hover_path,
-                                       NULL, NULL, NULL);
+    gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
+                                   x, y,
+                                   &view->details->hover_path,
+                                   NULL, NULL, NULL);
 
-        if (view->details->hover_path != NULL)
-        {
-            gdk_window_set_cursor (gtk_widget_get_window (widget), hand_cursor);
-        }
+    if (view->details->hover_path != NULL)
+    {
+        gdk_window_set_cursor (gtk_widget_get_window (widget), hand_cursor);
     }
 }
 


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