bgo#634558 - filechooser - Actually focus the Search entry when selecting the Search shortcut

Signed-off-by: Federico Mena Quintero <federico@novell.com>
This commit is contained in:
Federico Mena Quintero 2010-11-16 10:56:34 -06:00
parent 70929bc7ba
commit 10d541b8b6
2 changed files with 50 additions and 14 deletions

View File

@ -2325,6 +2325,19 @@ new_folder_button_clicked (GtkButton *button,
gtk_tree_path_free (path); gtk_tree_path_free (path);
} }
static GSource *
add_idle_while_impl_is_alive (GtkFileChooserDefault *impl, GCallback callback)
{
GSource *source;
source = g_idle_source_new ();
g_source_set_closure (source,
g_cclosure_new_object (callback, G_OBJECT (impl)));
g_source_attach (source, NULL);
return source;
}
/* Idle handler for creating a new folder after editing its name cell, or for /* Idle handler for creating a new folder after editing its name cell, or for
* canceling the editing. * canceling the editing.
*/ */
@ -2383,13 +2396,7 @@ queue_edited_idle (GtkFileChooserDefault *impl,
*/ */
if (!impl->edited_idle) if (!impl->edited_idle)
{ impl->edited_idle = add_idle_while_impl_is_alive (impl, G_CALLBACK (edited_idle_cb));
impl->edited_idle = g_idle_source_new ();
g_source_set_closure (impl->edited_idle,
g_cclosure_new_object (G_CALLBACK (edited_idle_cb),
G_OBJECT (impl)));
g_source_attach (impl->edited_idle, NULL);
}
g_free (impl->edited_new_text); g_free (impl->edited_new_text);
impl->edited_new_text = g_strdup (new_text); impl->edited_new_text = g_strdup (new_text);
@ -3134,11 +3141,7 @@ shortcuts_drag_leave_cb (GtkWidget *widget,
#if 0 #if 0
if (gtk_drag_get_source_widget (context) == widget && !impl->shortcuts_drag_outside_idle) if (gtk_drag_get_source_widget (context) == widget && !impl->shortcuts_drag_outside_idle)
{ {
impl->shortcuts_drag_outside_idle = g_idle_source_new (); impl->shortcuts_drag_outside_idle = add_idle_while_impl_is_alive (impl, G_CALLBACK (shortcuts_drag_outside_idle_cb));
g_source_set_closure (impl->shortcuts_drag_outside_idle,
g_cclosure_new_object (G_CALLBACK (shortcuts_drag_outside_idle_cb),
G_OBJECT (impl)));
g_source_attach (impl->shortcuts_drag_outside_idle, NULL);
} }
#endif #endif
@ -9079,6 +9082,37 @@ search_entry_activate_cb (GtkEntry *entry,
search_start_query (impl, text); search_start_query (impl, text);
} }
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));
}
/* Hides the path bar and creates the search entry */ /* Hides the path bar and creates the search entry */
static void static void
search_setup_widgets (GtkFileChooserDefault *impl) search_setup_widgets (GtkFileChooserDefault *impl)
@ -9147,7 +9181,7 @@ search_setup_widgets (GtkFileChooserDefault *impl)
gtk_widget_hide (impl->location_entry_box); gtk_widget_hide (impl->location_entry_box);
} }
gtk_widget_grab_focus (impl->search_entry); focus_search_entry_in_idle (impl);
/* FMQ: hide the filter combo? */ /* FMQ: hide the filter combo? */
} }
@ -9191,7 +9225,7 @@ search_activate (GtkFileChooserDefault *impl)
if (impl->operation_mode == OPERATION_MODE_SEARCH) if (impl->operation_mode == OPERATION_MODE_SEARCH)
{ {
gtk_widget_grab_focus (impl->search_entry); focus_search_entry_in_idle (impl);
return; return;
} }

View File

@ -273,6 +273,8 @@ struct _GtkFileChooserDefault
gulong settings_signal_id; gulong settings_signal_id;
int icon_size; int icon_size;
GSource *focus_entry_idle;
gulong toplevel_set_focus_id; gulong toplevel_set_focus_id;
GtkWidget *toplevel_last_focus_widget; GtkWidget *toplevel_last_focus_widget;