summaryrefslogtreecommitdiff
path: root/src/nautilus-dnd.c
diff options
context:
space:
mode:
authorAntónio Fernandes <antoniof@gnome.org>2021-12-22 09:53:17 +0000
committerAntónio Fernandes <antoniof@gnome.org>2022-01-05 11:32:11 +0000
commit641d29adb1bd53c040d5674bcbd679d00a47b4b4 (patch)
tree238e9fa0bbdce2277951b80dfbf2d904153e8a3b /src/nautilus-dnd.c
parent50842cc9287ab8049bc5f3f91522af3c9b548c3f (diff)
downloadnautilus-641d29adb1bd53c040d5674bcbd679d00a47b4b4.tar.gz
dnd: Stop using GtkMenu
This is the last usage of GtkMenu remaining in our own codebase. DND is due a reimplementation in GTK 4 and this particular menu (the one which asks the drop action if you hold Alt while dropping) uses a nested main loop and grabs. So, there is no need to aim for perfect here. Just reimplement it the lazy way as a GtkPopover with buttons and call it a day.
Diffstat (limited to 'src/nautilus-dnd.c')
-rw-r--r--src/nautilus-dnd.c49
1 files changed, 33 insertions, 16 deletions
diff --git a/src/nautilus-dnd.c b/src/nautilus-dnd.c
index 9b7b05607..73f20e9a7 100644
--- a/src/nautilus-dnd.c
+++ b/src/nautilus-dnd.c
@@ -27,6 +27,7 @@
#include "nautilus-dnd.h"
#include "nautilus-program-choosing.h"
+#include "nautilus-gtk4-helpers.h"
#include <eel/eel-glib-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-string.h>
@@ -759,15 +760,17 @@ append_drop_action_menu_item (GtkWidget *menu,
{
GtkWidget *menu_item;
- menu_item = gtk_menu_item_new_with_mnemonic (text);
+ menu_item = gtk_button_new_with_mnemonic (text);
gtk_widget_set_sensitive (menu_item, sensitive);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+ gtk_box_append (GTK_BOX (menu), menu_item);
+
+ gtk_style_context_add_class (gtk_widget_get_style_context (menu_item), "flat");
g_object_set_data (G_OBJECT (menu_item),
"action",
GINT_TO_POINTER (action));
- g_signal_connect (menu_item, "activate",
+ g_signal_connect (menu_item, "clicked",
G_CALLBACK (drop_action_activated_callback),
damd);
@@ -779,6 +782,7 @@ GdkDragAction
nautilus_drag_drop_action_ask (GtkWidget *widget,
GdkDragAction actions)
{
+ GtkWidget *popover;
GtkWidget *menu;
GtkWidget *menu_item;
DropActionMenuData damd;
@@ -786,8 +790,16 @@ nautilus_drag_drop_action_ask (GtkWidget *widget,
/* Create the menu and set the sensitivity of the items based on the
* allowed actions.
*/
- menu = gtk_menu_new ();
- gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (widget));
+ popover = gtk_popover_new (widget);
+ gtk_popover_set_position (GTK_POPOVER (popover), GTK_POS_TOP);
+
+ menu = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ gtk_widget_set_margin_top (menu, 6);
+ gtk_widget_set_margin_bottom (menu, 6);
+ gtk_widget_set_margin_start (menu, 6);
+ gtk_widget_set_margin_end (menu, 6);
+ gtk_popover_set_child (GTK_POPOVER (popover), menu);
+ gtk_widget_show (menu);
append_drop_action_menu_item (menu, _("_Move Here"),
GDK_ACTION_MOVE,
@@ -804,32 +816,37 @@ nautilus_drag_drop_action_ask (GtkWidget *widget,
(actions & GDK_ACTION_LINK) != 0,
&damd);
- eel_gtk_menu_append_separator (GTK_MENU (menu));
-
- menu_item = gtk_menu_item_new_with_mnemonic (_("Cancel"));
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+ menu_item = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
+ gtk_box_append (GTK_BOX (menu), menu_item);
gtk_widget_show (menu_item);
+ append_drop_action_menu_item (menu, _("Cancel"), 0, TRUE, &damd);
+
damd.chosen = 0;
damd.loop = g_main_loop_new (NULL, FALSE);
- g_signal_connect (menu, "deactivate",
+ g_signal_connect (popover, "closed",
G_CALLBACK (menu_deactivate_callback),
&damd);
- gtk_grab_add (menu);
+ gtk_grab_add (popover);
+
+ /* We don't have pointer coords here. Just pick the center of the widget. */
+ gtk_popover_set_pointing_to (GTK_POPOVER (popover),
+ &(GdkRectangle){ .x = 0.5 * gtk_widget_get_allocated_width (widget),
+ .y = 0.5 * gtk_widget_get_allocated_height (widget),
+ .width = 0, .height = 0 });
- gtk_menu_popup_at_pointer (GTK_MENU (menu),
- NULL);
+ gtk_popover_popup (GTK_POPOVER (popover));
g_main_loop_run (damd.loop);
- gtk_grab_remove (menu);
+ gtk_grab_remove (popover);
g_main_loop_unref (damd.loop);
- g_object_ref_sink (menu);
- g_object_unref (menu);
+ g_object_ref_sink (popover);
+ g_object_unref (popover);
return damd.chosen;
}