Commit ffbe7f6e authored by Bastien Nocera's avatar Bastien Nocera

GtkEntry: Focus the entry without selecting the text

Focusing the text entry without selecting all the text is needed in
some places (GtkTreeView, and some uses of GtkSearchEntry) so
create a private helper to avoid replicating the hacks.

https://bugzilla.gnome.org/show_bug.cgi?id=700787
parent 875b1d07
...@@ -4725,6 +4725,15 @@ gtk_entry_focus_out (GtkWidget *widget, ...@@ -4725,6 +4725,15 @@ gtk_entry_focus_out (GtkWidget *widget,
return FALSE; return FALSE;
} }
void
_gtk_entry_grab_focus (GtkEntry *entry,
gboolean select_all)
{
GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (GTK_WIDGET (entry));
if (select_all)
gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
}
static void static void
gtk_entry_grab_focus (GtkWidget *widget) gtk_entry_grab_focus (GtkWidget *widget)
{ {
...@@ -4732,8 +4741,6 @@ gtk_entry_grab_focus (GtkWidget *widget) ...@@ -4732,8 +4741,6 @@ gtk_entry_grab_focus (GtkWidget *widget)
GtkEntryPrivate *priv = entry->priv; GtkEntryPrivate *priv = entry->priv;
gboolean select_on_focus; gboolean select_on_focus;
GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
if (priv->editable && !priv->in_click) if (priv->editable && !priv->in_click)
{ {
g_object_get (gtk_widget_get_settings (widget), g_object_get (gtk_widget_get_settings (widget),
...@@ -4741,8 +4748,11 @@ gtk_entry_grab_focus (GtkWidget *widget) ...@@ -4741,8 +4748,11 @@ gtk_entry_grab_focus (GtkWidget *widget)
&select_on_focus, &select_on_focus,
NULL); NULL);
if (select_on_focus) _gtk_entry_grab_focus (entry, select_on_focus);
gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1); }
else
{
_gtk_entry_grab_focus (entry, FALSE);
} }
} }
......
...@@ -87,7 +87,8 @@ void _gtk_entry_get_borders (GtkEntry *entry, ...@@ -87,7 +87,8 @@ void _gtk_entry_get_borders (GtkEntry *entry,
GtkIMContext* _gtk_entry_get_im_context (GtkEntry *entry); GtkIMContext* _gtk_entry_get_im_context (GtkEntry *entry);
void _gtk_entry_set_is_cell_renderer (GtkEntry *entry, void _gtk_entry_set_is_cell_renderer (GtkEntry *entry,
gboolean is_cell_renderer); gboolean is_cell_renderer);
void _gtk_entry_grab_focus (GtkEntry *entry,
gboolean select_all);
G_END_DECLS G_END_DECLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment