[nautilus/wip/antoniof/gtk4-preparation-step-event-controllers: 5/28] list-view: Rearrange code
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/gtk4-preparation-step-event-controllers: 5/28] list-view: Rearrange code
- Date: Tue, 21 Dec 2021 15:52:48 +0000 (UTC)
commit 79984979cb812a2aaf50bdb24485e1953c3afa37
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 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);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]