[nautilus/antonioffix-menus-and-popovers: 6/14] ui-utilities: Pop up context menu near selection
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/antonioffix-menus-and-popovers: 6/14] ui-utilities: Pop up context menu near selection
- Date: Tue, 23 Jan 2018 16:33:50 +0000 (UTC)
commit 2652ea7a95017dc90d988b240f3af2d326e4455f
Author: António Fernandes <antoniof gnome org>
Date: Sun Jan 7 02:00:05 2018 +0000
ui-utilities: Pop up context menu near selection
Context menus pop up where the pointer is, which is at the
selection if the pointing device is used to open the menu.
However, if the <Menu> key or <Shift>+<F10> keyboard shortcut
are used, context menus still shows up wherever the pointer is,
which may not be near the selected item at all.
Instead, show context menu near the 1st selected item (or at
the edges if out of view) when the popup menu is activated from
the keyboard.
Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=102666
src/nautilus-files-view.c | 32 +++++++++++++++++++++++++++++---
1 file changed, 29 insertions(+), 3 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index e2f495b2f..5e2da7da7 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -8124,9 +8124,35 @@ nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
*/
update_context_menus_if_pending (view);
- nautilus_pop_up_context_menu_at_pointer (GTK_WIDGET (view),
- priv->selection_menu,
- event);
+ if (event != NULL)
+ {
+ nautilus_pop_up_context_menu_at_pointer (GTK_WIDGET (view),
+ priv->selection_menu,
+ event);
+ }
+ else
+ {
+ /* If triggered from the keyboard, popup at selection, not pointer */
+ g_autoptr (GtkWidget) gtk_menu = NULL;
+ g_autofree GdkRectangle *rectangle = NULL;
+
+ gtk_menu = gtk_menu_new_from_model (G_MENU_MODEL (priv->selection_menu));
+ gtk_menu_attach_to_widget (GTK_MENU (gtk_menu), GTK_WIDGET (view), NULL);
+
+ rectangle = nautilus_files_view_get_rectangle_for_popup (view);
+ /* Don't popup from outside the view area */
+ rectangle->y = CLAMP (rectangle->y,
+ 0 - rectangle->height,
+ gtk_widget_get_allocated_height (GTK_WIDGET (view)));
+
+ gtk_menu_popup_at_rect (GTK_MENU (gtk_menu),
+ gtk_widget_get_window (GTK_WIDGET (view)),
+ rectangle,
+ GDK_GRAVITY_SOUTH_WEST,
+ GDK_GRAVITY_NORTH_WEST,
+ NULL);
+ g_object_ref_sink (gtk_menu);
+ }
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]