+static gboolean
+focus_entry_idle_cb (GtkFileChooserDefault *impl)
+{
+ GDK_THREADS_ENTER ();
+
+ g_source_destroy (impl->focus_entry_idle);
+ impl->focus_entry_idle = NULL;
+
+ if (impl->search_entry)
+ gtk_widget_grab_focus (impl->search_entry);
+
+ GDK_THREADS_LEAVE ();
+
+ return FALSE;
+}
+
+static void
+focus_search_entry_in_idle (GtkFileChooserDefault *impl)
+{
+ /* bgo#634558 - When the user clicks on the Search entry in the shortcuts
+ * pane, we get a selection-changed signal and we set up the search widgets.
+ * However, gtk_tree_view_button_press() focuses the treeview *after* making
+ * the change to the selection. So, we need to re-focus the search entry
+ * after the treeview has finished doing its work; we'll do that in an idle
+ * handler.
+ */
+
+ if (!impl->focus_entry_idle)
+ impl->focus_entry_idle = add_idle_while_impl_is_alive (impl, G_CALLBACK (focus_entry_idle_cb));
+}
+