[nautilus/antonioffix-menus-and-popovers: 15/20] files-view: Unify keyboard context menu logic



commit 560ff515981e866a51e96ed24574b1ef76f616e2
Author: António Fernandes <antoniof gnome org>
Date:   Sat Jan 13 23:16:03 2018 +0000

    files-view: Unify keyboard context menu logic
    
    When the user presses the <Menu> key or the <Shift>+<F10> combo, we
    need to pop up a selection context menu or background context menu,
    respectively if something is selected or not.
    
    Currently, this logic is duplicated in list and canvas views, in
    different ways, and not implemented in the new icon view at all.
    
    Instead, handle the "popup-menu" signal in files-view. This way,
    the new views get the feature for free.

 src/nautilus-canvas-container.c | 24 +---------------
 src/nautilus-files-view.c       | 23 +++++++++++++++
 src/nautilus-list-view.c        | 63 ++---------------------------------------
 3 files changed, 26 insertions(+), 84 deletions(-)
---
diff --git a/src/nautilus-canvas-container.c b/src/nautilus-canvas-container.c
index 0f69bdf68..f42d56d60 100644
--- a/src/nautilus-canvas-container.c
+++ b/src/nautilus-canvas-container.c
@@ -3719,7 +3719,7 @@ key_press_event (GtkWidget   *widget,
         {
             /* handle Ctrl+F10 because we want to display the
              * background popup even if something is selected.
-             * The other cases are handled by popup_menu().
+             * The other cases are handled by the "popup-menu" GtkWidget signal.
              */
             if (event->state & GDK_CONTROL_MASK)
             {
@@ -3753,27 +3753,6 @@ key_press_event (GtkWidget   *widget,
     return handled;
 }
 
-static gboolean
-popup_menu (GtkWidget *widget)
-{
-    NautilusCanvasContainer *container;
-
-    container = NAUTILUS_CANVAS_CONTAINER (widget);
-
-    if (has_selection (container))
-    {
-        handle_popups (container, NULL,
-                       "context_click_selection");
-    }
-    else
-    {
-        handle_popups (container, NULL,
-                       "context_click_background");
-    }
-
-    return TRUE;
-}
-
 static void
 grab_notify_cb  (GtkWidget *widget,
                  gboolean   was_grabbed)
@@ -4100,7 +4079,6 @@ nautilus_canvas_container_class_init (NautilusCanvasContainerClass *class)
     widget_class->button_release_event = button_release_event;
     widget_class->motion_notify_event = motion_notify_event;
     widget_class->key_press_event = key_press_event;
-    widget_class->popup_menu = popup_menu;
     widget_class->style_updated = style_updated;
     widget_class->grab_notify = grab_notify_cb;
 
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 8b1430a39..db930064d 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -8161,6 +8161,25 @@ nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
                                              event);
 }
 
+static gboolean
+popup_menu_callback (NautilusFilesView *view)
+{
+    g_autoptr (GList) selection = NULL;
+
+    selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+
+    if (selection != NULL)
+    {
+        nautilus_files_view_pop_up_selection_context_menu (view, NULL);
+    }
+    else
+    {
+        nautilus_files_view_pop_up_background_context_menu (view, NULL);
+    }
+
+    return TRUE;
+}
+
 static void
 schedule_update_context_menus (NautilusFilesView *view)
 {
@@ -9518,6 +9537,10 @@ nautilus_files_view_init (NautilusFilesView *view)
                               "scroll-event",
                               G_CALLBACK (nautilus_files_view_scroll_event),
                               view);
+    g_signal_connect_swapped (priv->scrolled_window,
+                              "popup-menu",
+                              G_CALLBACK (popup_menu_callback),
+                              view);
 
     gtk_container_add (GTK_CONTAINER (priv->overlay), priv->scrolled_window);
 
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index ffe7a755e..60740e2ce 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -175,35 +175,6 @@ list_selection_changed_callback (GtkTreeSelection *selection,
     nautilus_files_view_notify_selection_changed (view);
 }
 
-/* Move these to eel? */
-
-static void
-tree_selection_foreach_set_boolean (GtkTreeModel *model,
-                                    GtkTreePath  *path,
-                                    GtkTreeIter  *iter,
-                                    gpointer      callback_data)
-{
-    *(gboolean *) callback_data = TRUE;
-}
-
-static gboolean
-tree_selection_not_empty (GtkTreeSelection *selection)
-{
-    gboolean not_empty;
-
-    not_empty = FALSE;
-    gtk_tree_selection_selected_foreach (selection,
-                                         tree_selection_foreach_set_boolean,
-                                         &not_empty);
-    return not_empty;
-}
-
-static gboolean
-tree_view_has_selection (GtkTreeView *view)
-{
-    return tree_selection_not_empty (gtk_tree_view_get_selection (view));
-}
-
 static void
 preview_selected_items (NautilusListView *view)
 {
@@ -427,21 +398,6 @@ enter_notify_callback (GtkWidget        *widget,
     return FALSE;
 }
 
-static void
-do_popup_menu (GtkWidget        *widget,
-               NautilusListView *view,
-               GdkEventButton   *event)
-{
-    if (tree_view_has_selection (GTK_TREE_VIEW (widget)))
-    {
-        nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (view), event);
-    }
-    else
-    {
-        nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (view), event);
-    }
-}
-
 static void
 row_activated_callback (GtkTreeView       *treeview,
                         GtkTreePath       *path,
@@ -628,7 +584,7 @@ button_press_callback (GtkWidget      *widget,
 
         if (event->button == 3)
         {
-            do_popup_menu (widget, view, event);
+            nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (view), event);
         }
 
         return TRUE;
@@ -784,7 +740,7 @@ button_press_callback (GtkWidget      *widget,
 
         if (event->button == 3)
         {
-            do_popup_menu (widget, view, event);
+            nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (view), event);
         }
     }
 
@@ -842,19 +798,6 @@ button_release_callback (GtkWidget      *widget,
     return FALSE;
 }
 
-static gboolean
-popup_menu_callback (GtkWidget *widget,
-                     gpointer   callback_data)
-{
-    NautilusListView *view;
-
-    view = NAUTILUS_LIST_VIEW (callback_data);
-
-    do_popup_menu (widget, view, NULL);
-
-    return TRUE;
-}
-
 static void
 subdirectory_done_loading_callback (NautilusDirectory *directory,
                                     NautilusListView  *view)
@@ -2060,8 +2003,6 @@ create_and_set_up_tree_view (NautilusListView *view)
                              G_CALLBACK (key_press_callback), view, 0);
     g_signal_connect_object (view->details->tree_view, "test-expand-row",
                              G_CALLBACK (test_expand_row_callback), view, 0);
-    g_signal_connect_object (view->details->tree_view, "popup-menu",
-                             G_CALLBACK (popup_menu_callback), view, 0);
     g_signal_connect_object (view->details->tree_view, "row-expanded",
                              G_CALLBACK (row_expanded_callback), view, 0);
     g_signal_connect_object (view->details->tree_view, "row-collapsed",


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