comparison 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
comparison
equal deleted inserted replaced
7294:e5d0f5cb61fb 7295:c7f0a4397d9e
407 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL); 407 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL);
408 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); 408 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL);
409 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL); 409 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL);
410 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); 410 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL);
411 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); 411 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL);
412 412 gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL);
413
413 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ 414 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */
414 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); 415 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2);
415 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); 416 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR);
416 417
417 imhtml->show_smileys = TRUE; 418 imhtml->show_smileys = TRUE;
1762 1763
1763 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale) 1764 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale)
1764 { 1765 {
1765 g_free(scale); 1766 g_free(scale);
1766 } 1767 }
1768
1769 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text)
1770 {
1771 GtkTextIter iter, start, end;
1772 gboolean new_search = TRUE;
1773
1774 g_return_val_if_fail(imhtml != NULL, FALSE);
1775 g_return_val_if_fail(text != NULL, FALSE);
1776
1777 if (imhtml->search_string && !strcmp(text, imhtml->search_string))
1778 new_search = FALSE;
1779
1780
1781 if (new_search) {
1782 gtk_imhtml_search_clear(imhtml);
1783 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter);
1784 } else {
1785 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter,
1786 gtk_text_buffer_get_mark(imhtml->text_buffer, "search"));
1787 }
1788 imhtml->search_string = g_strdup(text);
1789
1790 if (gtk_text_iter_forward_search(&iter, imhtml->search_string,
1791 GTK_TEXT_SEARCH_VISIBLE_ONLY,
1792 &start, &end, NULL)) {
1793
1794 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0);
1795 gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE);
1796 if (new_search) {
1797 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end);
1798 do
1799 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end);
1800 while (gtk_text_iter_forward_search(&end, imhtml->search_string, GTK_TEXT_SEARCH_VISIBLE_ONLY,
1801 &start, &end, NULL));
1802 }
1803 return TRUE;
1804 }
1805 return FALSE;
1806 }
1807
1808 void gtk_imhtml_search_clear(GtkIMHtml *imhtml)
1809 {
1810 GtkTextIter start, end;
1811
1812 g_return_if_fail(imhtml != NULL);
1813
1814 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start);
1815 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end);
1816
1817 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end);
1818 if (imhtml->search_string)
1819 g_free(imhtml->search_string);
1820 imhtml->search_string = NULL;
1821 }