[nautilus/antonioffix-menus-and-popovers: 4/6] 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: 4/6] ui-utilities: Pop up context menu near selection
- Date: Tue, 9 Jan 2018 22:54:14 +0000 (UTC)
commit 528014e5422eadeb09899bb28add0c316bcfe732
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 at pointer position, which is at selection
if a poiting device 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 | 16 ++++++++++++++--
src/nautilus-pathbar.c | 3 ++-
src/nautilus-ui-utilities.c | 21 +++++++++++++++++----
src/nautilus-ui-utilities.h | 3 ++-
4 files changed, 35 insertions(+), 8 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 4a8b19cbb..c5d8929f6 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -8114,6 +8114,7 @@ nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
GdkEventButton *event)
{
NautilusFilesViewPrivate *priv;
+ GdkRectangle *rectangle;
g_assert (NAUTILUS_IS_FILES_VIEW (view));
@@ -8124,7 +8125,18 @@ nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
*/
update_context_menus_if_pending (view);
- nautilus_pop_up_context_menu (GTK_WIDGET (view), priv->selection_menu, event);
+ rectangle = NULL;
+ if (!event)
+ {
+ /* If triggered from the keyboard, popup at selection, not pointer */
+ 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)));
+ }
+
+ nautilus_pop_up_context_menu (GTK_WIDGET (view), priv->selection_menu, event, rectangle);
}
/**
@@ -8149,7 +8161,7 @@ nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
*/
update_context_menus_if_pending (view);
- nautilus_pop_up_context_menu (GTK_WIDGET (view), priv->background_menu, event);
+ nautilus_pop_up_context_menu (GTK_WIDGET (view), priv->background_menu, event, NULL);
}
static void
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index dc8ee6dbe..09a74dd01 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -1628,7 +1628,8 @@ real_pop_up_pathbar_context_menu (NautilusPathBar *self)
nautilus_pop_up_context_menu (GTK_WIDGET (self),
priv->context_menu,
- priv->context_menu_event);
+ priv->context_menu_event,
+ NULL);
}
static void
diff --git a/src/nautilus-ui-utilities.c b/src/nautilus-ui-utilities.c
index 58958e5e4..2cc4832fe 100644
--- a/src/nautilus-ui-utilities.c
+++ b/src/nautilus-ui-utilities.c
@@ -171,7 +171,8 @@ nautilus_gmenu_add_item_in_submodel (GMenu *menu,
void
nautilus_pop_up_context_menu (GtkWidget *parent,
GMenu *menu,
- GdkEventButton *button_event)
+ GdkEventButton *button_event,
+ GdkRectangle *rectangle)
{
GtkWidget *gtk_menu;
@@ -181,9 +182,21 @@ nautilus_pop_up_context_menu (GtkWidget *parent,
gtk_menu = gtk_menu_new_from_model (G_MENU_MODEL (menu));
gtk_menu_attach_to_widget (GTK_MENU (gtk_menu), parent, NULL);
- gtk_menu_popup_at_pointer (GTK_MENU (gtk_menu),
- button_event ? (GdkEvent *) button_event :
- gtk_get_current_event ());
+ if (!button_event && rectangle)
+ {
+ gtk_menu_popup_at_rect (GTK_MENU (gtk_menu),
+ gtk_widget_get_window (parent),
+ rectangle,
+ GDK_GRAVITY_SOUTH_WEST,
+ GDK_GRAVITY_NORTH_WEST,
+ NULL);
+ }
+ else
+ {
+ gtk_menu_popup_at_pointer (GTK_MENU (gtk_menu),
+ button_event ? (GdkEvent *) button_event :
+ gtk_get_current_event ());
+ }
g_object_ref_sink (gtk_menu);
g_object_unref (gtk_menu);
diff --git a/src/nautilus-ui-utilities.h b/src/nautilus-ui-utilities.h
index 0dfd31ca9..74d5cf05e 100644
--- a/src/nautilus-ui-utilities.h
+++ b/src/nautilus-ui-utilities.h
@@ -36,7 +36,8 @@ void nautilus_gmenu_merge (GMenu *original,
gboolean prepend);
void nautilus_pop_up_context_menu (GtkWidget *parent,
GMenu *menu,
- GdkEventButton *button_event);
+ GdkEventButton *button_event,
+ GdkRectangle *rectangle);
void nautilus_ui_frame_image (GdkPixbuf **pixbuf);
void nautilus_ui_frame_video (GdkPixbuf **pixbuf);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]