]> spindle.queued.net Git - midori/commitdiff
Implement sokoke_entry_set_clear_button_visible
authorPeter Hatina <phatina@redhat.com>
Fri, 13 Jan 2012 23:34:11 +0000 (00:34 +0100)
committerChristian Dywan <christian@twotoasts.de>
Fri, 13 Jan 2012 23:34:11 +0000 (00:34 +0100)
Fixes: https://bugs.launchpad.net/midori/+bug/699954
midori/midori-searchaction.c
midori/sokoke.c
midori/sokoke.h

index 39ef35be721054daedf47c419ce910922cfd9499..c4a97121f3ac080bcd8598926036da7b76f15bb8 100644 (file)
@@ -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);
index 39ea28eba83bcd6602cfd50765af98dd1fae4149..e60087b57a4f5fe2ed4e241216915f88d900a861 100644 (file)
@@ -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);
+    }
+}
+
index db7aa28a91ac6a4cbc49b3a8c2f375b46b42ae41..ac8902f0cee1495cb6be387e1e16e4094abb6a65 100644 (file)
@@ -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__ */