From 1657404cf753ec4ed9b2a0e76cf02c0aba40a08a Mon Sep 17 00:00:00 2001 From: Ettore Perazzoli Date: Mon, 18 Mar 2002 20:54:36 +0000 Subject: New halper function to update the sensitivity of the commands. * e-search-bar.c (update_sensitivity): New halper function to update the sensitivity of the commands. (entry_changed_cb): New callback to make the activate_button and the "Find Now" verb sensitive only if the entry has some contents. (activate_by_subitems): Connect the callback here. (setup_standard_verbs): Call update_sensitivity() here. svn path=/trunk/; revision=16199 --- widgets/misc/ChangeLog | 9 +++++++++ widgets/misc/e-search-bar.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) (limited to 'widgets/misc') diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog index b2880a8559..9ec923e5ab 100644 --- a/widgets/misc/ChangeLog +++ b/widgets/misc/ChangeLog @@ -1,3 +1,12 @@ +2002-03-18 Ettore Perazzoli + + * e-search-bar.c (update_sensitivity): New halper function to + update the sensitivity of the commands. + (entry_changed_cb): New callback to make the activate_button and + the "Find Now" verb sensitive only if the entry has some contents. + (activate_by_subitems): Connect the callback here. + (setup_standard_verbs): Call update_sensitivity() here. + 2002-03-18 Ettore Perazzoli * e-search-bar.c (init): Init clear_button to NULL. diff --git a/widgets/misc/e-search-bar.c b/widgets/misc/e-search-bar.c index d70db2b9cc..b8bda3888c 100644 --- a/widgets/misc/e-search-bar.c +++ b/widgets/misc/e-search-bar.c @@ -96,6 +96,31 @@ emit_menu_activated (ESearchBar *esb, int item) item); } + +/* Utility functions. */ + +static void +update_sensitivity (ESearchBar *search_bar) +{ + const char *text; + + text = gtk_entry_get_text (GTK_ENTRY (search_bar->entry)); + + if (text != NULL && text[0] != '\0') { + if (search_bar->ui_component != NULL) + bonobo_ui_component_set_prop (search_bar->ui_component, + "/commands/ESearchBar:SearchNow", + "sensitive", "1", NULL); + gtk_widget_set_sensitive (search_bar->activate_button, TRUE); + } else { + if (search_bar->ui_component != NULL) + bonobo_ui_component_set_prop (search_bar->ui_component, + "/commands/ESearchBar:SearchNow", + "sensitive", "0", NULL); + gtk_widget_set_sensitive (search_bar->activate_button, FALSE); + } +} + /* This implements the "clear" action, i.e. clears the text and then emits * ::search_activated. */ @@ -138,6 +163,9 @@ setup_standard_verbs (ESearchBar *search_bar) clear_verb_cb, search_bar); bonobo_ui_component_add_verb (search_bar->ui_component, "ESearchBar:SearchNow", search_now_verb_cb, search_bar); + + /* Make sure the entries are created with the correct sensitivity. */ + update_sensitivity (search_bar); } /* Callbacks -- The verbs for all the definable items. */ @@ -167,6 +195,13 @@ entry_activated_cb (GtkWidget *widget, emit_search_activated (esb); } +static void +entry_changed_cb (GtkWidget *widget, + ESearchBar *esb) +{ + update_sensitivity (esb); +} + static void subitem_activated_cb (GtkWidget *widget, ESearchBar *esb) { @@ -199,6 +234,8 @@ activate_by_subitems (ESearchBar *esb, gint item_id, ESearchBarSubitem *subitems esb->entry = gtk_entry_new(); gtk_widget_set_usize (esb->entry, 4, -1); gtk_object_ref (GTK_OBJECT (esb->entry)); + gtk_signal_connect (GTK_OBJECT (esb->entry), "changed", + GTK_SIGNAL_FUNC (entry_changed_cb), esb); gtk_signal_connect (GTK_OBJECT (esb->entry), "activate", GTK_SIGNAL_FUNC (entry_activated_cb), esb); gtk_container_add (GTK_CONTAINER (esb->entry_box), esb->entry); -- cgit