[nautilus/wip/antoniof/gnome-42: 30/72] Revert "files-view: Use popovers for context menus"




commit dcad6d403c59a908ca50484e08dd2c1b7bd09fed
Author: Ondrej Holy <oholy redhat com>
Date:   Fri Feb 11 14:47:08 2022 +0100

    Revert "files-view: Use popovers for context menus"
    
    This reverts commit a7983d7a00191717e940e3170a0a539714a5ecbd.

 src/nautilus-files-view.c                          | 75 ++++++++++++++--------
 src/nautilus-files-view.h                          |  6 +-
 src/nautilus-list-view.c                           | 21 ++++--
 src/nautilus-view-icon-controller.c                | 17 +++--
 .../ui/nautilus-files-view-context-menus.ui        |  3 +-
 5 files changed, 80 insertions(+), 42 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 9b7578daa..53e59d32f 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -8246,8 +8246,7 @@ nautilus_files_view_reveal_for_selection_context_menu (NautilusFilesView *view)
  **/
 void
 nautilus_files_view_pop_up_selection_context_menu  (NautilusFilesView *view,
-                                                    gdouble            x,
-                                                    gdouble            y)
+                                                    const GdkEvent    *event)
 {
     NautilusFilesViewPrivate *priv;
 
@@ -8262,28 +8261,37 @@ nautilus_files_view_pop_up_selection_context_menu  (NautilusFilesView *view,
 
     if (NULL == priv->selection_menu)
     {
-        priv->selection_menu = gtk_popover_new (GTK_WIDGET (view));
+        priv->selection_menu = gtk_menu_new ();
+
+        gtk_menu_attach_to_widget (GTK_MENU (priv->selection_menu),
+                                   GTK_WIDGET (view),
+                                   NULL);
     }
 
-    gtk_popover_bind_model (GTK_POPOVER (priv->selection_menu),
-                            G_MENU_MODEL (priv->selection_menu_model),
-                            NULL);
-    if (x == -1 && y == -1)
+    gtk_menu_shell_bind_model (GTK_MENU_SHELL (priv->selection_menu),
+                               G_MENU_MODEL (priv->selection_menu_model),
+                               NULL,
+                               TRUE);
+
+    if (event != NULL)
+    {
+        gtk_menu_popup_at_pointer (GTK_MENU (priv->selection_menu), event);
+    }
+    else
     {
         /* If triggered from the keyboard, popup at selection, not pointer */
         g_autofree GdkRectangle *rectangle = NULL;
 
         rectangle = nautilus_files_view_reveal_for_selection_context_menu (view);
         g_return_if_fail (rectangle != NULL);
-        gtk_popover_set_pointing_to (GTK_POPOVER (priv->selection_menu),
-                                     rectangle);
-    }
-    else
-    {
-        gtk_popover_set_pointing_to (GTK_POPOVER (priv->selection_menu),
-                                     &(GdkRectangle){x, y, 0, 0});
+
+        gtk_menu_popup_at_rect (GTK_MENU (priv->selection_menu),
+                                gtk_widget_get_window (GTK_WIDGET (view)),
+                                rectangle,
+                                GDK_GRAVITY_SOUTH_WEST,
+                                GDK_GRAVITY_NORTH_WEST,
+                                NULL);
     }
-    gtk_popover_popup (GTK_POPOVER (priv->selection_menu));
 }
 
 /**
@@ -8295,8 +8303,7 @@ nautilus_files_view_pop_up_selection_context_menu  (NautilusFilesView *view,
  **/
 void
 nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
-                                                    gdouble            x,
-                                                    gdouble            y)
+                                                    const GdkEvent    *event)
 {
     NautilusFilesViewPrivate *priv;
 
@@ -8311,14 +8318,30 @@ nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
 
     if (NULL == priv->background_menu)
     {
-        priv->background_menu = gtk_popover_new (GTK_WIDGET (view));
+        priv->background_menu = gtk_menu_new ();
+
+        gtk_menu_attach_to_widget (GTK_MENU (priv->background_menu),
+                                   GTK_WIDGET (view),
+                                   NULL);
+    }
+    gtk_menu_shell_bind_model (GTK_MENU_SHELL (priv->background_menu),
+                               G_MENU_MODEL (priv->background_menu_model),
+                               NULL,
+                               TRUE);
+    if (event != NULL)
+    {
+        gtk_menu_popup_at_pointer (GTK_MENU (priv->background_menu), event);
+    }
+    else
+    {
+        /* It was triggered from the keyboard, so pop up from the center of view.
+         */
+        gtk_menu_popup_at_widget (GTK_MENU (priv->background_menu),
+                                  GTK_WIDGET (view),
+                                  GDK_GRAVITY_CENTER,
+                                  GDK_GRAVITY_CENTER,
+                                  NULL);
     }
-    gtk_popover_bind_model (GTK_POPOVER (priv->background_menu),
-                            G_MENU_MODEL (priv->background_menu_model),
-                            NULL);
-    gtk_popover_set_pointing_to (GTK_POPOVER (priv->background_menu),
-                                 &(GdkRectangle){x, y, 0, 0});
-    gtk_popover_popup (GTK_POPOVER (priv->background_menu));
 }
 
 static gboolean
