summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntónio Fernandes <antoniof@gnome.org>2021-08-05 22:51:04 +0100
committerAntónio Fernandes <antoniojpfernandes@gmail.com>2021-12-22 01:38:47 +0000
commita211f4abe0301ec1bea78512eefff011ab4a35e0 (patch)
treed7d217e34c4577a06298dad4cc50ed40bfd0576f
parent7491875784656c10adc038c4f00fa88c100a87e4 (diff)
downloadnautilus-a211f4abe0301ec1bea78512eefff011ab4a35e0.tar.gz
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).
-rw-r--r--src/nautilus-list-view.c85
1 files 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);
}
}