[gtk/shortcuts-rebased-again: 149/171] file chooser: Avoid use of popup-menu



commit e40758ec261abb842b27fa4173659957b46d6168
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jun 24 01:32:31 2019 +0000

    file chooser: Avoid use of popup-menu

 gtk/gtkfilechooserwidget.c     | 26 +++++++++++++++++++++++---
 gtk/ui/gtkfilechooserwidget.ui |  1 -
 2 files changed, 23 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 857699d7f6..749eaa3371 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -83,6 +83,10 @@
 #include "gtkentryprivate.h"
 #include "gtkroot.h"
 #include "gtkbinlayout.h"
+#include "gtkshortcutcontroller.h"
+#include "gtkshortcuttrigger.h"
+#include "gtkshortcutaction.h"
+#include "gtkshortcut.h"
 
 #include <cairo-gobject.h>
 
@@ -2234,9 +2238,11 @@ file_list_show_popover (GtkFileChooserWidget *impl,
 
 /* Callback used for the GtkWidget::popup-menu signal of the file list */
 static gboolean
-list_popup_menu_cb (GtkWidget            *widget,
-                    GtkFileChooserWidget *impl)
+list_popup_menu_cb (GtkWidget *widget,
+                    GVariant  *args,
+                    gpointer   data)
 {
+  GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (data);
   GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
   graphene_rect_t bounds;
 
@@ -8445,7 +8451,6 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
   /* And a *lot* of callbacks to bind ... */
   gtk_widget_class_bind_template_callback (widget_class, file_list_drag_drop_cb);
   gtk_widget_class_bind_template_callback (widget_class, file_list_drag_data_received_cb);
-  gtk_widget_class_bind_template_callback (widget_class, list_popup_menu_cb);
   gtk_widget_class_bind_template_callback (widget_class, file_list_query_tooltip_cb);
   gtk_widget_class_bind_template_callback (widget_class, list_row_activated);
   gtk_widget_class_bind_template_callback (widget_class, file_list_drag_begin_cb);
@@ -8485,8 +8490,23 @@ post_process_ui (GtkFileChooserWidget *impl)
   GtkCellRenderer  *cell;
   GList            *cells;
   GFile            *file;
+  GtkEventController *controller;
+  GtkShortcutTrigger *trigger;
+  GtkShortcutAction *action;
+  GtkShortcut *shortcut;
 
   /* Setup file list treeview */
+  controller = gtk_shortcut_controller_new ();
+  trigger = gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_F10, GDK_SHIFT_MASK),
+                                         gtk_keyval_trigger_new (GDK_KEY_Menu, 0));
+
+  action = gtk_callback_action_new (list_popup_menu_cb, impl, NULL);
+  shortcut = gtk_shortcut_new (trigger, action);
+  gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller),
+                                        shortcut);
+  g_object_unref (shortcut);
+  gtk_widget_add_controller (priv->browse_files_tree_view, controller);
+
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->browse_files_tree_view));
   gtk_tree_selection_set_select_function (selection,
                                           list_select_func,
diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui
index 623bd86aec..e9c82d434a 100644
--- a/gtk/ui/gtkfilechooserwidget.ui
+++ b/gtk/ui/gtkfilechooserwidget.ui
@@ -161,7 +161,6 @@
                                             <signal name="drag-begin" handler="file_list_drag_begin_cb" 
swapped="no"/>
                                             <signal name="drag-motion" handler="file_list_drag_motion_cb" 
swapped="no"/>
                                             <signal name="drag-end" handler="file_list_drag_end_cb" 
swapped="no"/>
-                                            <signal name="popup-menu" handler="list_popup_menu_cb" 
swapped="no"/>
                                             <signal name="query-tooltip" 
handler="file_list_query_tooltip_cb" swapped="no"/>
                                             <signal name="row-activated" handler="list_row_activated" 
swapped="no"/>
                                             <signal name="cursor-changed" handler="list_cursor_changed" 
swapped="no"/>


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