diff options
author | John Sullivan <sullivan@src.gnome.org> | 2000-08-07 21:11:53 +0000 |
---|---|---|
committer | John Sullivan <sullivan@src.gnome.org> | 2000-08-07 21:11:53 +0000 |
commit | 2d310112d76078f5054179b27cd88a57b6a534d7 (patch) | |
tree | 00a5fe3d1f8a40c0e63a0b2c8ed1c52777ee7dd8 /src/nautilus-simple-search-bar.c | |
parent | 7610363ab70c92556385f468d55e8cbf53aca740 (diff) | |
download | nautilus-2d310112d76078f5054179b27cd88a57b6a534d7.tar.gz |
Fixed bug 1969 enough for now (search bar buttons should
become sensitive & insensitive appropriately). Will write
up bug reports about remaining issues.
Made the "Find" button only be sensitive if all text-entry
fields are non-empty. (Did this for both simple & complex
search bar). Cleaned up some other code that I couldn't
avoid in there too.
* src/nautilus-simple-search-bar.c:
Define Details struct.
(nautilus_simple_search_bar_initialize_class): Wire up
destroy handler.
(search_text_is_invalid): New function, returns TRUE if the
text is empty.
(update_simple_find_button_state): New function, sets the
sensitivity of the find button based on search_text_is_invalid.
(activated_search_field): New function, calls location_changed
only if text is valid.
(nautilus_simple_search_bar_initialize): Initialize Details field;
change "activate" signal on text field to call
activated_search_field instead of calling location_changed directly
so it can handle the text-invalid case; wired "change" signal of
text field to update_simple_find_button_state; call update_simple_
find_button_state once after setting up widgets; simplify
widget-creation code.
(nautilus_simple_search_bar_destroy): Free details field.
(nautilus_simple_search_bar_set_location),
(nautilus_simple_search_bar_get_location): Updated to use Details.
* src/nautilus-complex-search-bar.c:
(criteria_invalid): Walks through the list of criteria, checking
whether any of the text-field ones have empty text. Later we
could add other types of checks in here.
(update_options_buttons_state): Just added FIXME comment.
(update_find_button_state): New function, sets sensitivity
of find button based on criteria_invalid.
(update_dynamic_buttons_state): New function, calls the other
two button-updating functions.
(nautilus_complex_search_bar_initialize_class): Wire up destroy
handler.
(more_options_callback), (fewer_options_callback),
(nautilus_complex_search_bar_initialize):
Call update_dynamic_buttons_state instead of just
update_options_buttons_state.
(nautilus_complex_search_bar_destroy): free Details struct. This
was leaking before.
(attach_criterion_to_search_bar): Attach update_find_button_state
to "changed" signal of any new text-entry field.
* src/nautilus-simple-search-bar.h: Replaced several fields in
NautilusSimpleSearchBar struct with new Details field. Among
the replaced fields were some undo-related ones that were not
yet used anywhere, so I left them out of Details.
Diffstat (limited to 'src/nautilus-simple-search-bar.c')
-rw-r--r-- | src/nautilus-simple-search-bar.c | 77 |
1 files changed, 58 insertions, 19 deletions
diff --git a/src/nautilus-simple-search-bar.c b/src/nautilus-simple-search-bar.c index f30e8e2cb..ac77308ed 100644 --- a/src/nautilus-simple-search-bar.c +++ b/src/nautilus-simple-search-bar.c @@ -27,9 +27,11 @@ #include <libgnomevfs/gnome-vfs-utils.h> #include <libnautilus-extensions/nautilus-gtk-macros.h> +#include <libnautilus-extensions/nautilus-string.h> struct NautilusSimpleSearchBarDetails { GtkEntry *entry; + GtkWidget *find_button; }; static char * nautilus_simple_search_bar_get_location (NautilusNavigationBar *bar); @@ -41,6 +43,7 @@ static char * nautilus_simple_search_criteria_to_search_uri (const char static void nautilus_simple_search_bar_initialize_class (NautilusSimpleSearchBarClass *class); static void nautilus_simple_search_bar_initialize (NautilusSimpleSearchBar *bar); +static void nautilus_simple_search_bar_destroy (GtkObject *object); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusSimpleSearchBar, nautilus_simple_search_bar, @@ -49,40 +52,76 @@ NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusSimpleSearchBar, static void nautilus_simple_search_bar_initialize_class (NautilusSimpleSearchBarClass *klass) { + GTK_OBJECT_CLASS (klass)->destroy = nautilus_simple_search_bar_destroy; + NAUTILUS_NAVIGATION_BAR_CLASS (klass)->get_location = nautilus_simple_search_bar_get_location; NAUTILUS_NAVIGATION_BAR_CLASS (klass)->set_location = nautilus_simple_search_bar_set_location; } +static gboolean +search_text_is_invalid (NautilusSimpleSearchBar *bar) +{ + char *user_text; + gboolean is_empty; + + user_text = gtk_editable_get_chars (GTK_EDITABLE (bar->details->entry), 0, -1); + is_empty = nautilus_str_is_empty (user_text); + g_free (user_text); + + return is_empty; +} + +static void +update_simple_find_button_state (NautilusSimpleSearchBar *bar) +{ + gtk_widget_set_sensitive (GTK_WIDGET (bar->details->find_button), + !search_text_is_invalid (bar)); +} + +static void +activated_search_field (NautilusSimpleSearchBar *bar) +{ + /* Might be called when there's no text. */ + if (!search_text_is_invalid (bar)) { + nautilus_navigation_bar_location_changed + (NAUTILUS_NAVIGATION_BAR (bar)); + } +} + static void nautilus_simple_search_bar_initialize (NautilusSimpleSearchBar *bar) { - GtkWidget *entry; GtkWidget *hbox; - GtkWidget *find_them, *find_them_label; + bar->details = g_new0 (NautilusSimpleSearchBarDetails, 1); + hbox = gtk_hbox_new (0, FALSE); - entry = gtk_entry_new (); - gtk_signal_connect_object (GTK_OBJECT (entry), "activate", - nautilus_navigation_bar_location_changed, GTK_OBJECT (bar)); - gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); - - find_them = gtk_button_new (); - find_them_label = gtk_label_new ("Find Them!"); - gtk_container_add (GTK_CONTAINER (find_them), find_them_label); - gtk_signal_connect_object (GTK_OBJECT (find_them), "pressed", + bar->details->entry = GTK_ENTRY (gtk_entry_new ()); + gtk_signal_connect_object (GTK_OBJECT (bar->details->entry), "activate", + activated_search_field, GTK_OBJECT (bar)); + gtk_signal_connect_object (GTK_OBJECT (bar->details->entry), "changed", + update_simple_find_button_state, GTK_OBJECT (bar)); + + gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (bar->details->entry), TRUE, TRUE, 0); + + bar->details->find_button = gtk_button_new_with_label (_("Find Them!")); + gtk_signal_connect_object (GTK_OBJECT (bar->details->find_button), "clicked", nautilus_navigation_bar_location_changed, GTK_OBJECT (bar)); - gtk_box_pack_start (GTK_BOX (hbox), find_them, FALSE, TRUE, 1); - + gtk_box_pack_start (GTK_BOX (hbox), bar->details->find_button, FALSE, TRUE, 1); + update_simple_find_button_state (bar); gtk_container_add (GTK_CONTAINER (bar), hbox); - - gtk_widget_show_all (hbox); - - bar->entry = GTK_ENTRY (entry); +} + +static void +nautilus_simple_search_bar_destroy (GtkObject *object) +{ + g_free (NAUTILUS_SIMPLE_SEARCH_BAR (object)->details); + NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object)); } GtkWidget * @@ -105,7 +144,7 @@ nautilus_simple_search_bar_set_location (NautilusNavigationBar *navigation_bar, /* Set the words in the box to be the words originally done in the search */ criteria = nautilus_search_uri_to_simple_search_criteria (location); - gtk_entry_set_text (bar->entry, criteria); + gtk_entry_set_text (bar->details->entry, criteria); g_free (criteria); } @@ -116,7 +155,7 @@ nautilus_simple_search_bar_get_location (NautilusNavigationBar *navigation_bar) char *search_entry_text; bar = NAUTILUS_SIMPLE_SEARCH_BAR (navigation_bar); - search_entry_text = gtk_entry_get_text (bar->entry); + search_entry_text = gtk_entry_get_text (bar->details->entry); return nautilus_simple_search_criteria_to_search_uri (search_entry_text); } |