[file-roller/wip/iainl/keypress-fixes: 3/4] fr-window: Position the Shift-F10 menu at the selected row



commit 0c7b2692f35003a9ac7c45c21cb70db4c6ee440d
Author: Iain Lane <iainl gnome org>
Date:   Tue Apr 23 15:46:15 2019 +0100

    fr-window: Position the Shift-F10 menu at the selected row
    
    ...rather than the location of the mouse cursor
    
    This is the approach taken by nautilus, and it means the menu is at a
    more sensible place.

 meson.build     |  2 +-
 src/fr-window.c | 37 ++++++++++++++++++++++++++++++-------
 2 files changed, 31 insertions(+), 8 deletions(-)
---
diff --git a/meson.build b/meson.build
index 709a9643..99585745 100644
--- a/meson.build
+++ b/meson.build
@@ -5,7 +5,7 @@ project('file-roller', 'c',
 )
 
 glib_version = '>=2.36'
-gtk_version = '>=3.16.0'
+gtk_version = '>=3.22.0'
 nautilus_version = '>=2.22.2'
 json_glib_version = '>=0.14.0'
 libnotify_version = '>=0.4.3'
diff --git a/src/fr-window.c b/src/fr-window.c
index 91ef5286..de8f3330 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -4833,16 +4833,39 @@ key_press_cb (GtkWidget   *widget,
        case GDK_KEY_F10:
                if (event->state & GDK_SHIFT_MASK) {
                        GtkTreeSelection *selection;
-
-                       selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (window->priv->list_view));
+                       GList *selected_rows;
+                       GtkTreePath *first_selected_row_path;
+                       GtkTreeView *tree_view;
+                       GdkRectangle rect;
+                       GdkWindow   *win;
+
+                       tree_view = GTK_TREE_VIEW (window->priv->list_view);
+                       win = gtk_tree_view_get_bin_window (tree_view);
+
+                       selection = gtk_tree_view_get_selection (tree_view);
+                       selected_rows = gtk_tree_selection_get_selected_rows (selection,
+                                                                             &window->priv->list_store);
                        if (selection == NULL)
                                return GDK_EVENT_PROPAGATE;
 
-                       gtk_menu_popup (GTK_MENU (window->priv->file_popup_menu),
-                                       NULL, NULL, NULL,
-                                       window,
-                                       3,
-                                       GDK_CURRENT_TIME);
+                       if (selected_rows == NULL)
+                               return GDK_EVENT_PROPAGATE;
+
+                       first_selected_row_path = (GtkTreePath *) selected_rows->data;
+
+                       gtk_tree_view_get_cell_area (tree_view,
+                                                    first_selected_row_path,
+                                                    NULL,
+                                                    &rect);
+
+                       g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
+
+                       gtk_menu_popup_at_rect (GTK_MENU (window->priv->file_popup_menu),
+                                               win,
+                                               &rect,
+                                               GDK_GRAVITY_SOUTH_WEST,
+                                               GDK_GRAVITY_NORTH_WEST,
+                                               (const GdkEvent *) event);
                        retval = GDK_EVENT_STOP;
                }
                break;


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