From f18eef7e6faab4730ab16d46f4b12f7004815558 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 27 Apr 2020 00:13:46 -0400 Subject: filechooser: Fix type-to-search We need to capture the keys and forward them to the search entry, for anything to happen. --- gtk/gtkfilechooserwidget.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gtk/gtkfilechooserwidget.c') diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index 7be77590a4..c625114015 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -7658,6 +7658,26 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class) gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); } +static gboolean +captured_key (GtkEventControllerKey *controller, + guint keyval, + guint keycode, + GdkModifierType state, + gpointer data) +{ + GtkFileChooserWidget *impl = data; + gboolean handled; + + if (impl->operation_mode == OPERATION_MODE_SEARCH) + return GDK_EVENT_PROPAGATE; + + handled = gtk_event_controller_key_forward (controller, GTK_WIDGET (impl->search_entry)); + if (handled == GDK_EVENT_STOP) + operation_mode_set (impl, OPERATION_MODE_SEARCH); + + return handled; +} + static void post_process_ui (GtkFileChooserWidget *impl) { @@ -7735,6 +7755,12 @@ post_process_ui (GtkFileChooserWidget *impl) gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (impl->search_entry), impl->search_entry); + controller = gtk_event_controller_key_new (); + g_signal_connect (controller, "key-pressed", G_CALLBACK (captured_key), impl); + g_signal_connect (controller, "key-released", G_CALLBACK (captured_key), impl); + gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE); + gtk_widget_add_controller (GTK_WIDGET (impl), controller); + gtk_widget_set_parent (impl->rename_file_popover, GTK_WIDGET (impl)); gesture = gtk_gesture_click_new (); -- cgit v1.2.1