[nautilus/wip/antoniof/gtk4-preparation-step-event-controllers: 8/22] list-view: Cleanup long press gesture at ::finalize




commit ff9f3a72554a20a64fae229e296d51736ece8a35
Author: António Fernandes <antoniof gnome org>
Date:   Fri Aug 6 02:01:57 2021 +0100

    list-view: Cleanup long press gesture at ::finalize
    
    Also, restyle code to make it more readable.

 src/nautilus-list-view-private.h |  1 +
 src/nautilus-list-view.c         | 36 ++++++++++++++++++++----------------
 2 files changed, 21 insertions(+), 16 deletions(-)
---
diff --git a/src/nautilus-list-view-private.h b/src/nautilus-list-view-private.h
index c874c38f7..973ae09c2 100644
--- a/src/nautilus-list-view-private.h
+++ b/src/nautilus-list-view-private.h
@@ -77,5 +77,6 @@ struct NautilusListViewDetails {
   GtkGesture *tree_view_multi_press_gesture;
   GtkEventController *motion_controller;
   GtkEventController *key_controller;
+  GtkGesture *long_press_gesture;
 };
 
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 2a0356ec3..d3f1507f2 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -2081,7 +2081,7 @@ create_and_set_up_tree_view (NautilusListView *view)
     GList *l;
     gchar **default_column_order, **default_visible_columns;
     GtkWidget *content_widget;
-    GtkGesture *longpress_gesture;
+    GtkGesture *gesture;
     GtkEventController *controller;
 
     content_widget = nautilus_files_view_get_content_widget (NAUTILUS_FILES_VIEW (view));
@@ -2127,26 +2127,28 @@ create_and_set_up_tree_view (NautilusListView *view)
                              "changed",
                              G_CALLBACK (list_selection_changed_callback), view, 0);
 
-    view->details->tree_view_drag_gesture = gtk_gesture_drag_new (GTK_WIDGET (view->details->tree_view));
+    gesture = gtk_gesture_drag_new (GTK_WIDGET (view->details->tree_view));
+    view->details->tree_view_drag_gesture = gesture;
 
-    gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (view->details->tree_view_drag_gesture),
+    gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture),
                                                 GTK_PHASE_CAPTURE);
-    gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (view->details->tree_view_drag_gesture), 0);
+    gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
 
-    g_signal_connect (view->details->tree_view_drag_gesture, "drag-begin",
+    g_signal_connect (gesture, "drag-begin",
                       G_CALLBACK (on_tree_view_drag_gesture_drag_begin), view);
-    g_signal_connect (view->details->tree_view_drag_gesture, "drag-update",
+    g_signal_connect (gesture, "drag-update",
                       G_CALLBACK (on_tree_view_drag_gesture_drag_update), view);
 
-    view->details->tree_view_multi_press_gesture = gtk_gesture_multi_press_new (GTK_WIDGET 
(view->details->tree_view));
+    gesture = gtk_gesture_multi_press_new (GTK_WIDGET (view->details->tree_view));
+    view->details->tree_view_multi_press_gesture = gesture;
 
-    gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER 
(view->details->tree_view_multi_press_gesture),
+    gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture),
                                                 GTK_PHASE_CAPTURE);
-    gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (view->details->tree_view_multi_press_gesture), 0);
+    gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
 
-    g_signal_connect (view->details->tree_view_multi_press_gesture, "pressed",
+    g_signal_connect (gesture, "pressed",
                       G_CALLBACK (on_tree_view_multi_press_gesture_pressed), view);
-    g_signal_connect (view->details->tree_view_multi_press_gesture, "released",
+    g_signal_connect (gesture, "released",
                       G_CALLBACK (on_tree_view_multi_press_gesture_released), view);
 
     controller = gtk_event_controller_motion_new (GTK_WIDGET (view->details->tree_view));
@@ -2199,12 +2201,13 @@ create_and_set_up_tree_view (NautilusListView *view)
     g_signal_connect_object (view->details->model, "get-icon-scale",
                              G_CALLBACK (get_icon_scale_callback), view, 0);
 
-    longpress_gesture = gtk_gesture_long_press_new (GTK_WIDGET (content_widget));
-    gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (longpress_gesture),
+    gesture = gtk_gesture_long_press_new (GTK_WIDGET (content_widget));
+    view->details->long_press_gesture = gesture;
+
+    gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture),
                                                 GTK_PHASE_CAPTURE);
-    gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (longpress_gesture),
-                                       TRUE);
-    g_signal_connect (longpress_gesture,
+    gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), TRUE);
+    g_signal_connect (gesture,
                       "pressed",
                       (GCallback) on_longpress_gesture_pressed_event,
                       view);
@@ -3684,6 +3687,7 @@ nautilus_list_view_dispose (GObject *object)
     g_clear_object (&list_view->details->tree_view_multi_press_gesture);
     g_clear_object (&list_view->details->motion_controller);
     g_clear_object (&list_view->details->key_controller);
+    g_clear_object (&list_view->details->long_press_gesture);
 
     G_OBJECT_CLASS (nautilus_list_view_parent_class)->dispose (object);
 }


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