@@ -8330,11 +8353,11 @@ popup_menu_callback (NautilusFilesView *view)
 
     if (selection != NULL)
     {
-        nautilus_files_view_pop_up_selection_context_menu (view, -1, -1);
+        nautilus_files_view_pop_up_selection_context_menu (view, NULL);
     }
     else
     {
-        nautilus_files_view_pop_up_background_context_menu (view, 0, 0);
+        nautilus_files_view_pop_up_background_context_menu (view, NULL);
     }
 
     return TRUE;
diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h
index 9bbd61962..32ac9937c 100644
--- a/src/nautilus-files-view.h
+++ b/src/nautilus-files-view.h
@@ -263,11 +263,9 @@ void                nautilus_files_view_notify_selection_changed         (Nautil
 NautilusDirectory  *nautilus_files_view_get_model                        (NautilusFilesView *view);
 NautilusFile       *nautilus_files_view_get_directory_as_file            (NautilusFilesView *view);
 void                nautilus_files_view_pop_up_background_context_menu   (NautilusFilesView *view,
-                                                                          gdouble            x,
-                                                                          gdouble            y);
+                                                                          const GdkEvent    *event);
 void                nautilus_files_view_pop_up_selection_context_menu    (NautilusFilesView *view,
-                                                                          gdouble            x,
-                                                                          gdouble            y);
+                                                                          const GdkEvent    *event);
 gboolean            nautilus_files_view_should_show_file                 (NautilusFilesView *view,
                                                                           NautilusFile      *file);
 gboolean            nautilus_files_view_should_sort_directories_first    (NautilusFilesView *view);
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 0647ba29f..29ff73950 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -533,7 +533,7 @@ on_tree_view_multi_press_gesture_pressed (GtkGestureMultiPress *gesture,
         if (button == GDK_BUTTON_SECONDARY)
         {
             nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (view),
-                                                                x, y);
+                                                                event);
         }
 
         return;
