gtkplacesview: add a clear button to address entry

So it allows a quick way to clear the entry.

https://bugzilla.gnome.org/show_bug.cgi?id=756568
This commit is contained in:
Carlos Soriano 2015-09-24 11:26:59 +02:00
parent f9b6c07c8a
commit 9341f64c19
2 changed files with 21 additions and 2 deletions

View File

@ -1828,11 +1828,19 @@ on_address_entry_text_changed (GtkPlacesView *view)
priv = gtk_places_view_get_instance_private (view);
supported = FALSE;
supported_protocols = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
address = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->address_entry)));
if (strlen (address) > 0)
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->address_entry),
GTK_ENTRY_ICON_SECONDARY,
"edit-clear-symbolic");
else
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->address_entry),
GTK_ENTRY_ICON_SECONDARY,
NULL);
if (!supported_protocols)
return;
goto out;
address = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->address_entry)));
scheme = g_uri_parse_scheme (address);
if (!scheme)
@ -1846,6 +1854,15 @@ out:
g_free (address);
}
static void
on_address_entry_clear_pressed (GtkPlacesView *view,
GtkEntryIconPosition icon_pos,
GdkEvent *event,
GtkEntry *entry)
{
gtk_entry_set_text (entry, "");
}
static void
on_recent_servers_listbox_row_activated (GtkPlacesView *view,
GtkPlacesViewRow *row,
@ -2220,6 +2237,7 @@ gtk_places_view_class_init (GtkPlacesViewClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GtkPlacesView, stack);
gtk_widget_class_bind_template_callback (widget_class, on_address_entry_text_changed);
gtk_widget_class_bind_template_callback (widget_class, on_address_entry_clear_pressed);
gtk_widget_class_bind_template_callback (widget_class, on_connect_button_clicked);
gtk_widget_class_bind_template_callback (widget_class, on_key_press_event);
gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_activated);

View File

@ -247,6 +247,7 @@
<property name="completion">address_entry_completion</property>
<signal name="notify::text" handler="on_address_entry_text_changed" object="GtkPlacesView" swapped="yes"/>
<signal name="activate" handler="on_connect_button_clicked" object="GtkPlacesView" swapped="yes"/>
<signal name="icon-press" handler="on_address_entry_clear_pressed" object="GtkPlacesView" swapped="yes"/>
</object>
</child>
<child>