From a211f4abe0301ec1bea78512eefff011ab4a35e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Thu, 5 Aug 2021 22:51:04 +0100 Subject: 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 7a8fdbbd3..0bba76860 100644 --- a/src/nautilus-list-view.c +++ b/src/nautilus-list-view.c @@ -326,38 +326,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 @@ -368,12 +368,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 @@ -385,25 +387,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); } } -- cgit v1.2.1