@@ -693,7 +693,7 @@ on_tree_view_multi_press_gesture_pressed (GtkGestureMultiPress *gesture,
         if (button == GDK_BUTTON_SECONDARY)
         {
             nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (view),
-                                                               x, y);
+                                                               event);
         }
 
         /* Don't open a new tab if we are in single click mode (this would open 2 tabs),
@@ -826,7 +826,7 @@ on_event_controller_key_key_pressed (GtkEventControllerKey *controller,
     {
         if ((state & GDK_CONTROL_MASK) != 0)
         {
-            nautilus_files_view_pop_up_background_context_menu (view, 0, 0);
+            nautilus_files_view_pop_up_background_context_menu (view, NULL);
 
             return GDK_EVENT_STOP;
         }
@@ -1923,17 +1923,27 @@ on_longpress_gesture_pressed_event (GtkGestureLongPress *gesture,
                                     gdouble              y,
                                     gpointer             user_data)
 {
+    GdkEventSequence *event_sequence;
+    const GdkEvent *event;
     NautilusListView *view = user_data;
     g_autolist (NautilusFile) selection = NULL;
 
+    event_sequence = gtk_gesture_get_last_updated_sequence (GTK_GESTURE (gesture));
+    if (event_sequence == NULL)
+    {
+        return;
+    }
+
+    event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), event_sequence);
+
     selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
     if (selection != NULL)
     {
-        nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (view), x, y);
+        nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (view), event);
     }
     else
     {
-        nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (view), x, y);
+        nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (view), event);
     }
 }
 
@@ -3881,7 +3891,6 @@ nautilus_list_view_reveal_for_selection_context_menu (NautilusFilesView *view)
     gtk_tree_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
 
     rect = get_rectangle_for_path (list_view, path);
-    rect->width = rect->height;
 
     gtk_tree_path_free (path);
 
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index f56797771..98599862c 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -777,6 +777,8 @@ on_button_press_event (GtkGestureMultiPress *gesture,
 {
     NautilusViewIconController *self;
     guint button;
+    GdkEventSequence *sequence;
+    const GdkEvent *event;
     GdkModifierType modifiers = 0;
     gint view_x;
     gint view_y;
@@ -784,6 +786,8 @@ on_button_press_event (GtkGestureMultiPress *gesture,
 
     self = NAUTILUS_VIEW_ICON_CONTROLLER (user_data);
     button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
+    sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
+    event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
 #if GTK_MAJOR_VERSION < 4
     gtk_get_current_event_state (&modifiers);
 #else
@@ -841,7 +845,7 @@ on_button_press_event (GtkGestureMultiPress *gesture,
         else if (button == GDK_BUTTON_SECONDARY)
         {
             nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (self),
-                                                               x, y);
+                                                               event);
         }
     }
     else
@@ -850,7 +854,7 @@ on_button_press_event (GtkGestureMultiPress *gesture,
         if (button == GDK_BUTTON_SECONDARY)
         {
             nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (self),
-                                                                x, y);
+                                                                event);
         }
     }
 }
@@ -889,9 +893,14 @@ on_longpress_gesture_pressed_callback (GtkGestureLongPress *gesture,
 {
     NautilusViewIconController *self;
     GtkFlowBoxChild *child_at_pos;
+    GdkEventSequence *event_sequence;
+    GdkEvent *event;
     gint view_x;
     gint view_y;
 
+    event_sequence = gtk_gesture_get_last_updated_sequence (GTK_GESTURE (gesture));
+    event = (GdkEvent *) gtk_gesture_get_last_event (GTK_GESTURE (gesture), event_sequence);
+
     self = NAUTILUS_VIEW_ICON_CONTROLLER (user_data);
 
     gtk_widget_translate_coordinates (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)),
@@ -901,13 +910,13 @@ on_longpress_gesture_pressed_callback (GtkGestureLongPress *gesture,
     if (child_at_pos != NULL)
     {
         nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (self),
-                                                           x, y);
+                                                           event);
     }
     else
     {
         nautilus_view_set_selection (NAUTILUS_VIEW (self), NULL);
         nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (self),
-                                                            x, y);
+                                                            event);
     }
 }
 
diff --git a/src/resources/ui/nautilus-files-view-context-menus.ui 
b/src/resources/ui/nautilus-files-view-context-menus.ui
index a951549ab..ac29451a7 100644
--- a/src/resources/ui/nautilus-files-view-context-menus.ui
+++ b/src/resources/ui/nautilus-files-view-context-menus.ui
@@ -121,7 +121,6 @@
       </item>
     </section>
     <section>
-      <attribute name="display-hint">horizontal-buttons</attribute>
       <item>
         <attribute name="label" translatable="yes">Cu_t</attribute>
         <attribute name="action">view.cut</attribute>
@@ -130,13 +129,13 @@
         <attribute name="label" translatable="yes">_Copy</attribute>
         <attribute name="action">view.copy</attribute>
       </item>
-    </section>
     <section>
       <item>
         <attribute name="label" translatable="yes">Create _Link</attribute>
         <attribute name="action">view.create-link-in-place</attribute>
         <attribute name="hidden-when">action-disabled</attribute>
       </item>
+    </section>
       <item>
         <attribute name="label" translatable="yes">_Paste Into Folder</attribute>
         <attribute name="action">view.paste-into</attribute>


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