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



commit 0c3a0485b1e52ce649cbd0797c8f1cc1391a064f
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  | 18 ++++++++++++++++++
 2 files changed, 26 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..43d4183ab 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -3710,6 +3710,7 @@ nautilus_list_view_get_rectangle_for_popup (NautilusFilesView *view)
     GtkTreeView *tree_view;
     GList *list;
     NautilusListView *list_view;
+    int header_h;
 
     rect = g_malloc0 (sizeof (GdkRectangle));
     list_view = NAUTILUS_LIST_VIEW (view);
@@ -3731,6 +3732,23 @@ nautilus_list_view_get_rectangle_for_popup (NautilusFilesView *view)
 
     g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
 
+    /* Workaround to https://bugzilla.gnome.org/show_bug.cgi?id=746773
+     * In short, due to smooth scrolling, we get the cell area while the view is
+     * still scrolling (and still be outside the view), not at the final
+     * position of the cell after scrolling.
+     * This workaround guesses the final y coordinate by clamping it to
+     * the widget edge. Note that the top hedge has the columns header, which is
+     * private, so first guess its height from the difference in coordinates.
+     */
+    gtk_tree_view_convert_bin_window_to_widget_coords (tree_view,
+                                                       NULL, 0,
+                                                       NULL, &header_h);
+
+    rect->y = CLAMP (rect->y,
+                     header_h,
+                     gtk_widget_get_allocated_height (GTK_WIDGET (view)) - rect->height);
+    /* End of workaroud */
+
     return rect;
 }
 


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