Mercurial > pidgin.yaz
diff src/gtkimhtml.c @ 7295:c7f0a4397d9e
[gaim-migrate @ 7879]
I added a search feature to conversations. I actually did most of this a
while ago for the log viewer. GtkIMHtml has some functions to handle searching
itself. I just added a new item to the conversation menu to handle it.
This should be useful for long IRC channel backlogs and the sorts.
It's case-sensitive right now. That kinda sucks, but that's all GTK lets me
do. GtkSourceView has some nice case-insensitive search functions that I'll
likely bring in before the release.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 18 Oct 2003 01:58:02 +0000 |
parents | 3a41c3f80228 |
children | 7ba7fedc1d8b |
line wrap: on
line diff
--- a/src/gtkimhtml.c Fri Oct 17 21:29:15 2003 +0000 +++ b/src/gtkimhtml.c Sat Oct 18 01:58:02 2003 +0000 @@ -409,7 +409,8 @@ gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL); gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); - + gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL); + /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); @@ -1764,3 +1765,57 @@ { g_free(scale); } + +gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text) +{ + GtkTextIter iter, start, end; + gboolean new_search = TRUE; + + g_return_val_if_fail(imhtml != NULL, FALSE); + g_return_val_if_fail(text != NULL, FALSE); + + if (imhtml->search_string && !strcmp(text, imhtml->search_string)) + new_search = FALSE; + + + if (new_search) { + gtk_imhtml_search_clear(imhtml); + gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); + } else { + gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, + gtk_text_buffer_get_mark(imhtml->text_buffer, "search")); + } + imhtml->search_string = g_strdup(text); + + if (gtk_text_iter_forward_search(&iter, imhtml->search_string, + GTK_TEXT_SEARCH_VISIBLE_ONLY, + &start, &end, NULL)) { + + gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0); + gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE); + if (new_search) { + gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end); + do + gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end); + while (gtk_text_iter_forward_search(&end, imhtml->search_string, GTK_TEXT_SEARCH_VISIBLE_ONLY, + &start, &end, NULL)); + } + return TRUE; + } + return FALSE; +} + +void gtk_imhtml_search_clear(GtkIMHtml *imhtml) +{ + GtkTextIter start, end; + + g_return_if_fail(imhtml != NULL); + + gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); + gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); + + gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end); + if (imhtml->search_string) + g_free(imhtml->search_string); + imhtml->search_string = NULL; +}