[Xfce4-commits] <midori:master> Implement sokoke_entry_set_clear_button_visible
Christian Dywan
noreply at xfce.org
Sat Jan 14 07:02:04 CET 2012
Updating branch refs/heads/master
to c0e0bee467561d5840430151bea760e104766992 (commit)
from ff95e17f6fabcfb68b52e0fba5cd080f5bc985cc (commit)
commit c0e0bee467561d5840430151bea760e104766992
Author: Peter Hatina <phatina at redhat.com>
Date: Sat Jan 14 00:34:11 2012 +0100
Implement sokoke_entry_set_clear_button_visible
Fixes: https://bugs.launchpad.net/midori/+bug/699954
midori/midori-searchaction.c | 1 +
midori/sokoke.c | 52 ++++++++++++++++++++++++++++++++++++++++++
midori/sokoke.h | 4 +++
3 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/midori/midori-searchaction.c b/midori/midori-searchaction.c
index 39ef35b..c4a9712 100644
--- a/midori/midori-searchaction.c
+++ b/midori/midori-searchaction.c
@@ -312,6 +312,7 @@ midori_search_action_create_tool_item (GtkAction* action)
toolitem = GTK_WIDGET (gtk_tool_item_new ());
entry = gtk_icon_entry_new ();
+ sokoke_entry_set_clear_button_visible (GTK_ENTRY (entry), TRUE);
gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (entry),
GTK_ICON_ENTRY_PRIMARY, TRUE);
alignment = gtk_alignment_new (0, 0.5, 1, 0.1);
diff --git a/midori/sokoke.c b/midori/sokoke.c
index 39ea28e..e60087b 100644
--- a/midori/sokoke.c
+++ b/midori/sokoke.c
@@ -1731,3 +1731,55 @@ midori_download_prepare_tooltip_text (WebKitDownload* download)
return g_string_free (tooltip, FALSE);
}
+static void
+sokoke_entry_changed_cb (GtkEditable* editable,
+ GtkEntry* entry)
+{
+ const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
+ gboolean visible = text && *text;
+ gtk_icon_entry_set_icon_from_stock (
+ GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_SECONDARY,
+ visible ? GTK_STOCK_CLEAR : NULL);
+}
+
+static void
+sokoke_entry_icon_released_cb (GtkEntry* entry,
+ GtkIconEntryPosition icon_pos,
+ GdkEvent* event,
+ gpointer user_data)
+{
+ if (icon_pos != GTK_ICON_ENTRY_SECONDARY)
+ return;
+
+ gtk_entry_set_text (entry, "");
+ gtk_widget_grab_focus (GTK_WIDGET (entry));
+}
+
+void
+sokoke_entry_set_clear_button_visible (GtkEntry* entry,
+ gboolean visible)
+{
+ g_return_if_fail (GTK_IS_ENTRY (entry));
+
+ gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (entry),
+ GTK_ICON_ENTRY_SECONDARY, TRUE);
+ if (visible)
+ {
+ g_object_connect (entry,
+ "signal::icon-release",
+ G_CALLBACK (sokoke_entry_icon_released_cb), NULL,
+ "signal::changed",
+ G_CALLBACK (sokoke_entry_changed_cb), entry, NULL);
+ g_signal_emit_by_name (G_OBJECT (entry), "changed");
+ }
+ else
+ {
+ g_object_disconnect (entry,
+ "any_signal::icon-release",
+ G_CALLBACK (sokoke_entry_icon_released_cb), NULL,
+ "any_signal::changed",
+ G_CALLBACK (sokoke_entry_changed_cb), entry, NULL);
+ }
+}
+
diff --git a/midori/sokoke.h b/midori/sokoke.h
index db7aa28..ac8902f 100644
--- a/midori/sokoke.h
+++ b/midori/sokoke.h
@@ -202,4 +202,8 @@ sokoke_build_thumbnail_path (const gchar* name);
gchar*
midori_download_prepare_tooltip_text (WebKitDownload* download);
+void
+sokoke_entry_set_clear_button_visible (GtkEntry* entry,
+ gboolean visible);
+
#endif /* !__SOKOKE_H__ */
More information about the Xfce4-commits
mailing list