changeset 14338:2ec879353592

[gaim-migrate @ 17035] Fixes SF Bug # 1373116 (and related Debian Bug #341607) Fix the Find functionality in the log viewer. It now properly scrolls to the first occurrence of the search term. Also, clicking the Find button will now jump to the next occurrence of the search term, including wrapping around to the top. Possible Badness: This changes the behavior of all IMHTML searches. Previously, if you kept calling gtk_imhtml_search_find(), it'd clear the highlighting when you went past the last occurrence of the search term. This seems wrong. I believe it should either stop or wrap around to the top. Wrapping around seemed most useful to me, so that's what I implemented. This was inspired by SF Patch #1545488 by Mark Schneider committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Sat, 26 Aug 2006 06:25:49 +0000
parents 1a500db56415
children ba1fd54bb157
files doc/ChangeLog.API gtk/gtkimhtml.c gtk/gtklog.c
diffstat 3 files changed, 49 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog.API	Fri Aug 25 23:59:23 2006 +0000
+++ b/doc/ChangeLog.API	Sat Aug 26 06:25:49 2006 +0000
@@ -125,6 +125,8 @@
 	* gaim_gtk_create_imhtml(): Added sw_ret() parameter
 	* gaim_account_get_log(): Added create parameter
 	* GAIM_CMD_P_VERYHIGH is now GAIM_CMD_P_VERY_HIGH
+	* gtk_imhtml_search_find(): Now wraps around to the top instead of
+	  clearing the search at the end.
 
 	Removed:
 	* gaim_gtk_sound_{get,set}_mute() (replaced by the /gaim/gtk/sound/mute
--- a/gtk/gtkimhtml.c	Fri Aug 25 23:59:23 2006 +0000
+++ b/gtk/gtkimhtml.c	Sat Aug 26 06:25:49 2006 +0000
@@ -3542,12 +3542,13 @@
 	imhtml->search_string = g_strdup(text);
 
 	if (gtk_source_iter_forward_search(&iter, imhtml->search_string,
-					   GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
-					 &start, &end, NULL)) {
-
+	                                   GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
+	                                   &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) {
+		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);
@@ -3558,8 +3559,22 @@
 		}
 		return TRUE;
 	}
-
-	gtk_imhtml_search_clear(imhtml);
+	else if (!new_search)
+	{
+		/* We hit the end, so start at the beginning again. */
+		gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter);
+
+		if (gtk_source_iter_forward_search(&iter, imhtml->search_string,
+		                                   GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
+		                                   &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);
+
+			return TRUE;
+		}
+
+	}
 
 	return FALSE;
 }
--- a/gtk/gtklog.c	Fri Aug 25 23:59:23 2006 +0000
+++ b/gtk/gtklog.c	Sat Aug 26 06:25:49 2006 +0000
@@ -111,23 +111,32 @@
 	const char *search_term = gtk_entry_get_text(GTK_ENTRY(lv->entry));
 	GList *logs;
 
-	g_free(lv->search);
-
-	gtk_tree_store_clear(lv->treestore);
 	if (!(*search_term)) {
 		/* reset the tree */
+		gtk_tree_store_clear(lv->treestore);
 		populate_log_tree(lv);
+		g_free(lv->search);
 		lv->search = NULL;
 		gtk_imhtml_search_clear(GTK_IMHTML(lv->imhtml));
 		select_first_log(lv);
 		return;
 	}
 
-	lv->search = g_strdup(search_term);
-	gtk_imhtml_clear(GTK_IMHTML(lv->imhtml));
+	if (lv->search != NULL && !strcmp(lv->search, search_term))
+	{
+		/* Searching for the same term acts as "Find Next" */
+		gtk_imhtml_search_find(GTK_IMHTML(lv->imhtml), lv->search);
+		return;	
+	}
 
 	gaim_gtk_set_cursor(lv->window, GDK_WATCH);
 
+	g_free(lv->search);
+	lv->search = g_strdup(search_term);
+
+	gtk_tree_store_clear(lv->treestore);
+	gtk_imhtml_clear(GTK_IMHTML(lv->imhtml));
+
 	for (logs = lv->logs; logs != NULL; logs = logs->next) {
 		char *read = gaim_log_read((GaimLog*)logs->data, NULL);
 		if (read && *read && gaim_strcasestr(read, search_term)) {
@@ -176,6 +185,13 @@
 		gtk_tree_view_expand_row(tv, path, FALSE);
 }
 
+static gboolean search_find_cb(gpointer data)
+{
+	GaimGtkLogViewer *viewer = data;
+	gtk_imhtml_search_find(GTK_IMHTML(viewer->imhtml), viewer->search);
+	return FALSE;
+}
+
 static void log_select_cb(GtkTreeSelection *sel, GaimGtkLogViewer *viewer) {
 	GtkTreeIter iter;
 	GValue val;
@@ -230,7 +246,7 @@
 
 	if (viewer->search != NULL) {
 		gtk_imhtml_search_clear(GTK_IMHTML(viewer->imhtml));
-		gtk_imhtml_search_find(GTK_IMHTML(viewer->imhtml), viewer->search);
+		g_idle_add(search_find_cb, viewer);
 	}
 
 	gaim_gtk_clear_cursor(viewer->window);
@@ -291,7 +307,7 @@
 	GtkWidget *vbox;
 	GtkWidget *frame;
 	GtkWidget *hbox;
-	GtkWidget *button;
+	GtkWidget *find_button;
 	GtkWidget *size_label;
 
 	if (logs == NULL)
@@ -417,10 +433,10 @@
 	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
 	lv->entry = gtk_entry_new();
 	gtk_box_pack_start(GTK_BOX(hbox), lv->entry, TRUE, TRUE, 0);
-	button = gtk_button_new_from_stock(GTK_STOCK_FIND);
-	gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
+	find_button = gtk_button_new_from_stock(GTK_STOCK_FIND);
+	gtk_box_pack_start(GTK_BOX(hbox), find_button, FALSE, FALSE, 0);
 	g_signal_connect(GTK_ENTRY(lv->entry), "activate", G_CALLBACK(search_cb), lv);
-	g_signal_connect(GTK_BUTTON(button), "clicked", G_CALLBACK(search_cb), lv);
+	g_signal_connect(GTK_BUTTON(find_button), "clicked", G_CALLBACK(search_cb), lv);
 
 	select_first_log(lv);