[nautilus/antonioffix-menus-and-popovers: 8/14] files-view: Reveal selection for rename popover/context menu



commit 113674a34f62719750ad9a28a0609c44469e5b11
Author: António Fernandes <antoniof gnome org>
Date:   Mon Jan 8 00:59:52 2018 +0000

    files-view: Reveal selection for rename popover/context menu
    
    When renaming, if the item is out of view, the popover may pop up
    outside of the window or even outside of the screen.
    
    It is conveninent to see the item to be renamed and provide a
    visible target for the popover. The same is true for context
    menus.
    
    So, reveal selection before popping up a popover or context menu.
    
    Fixes: https://gitlab.gnome.org/GNOME/nautilus/issues/5

 src/nautilus-files-view.c | 13 ++++++++-----
 src/nautilus-list-view.c  | 21 +++++++++++++++++++++
 2 files changed, 29 insertions(+), 5 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 1fb14dd66..b0da89dfa 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -1946,6 +1946,8 @@ nautilus_files_view_rename_file_popover_new (NautilusFilesView *view,
         return;
     }
 
+    nautilus_files_view_reveal_selection (view);
+
     pointing_to = nautilus_files_view_get_rectangle_for_popup (view);
 
     priv->rename_file_controller =
@@ -8132,18 +8134,19 @@ nautilus_files_view_pop_up_selection_context_menu  (NautilusFilesView *view,
     }
     else
     {
-        /* If triggered from the keyboard, popup at selection, not pointer */
+        /* It was triggered from the keyboard, so we need to 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);
 
+        /* Make sure the selection is in view. */
+        nautilus_files_view_reveal_selection (view);
+
         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)),
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index f11832289..dd5f65f17 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -3672,6 +3672,27 @@ nautilus_list_view_get_rectangle_for_popup (NautilusFilesView *view)
 
     g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
 
+    /* FIXME Due to smooth scrolling, we get the cell area while the view is
+     * still scrolling (and still outside the view), not at the final position
+     * of the cell after scrolling.
+     * https://bugzilla.gnome.org/show_bug.cgi?id=746773
+     * The following workaround guesses the final "y" coordinate by clamping it
+     * to the widget edge. Note that the top edge has got columns header, which
+     * is private, so first guess the header height from the difference between
+     * widget coordinates and bin cooridinates.
+     */
+    {
+        int header_height;
+
+        gtk_tree_view_convert_bin_window_to_widget_coords (tree_view,
+                                                           NULL, 0,
+                                                           NULL, &header_height);
+
+        rect->y = CLAMP (rect->y,
+                         header_height,
+                         gtk_widget_get_allocated_height (GTK_WIDGET (view)) - rect->height);
+    }
+
     return rect;
 }
 


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