From ceff7d71a21245adb31a8f805a66103da8f12765 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 13 Jun 2007 11:27:04 +0200 Subject: [PATCH] Improve address/title logic --- lib/sugar-address-entry.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/sugar-address-entry.c b/lib/sugar-address-entry.c index 07f2d13d..6b6ea0d8 100644 --- a/lib/sugar-address-entry.c +++ b/lib/sugar-address-entry.c @@ -493,17 +493,31 @@ sugar_address_entry_expose(GtkWidget *widget, return FALSE; } +static void +entry_changed_cb(SugarAddressEntry *entry) +{ + if (entry->address) { + g_free (entry->address); + } + + entry->address = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); +} + static void update_entry_text(SugarAddressEntry *address_entry, gboolean has_focus) { - if (has_focus) { + g_signal_handlers_block_by_func(address_entry, entry_changed_cb, NULL); + + if (has_focus || address_entry->title == NULL) { gtk_entry_set_text(GTK_ENTRY(address_entry), address_entry->address); } else { gtk_entry_set_text(GTK_ENTRY(address_entry), address_entry->title); } + + g_signal_handlers_unblock_by_func(address_entry, entry_changed_cb, NULL); } static void @@ -656,6 +670,8 @@ sugar_address_entry_init(SugarAddressEntry *entry) G_CALLBACK(focus_in_event_cb), NULL); g_signal_connect(entry, "focus-out-event", G_CALLBACK(focus_out_event_cb), NULL); + g_signal_connect(entry, "changed", + G_CALLBACK(entry_changed_cb), NULL); g_signal_connect(entry, "button-press-event", G_CALLBACK(button_press_event_cb), NULL); }