gtkfilechooserwidget: Forward events to filechooser through key controller

Instead of manually calling gtk_binding_set_activate_event() on an ::event
callback in the save entry.
This commit is contained in:
Carlos Garnacho 2018-06-08 19:05:28 +02:00
parent 7fa3183d7f
commit 686116ba61

View File

@ -81,6 +81,7 @@
#include "gtkeventcontrollerkey.h" #include "gtkeventcontrollerkey.h"
#include "gtkdebug.h" #include "gtkdebug.h"
#include "gtkfilechoosererrorstackprivate.h" #include "gtkfilechoosererrorstackprivate.h"
#include "gtkentryprivate.h"
#include <cairo-gobject.h> #include <cairo-gobject.h>
@ -2534,17 +2535,16 @@ location_entry_create (GtkFileChooserWidget *impl)
} }
static gboolean static gboolean
external_entry_event (GtkWidget *entry, forward_key (GtkEventControllerKey *key,
GdkEvent *event, guint keyval,
GtkFileChooserWidget *impl) guint keycode,
GdkModifierType modifiers,
GtkFileChooserWidget *impl)
{ {
/* Since the entry is not a descendent of the file chooser widget /* Since the entry is not a descendent of the file chooser widget
* in this case, we need to manually make our bindings apply. * in this case, we need to manually make our bindings apply.
*/ */
if (gdk_event_get_event_type (event) != GDK_KEY_PRESS) return gtk_event_controller_key_forward (key, GTK_WIDGET (impl));
return GDK_EVENT_PROPAGATE;
return gtk_bindings_activate_event (G_OBJECT (impl), (GdkEventKey *)event);
} }
/* Creates the widgets specific to Save mode */ /* Creates the widgets specific to Save mode */
@ -2569,8 +2569,9 @@ save_widgets_create (GtkFileChooserWidget *impl)
priv->location_entry = priv->external_entry; priv->location_entry = priv->external_entry;
location_entry_setup (impl); location_entry_setup (impl);
g_signal_connect_after (priv->external_entry, "event", g_signal_connect_after (gtk_entry_get_key_controller (GTK_ENTRY (priv->external_entry)),
G_CALLBACK (external_entry_event), impl); "key-pressed",
G_CALLBACK (forward_key), impl);
return; return;
} }
@ -2611,7 +2612,8 @@ save_widgets_destroy (GtkFileChooserWidget *impl)
if (priv->external_entry && priv->external_entry == priv->location_entry) if (priv->external_entry && priv->external_entry == priv->location_entry)
{ {
g_signal_handlers_disconnect_by_func (priv->external_entry, external_entry_event, impl); g_signal_handlers_disconnect_by_func (gtk_entry_get_key_controller (GTK_ENTRY (priv->external_entry)),
forward_key, impl);
location_entry_disconnect (impl); location_entry_disconnect (impl);
priv->location_entry = NULL; priv->location_entry = NULL;