[nautilus/gtk4-preparation-trunk: 18/36] files-view: Use popovers for context menus
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/gtk4-preparation-trunk: 18/36] files-view: Use popovers for context menus
- Date: Sat, 1 Jan 2022 22:04:22 +0000 (UTC)
commit 46b710c3b9ab19ab295ee439a4c410694b2fe7f0
Author: António Fernandes <antoniof gnome org>
Date: Fri Dec 17 11:43:35 2021 +0000
files-view: Use popovers for context menus
GtkMenu is gone in GTK4. Prepare for the transition using GtkPopover.
This is going to need design review after the GTK 4 switch, but it's
good enough for the purpose of simplifying the switch.
Closes https://gitlab.gnome.org/GNOME/nautilus/-/issues/738
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, 42 insertions(+), 80 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 05c1bc090..b246a1db0 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -8258,7 +8258,8 @@ nautilus_files_view_reveal_for_selection_context_menu (NautilusFilesView *view)
**/
void
nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
- const GdkEvent *event)
+ gdouble x,
+ gdouble y)
{
NautilusFilesViewPrivate *priv;
@@ -8273,37 +8274,28 @@ nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
if (NULL == priv->selection_menu)
{
- priv->selection_menu = gtk_menu_new ();
-
- gtk_menu_attach_to_widget (GTK_MENU (priv->selection_menu),
- GTK_WIDGET (view),
- NULL);
+ priv->selection_menu = gtk_popover_new (GTK_WIDGET (view));
}
- 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
+ gtk_popover_bind_model (GTK_POPOVER (priv->selection_menu),
+ G_MENU_MODEL (priv->selection_menu_model),
+ NULL);
+ if (x == -1 && y == -1)
{
/* 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_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_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_popover_popup (GTK_POPOVER (priv->selection_menu));
}
/**
@@ -8315,7 +8307,8 @@ nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
**/
void
nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
- const GdkEvent *event)
+ gdouble x,
+ gdouble y)
{
NautilusFilesViewPrivate *priv;
@@ -8330,30 +8323,14 @@ nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
if (NULL == priv->background_menu)
{
- 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);
+ priv->background_menu = gtk_popover_new (GTK_WIDGET (view));
}
+ 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
@@ -8365,11 +8342,11 @@ popup_menu_callback (NautilusFilesView *view)
if (selection != NULL)
{
- nautilus_files_view_pop_up_selection_context_menu (view, NULL);
+ nautilus_files_view_pop_up_selection_context_menu (view, -1, -1);
}
else
{
- nautilus_files_view_pop_up_background_context_menu (view, NULL);
+ nautilus_files_view_pop_up_background_context_menu (view, 0, 0);
}
return TRUE;
diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h
index 32ac9937c..9bbd61962 100644
--- a/src/nautilus-files-view.h
+++ b/src/nautilus-files-view.h
@@ -263,9 +263,11 @@ 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,
- const GdkEvent *event);
+ gdouble x,
+ gdouble y);
void nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
- const GdkEvent *event);
+ gdouble x,
+ gdouble y);
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 7740f5739..1d8f4cf52 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),
- event);
+ x, y);
}
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),
- event);
+ x, y);
}
/* 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, NULL);
+ nautilus_files_view_pop_up_background_context_menu (view, 0, 0);
return GDK_EVENT_STOP;
}
@@ -1917,27 +1917,17 @@ 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), event);
+ nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (view), x, y);
}
else
{
- nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (view), event);
+ nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (view), x, y);
}
}
@@ -3885,6 +3875,7 @@ 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 98599862c..f56797771 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -777,8 +777,6 @@ on_button_press_event (GtkGestureMultiPress *gesture,
{
NautilusViewIconController *self;
guint button;
- GdkEventSequence *sequence;
- const GdkEvent *event;
GdkModifierType modifiers = 0;
gint view_x;
gint view_y;
@@ -786,8 +784,6 @@ 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
@@ -845,7 +841,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),
- event);
+ x, y);
}
}
else
@@ -854,7 +850,7 @@ on_button_press_event (GtkGestureMultiPress *gesture,
if (button == GDK_BUTTON_SECONDARY)
{
nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (self),
- event);
+ x, y);
}
}
}
@@ -893,14 +889,9 @@ 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)),
@@ -910,13 +901,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),
- event);
+ x, y);
}
else
{
nautilus_view_set_selection (NAUTILUS_VIEW (self), NULL);
nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (self),
- event);
+ x, y);
}
}
diff --git a/src/resources/ui/nautilus-files-view-context-menus.ui
b/src/resources/ui/nautilus-files-view-context-menus.ui
index ac29451a7..a951549ab 100644
--- a/src/resources/ui/nautilus-files-view-context-menus.ui
+++ b/src/resources/ui/nautilus-files-view-context-menus.ui
@@ -121,6 +121,7 @@
</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>
@@ -129,13 +130,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]