[Gtranslator-devel] [patch] Select found text



Hi,

The attached patch selects the text found by running the Find dialog. It
also fixes the following failed assertion:

(gtranslator:14766): Gtk-CRITICAL **: file gtkeditable.c: line 183
(gtk_editable_select_region): assertion `GTK_IS_EDITABLE (editable)'
failed

OK to commit?


-dan
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtranslator/src/ChangeLog,v
retrieving revision 1.909
diff -u -r1.909 ChangeLog
--- ChangeLog	11 Jan 2004 14:30:47 -0000	1.909
+++ ChangeLog	11 Jan 2004 22:29:57 -0000
@@ -1,3 +1,8 @@
+2004-01-12  Dan Damian  <dand gnome ro>
+
+	* gui.h, gui.c (gtranslator_selection_set), find.c (find_in_msg):
+	Select found text.
+
 2004-01-11  Dan Damian  <dand gnome ro>
 
 	* languages.c (languages): Added mailing list for Romanian.
Index: find.c
===================================================================
RCS file: /cvs/gnome/gtranslator/src/find.c,v
retrieving revision 1.35
diff -u -r1.35 find.c
--- find.c	27 Aug 2003 21:01:01 -0000	1.35
+++ find.c	11 Jan 2004 22:29:57 -0000
@@ -151,8 +151,8 @@
 			 */
 			gtranslator_message_go_to(msg);
 			pos = (regmatch_t *)g_list_nth_data(poslist, actpos);
-			gtk_editable_select_region(GTK_EDITABLE(trans_box),
-				pos->rm_so, pos->rm_eo);
+			gtranslator_selection_set(trans_box,
+						  pos->rm_so, pos->rm_eo);
 			actpos++;
 
 			return 1;
@@ -165,9 +165,9 @@
 			 * We found it!
 			 */
 			gtranslator_message_go_to(msg);
-			pos = (regmatch_t *)g_list_nth_data(poslist, actpos);
-			gtk_editable_select_region(GTK_EDITABLE(text_box),
-				pos->rm_so, pos->rm_eo);
+			pos = (regmatch_t *)g_list_nth_data(poslist, actpos);			
+			gtranslator_selection_set(text_box,
+						  pos->rm_so, pos->rm_eo);
 			actpos++;
 		
 			return 1;
Index: gui.c
===================================================================
RCS file: /cvs/gnome/gtranslator/src/gui.c,v
retrieving revision 1.223
diff -u -r1.223 gui.c
--- gui.c	2 Oct 2003 17:36:58 -0000	1.223
+++ gui.c	11 Jan 2004 22:29:57 -0000
@@ -585,6 +585,33 @@
 	gtk_editable_paste_clipboard(GTK_EDITABLE(trans_box));
 }
 
+void
+gtranslator_selection_set(GtkTextView *text_view, gint start, gint end)
+{
+	GtkTextBuffer *buffer;
+	GtkTextIter start_iter;
+	GtkTextIter end_iter;
+
+	g_return_if_fail(text_view != NULL);
+	g_return_if_fail(start >= 0);
+	g_return_if_fail((end > start) || (end < 0));
+	
+	buffer = GTK_TEXT_BUFFER(gtk_text_view_get_buffer(text_view));
+	g_return_if_fail(buffer != NULL);	
+
+	gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, start);
+
+	if (end < 0)
+		gtk_text_buffer_get_end_iter(buffer, &end_iter);
+	else
+		gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
+	
+	gtk_text_buffer_place_cursor(buffer, &end_iter);
+
+	gtk_text_buffer_move_mark_by_name(buffer, "selection_bound", &start_iter);
+}
+
+
 void gtranslator_selection_clear(GtkWidget  * widget, gpointer useless)
 {
 	GtkTextBuffer *buffer = GTK_TEXT_BUFFER(gtk_text_view_get_buffer(trans_box));
Index: gui.h
===================================================================
RCS file: /cvs/gnome/gtranslator/src/gui.h,v
retrieving revision 1.45
diff -u -r1.45 gui.h
--- gui.h	13 Jul 2003 15:44:15 -0000	1.45
+++ gui.h	11 Jan 2004 22:29:57 -0000
@@ -85,6 +85,7 @@
 void gtranslator_clipboard_copy(GtkWidget  *widget, gpointer useless);
 void gtranslator_clipboard_paste(GtkWidget  *widget, gpointer useless);
 void gtranslator_selection_clear(GtkWidget  *widget, gpointer useless);
+void gtranslator_selection_set(GtkTextView *text_view, gint start, gint end);
 
 /*
  * A status defining callback -- now generaly defined for instance.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]