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



commit 73a68a4314af8512f5e63630abf4708c1d0bbfa1
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 be
    invisible or show up outside the window.
    
    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 poping up a popover or context menu.
    
    Fixes: https://gitlab.gnome.org/GNOME/nautilus/issues/5

 src/nautilus-files-view.c | 14 ++++++++------
 src/nautilus-list-view.c  | 10 ++++++++++
 2 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index c5d8929f6..f85aadf7d 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -1936,8 +1936,8 @@ static void
 nautilus_files_view_rename_file_popover_new (NautilusFilesView *view,
                                              NautilusFile      *target_file)
 {
-    GdkRectangle *pointing_to;
     NautilusFilesViewPrivate *priv;
+    GdkRectangle             *pointing_to;
 
     priv = nautilus_files_view_get_instance_private (view);
 
@@ -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 =
@@ -8128,12 +8130,12 @@ nautilus_files_view_pop_up_selection_context_menu  (NautilusFilesView *view,
     rectangle = NULL;
     if (!event)
     {
-        /* 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. But first make sure the selection is scrolled into 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)));
     }
 
     nautilus_pop_up_context_menu (GTK_WIDGET (view), priv->selection_menu, event, rectangle);
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index eb17d2b37..0358a9f6a 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -3731,6 +3731,16 @@ nautilus_list_view_get_rectangle_for_popup (NautilusFilesView *view)
 
     g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
 
+    /* Due to smooth scrolling, the rectangle may still be outside the
+     * view area. https://bugzilla.gnome.org/show_bug.cgi?id=746773
+     * Clamp it to the expected y coordinate after scrolling.
+     * FIXME: Should also subtract the height of the header, but that's private
+     * to GtkTreeView.
+     */
+    rect->y = CLAMP (rect->y,
+                          0,
+                          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]