After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 303960 - Search & Replace only selected text
Search & Replace only selected text
Status: RESOLVED DUPLICATE of bug 150010
Product: gedit
Classification: Applications
Component: general
2.10.x
Other All
: High critical
: ---
Assigned To: Gedit maintainers
gedit QA volunteers
Depends on:
Blocks:
 
 
Reported: 2005-05-12 20:18 UTC by Bhuvaneswari
Modified: 2005-07-25 12:51 UTC
See Also:
GNOME target: ---
GNOME version: 2.9/2.10



Description Bhuvaneswari 2005-05-12 20:18:27 UTC
Steps to reproduce:
1. As soon as, the find button is pressed, the application get crashed.
2. 
3. 


Stack trace:
Index: gedit-dialog-replace.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/dialogs/gedit-dialog-replace.c,v
retrieving revision 1.37
diff -u -p -r1.37 gedit-dialog-replace.c
--- gedit-dialog-replace.c	25 Jan 2005 10:26:25 -0000	1.37
+++ gedit-dialog-replace.c	12 May 2005 17:37:31 -0000
@@ -65,6 +65,7 @@ struct _GeditDialogReplace {
 	GtkWidget *match_case_checkbutton;
 	GtkWidget *entire_word_checkbutton;
 	GtkWidget *wrap_around_checkbutton;
+	GtkWidget *current_selection_only_checkbutton;
 	GtkWidget *search_backwards_checkbutton;
 };
 
@@ -77,6 +78,7 @@ struct _GeditDialogFind {
 	GtkWidget *match_case_checkbutton;
 	GtkWidget *entire_word_checkbutton;
 	GtkWidget *wrap_around_checkbutton;
+	GtkWidget *current_selection_only_checkbutton;
 	GtkWidget *search_backwards_checkbutton;
 };
 
@@ -99,6 +101,7 @@ static GQuark was_wrap_around_id = 0;
 static GQuark was_entire_word_id = 0;
 static GQuark was_case_sensitive_id = 0;
 static GQuark was_search_backwards_id = 0;
+static GQuark was_current_selection_only_id = 0;
 
 GQuark 
 gedit_was_wrap_around_quark (void)
@@ -296,6 +299,7 @@ dialog_replace_get_dialog (void)
 	replace_with_label         = glade_xml_get_widget (gui, "replace_with_label");
 	dialog->match_case_checkbutton = glade_xml_get_widget (gui,
"match_case_checkbutton");
 	dialog->wrap_around_checkbutton =  glade_xml_get_widget (gui,
"wrap_around_checkbutton");
+	dialog->current_selection_only_checkbutton = glade_xml_get_widget (gui,
"current_selection_only_checkbutton");
 	dialog->entire_word_checkbutton = glade_xml_get_widget (gui,
"entire_word_checkbutton");
 	dialog->search_backwards_checkbutton = glade_xml_get_widget (gui,
"search_backwards_checkbutton");
 
@@ -308,6 +312,7 @@ dialog_replace_get_dialog (void)
 	    !dialog->match_case_checkbutton 	||
 	    !dialog->entire_word_checkbutton 	||
 	    !dialog->wrap_around_checkbutton 	||
+	    !dialog->current_selection_only_checkbutton||
 	    !dialog->search_backwards_checkbutton)
 	{
 		gedit_warning (window,
@@ -423,6 +428,7 @@ dialog_find_get_dialog (void)
 	
 	dialog->match_case_checkbutton = glade_xml_get_widget (gui,
"match_case_checkbutton");
 	dialog->wrap_around_checkbutton =  glade_xml_get_widget (gui,
"wrap_around_checkbutton");
+	dialog->current_selection_only_checkbutton = glade_xml_get_widget (gui,
"current_selection_only_checkbutton");
 	dialog->entire_word_checkbutton = glade_xml_get_widget (gui,
"entire_word_checkbutton");
 	dialog->search_backwards_checkbutton = glade_xml_get_widget (gui,
"search_backwards_checkbutton");
 
@@ -437,6 +443,7 @@ dialog_find_get_dialog (void)
 	    !dialog->match_case_checkbutton 	||
 	    !dialog->entire_word_checkbutton 	||
 	    !dialog->wrap_around_checkbutton	||
+	    !dialog->current_selection_only_checkbutton||
 	    !dialog->search_backwards_checkbutton)
 	{
 		gedit_warning (window,
@@ -592,6 +599,7 @@ gedit_dialog_find (void)
 	gboolean was_entire_word;
 	gboolean was_case_sensitive;
 	gboolean was_search_backwards;
+	gboolean was_current_selection_only;
 	gpointer data;
 	
 	gedit_debug (DEBUG_SEARCH, "");
@@ -641,6 +649,9 @@ gedit_dialog_find (void)
 	if (!was_case_sensitive_id)
 		was_case_sensitive_id = g_quark_from_static_string ("GeditWasCaseSensitive");
 
+	if (!was_current_selection_only_id)
+		was_current_selection_only_id = g_quark_from_static_string
("GeditWasSearchSelected");
+
 	data = g_object_get_qdata (G_OBJECT (doc), was_wrap_around_id);
 	if (data == NULL)
 		was_wrap_around = TRUE;
@@ -665,15 +676,25 @@ gedit_dialog_find (void)
 	else
 		was_case_sensitive = GPOINTER_TO_BOOLEAN (data);
 	
+	data = g_object_get_qdata (G_OBJECT (doc), was_current_selection_only_id);
+	if (data == NULL)
+		was_current_selection_only = FALSE;
+	else
+		was_current_selection_only = GPOINTER_TO_BOOLEAN (data);
+
+
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->match_case_checkbutton), 
 				      was_case_sensitive);
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->entire_word_checkbutton),
 				      was_entire_word);
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->wrap_around_checkbutton),
 				      was_wrap_around);
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
(dialog->search_backwards_checkbutton),
-				      was_search_backwards);
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
(dialog->current_selection_only_checkbutton), selection_exists);
 
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
(dialog->search_backwards_checkbutton),
+				      was_search_backwards);      
+				      
+				      
 	gtk_widget_grab_focus (dialog->search_entry);
 	
 	gtk_widget_show (dialog->dialog);
@@ -693,6 +714,7 @@ gedit_dialog_replace (void)
 	gboolean was_entire_word;
 	gboolean was_case_sensitive;
 	gboolean was_search_backwards;
+	gboolean was_current_selection_only;
 	gpointer data;
 
 	gedit_debug (DEBUG_SEARCH, "");
@@ -753,6 +775,9 @@ gedit_dialog_replace (void)
 	if (!was_case_sensitive_id)
 		was_case_sensitive_id = g_quark_from_static_string ("GeditWasCaseSensitive");
 
+	if (!was_current_selection_only_id)
+		was_current_selection_only_id = g_quark_from_static_string
("GeditWasSearchSelected");
+
 	data = g_object_get_qdata (G_OBJECT (doc), was_search_backwards_id);
 	if (data == NULL)
 		was_search_backwards = FALSE;
@@ -776,13 +801,22 @@ gedit_dialog_replace (void)
 		was_case_sensitive = FALSE;
 	else
 		was_case_sensitive = GPOINTER_TO_BOOLEAN (data);
-	
+
+	data = g_object_get_qdata (G_OBJECT (doc), was_current_selection_only_id);
+	if (data == NULL)
+		was_current_selection_only = FALSE;
+	else
+		was_current_selection_only = GPOINTER_TO_BOOLEAN (data);
+		
+
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->match_case_checkbutton), 
 				      was_case_sensitive);
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->entire_word_checkbutton),
 				      was_entire_word);
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->wrap_around_checkbutton),
 				      was_wrap_around);
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
(dialog->current_selection_only_checkbutton),
+				      was_current_selection_only);
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
(dialog->search_backwards_checkbutton),
 				      was_search_backwards);
 
@@ -804,6 +838,7 @@ find_dlg_find_button_pressed (GeditDialo
 	gboolean entire_word;
 	gboolean wrap_around;
 	gboolean search_backwards;
+	gboolean selection_exists;
 	gint flags = 0;
 
 	gedit_debug (DEBUG_SEARCH, "");
@@ -832,11 +867,13 @@ find_dlg_find_button_pressed (GeditDialo
 	case_sensitive = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->match_case_checkbutton));
 	entire_word = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->entire_word_checkbutton));
 	wrap_around = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->wrap_around_checkbutton));
+        selection_exists = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->current_selection_only_checkbutton));
 	search_backwards = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->search_backwards_checkbutton));
 
 	/* setup quarks for next invocation */
 	g_object_set_qdata (G_OBJECT (doc), was_search_backwards_id,
GBOOLEAN_TO_POINTER (search_backwards));
 	g_object_set_qdata (G_OBJECT (doc), was_wrap_around_id, GBOOLEAN_TO_POINTER
(wrap_around));
+	
 	g_object_set_qdata (G_OBJECT (doc), was_entire_word_id, GBOOLEAN_TO_POINTER
(entire_word));
 	g_object_set_qdata (G_OBJECT (doc), was_case_sensitive_id, GBOOLEAN_TO_POINTER
(case_sensitive));
 
@@ -845,6 +882,7 @@ find_dlg_find_button_pressed (GeditDialo
 	GEDIT_SEARCH_SET_CASE_SENSITIVE (flags, case_sensitive);
 	GEDIT_SEARCH_SET_BACKWARDS (flags, search_backwards);
 	GEDIT_SEARCH_SET_ENTIRE_WORD (flags, entire_word);
+	GEDIT_SEARCH_SET_IN_SELECTION (flags, selection_exists);   /* Bhuvana */
 
 	/* run search */
 	found = gedit_document_find (doc, search_string, flags);
@@ -879,6 +917,7 @@ replace_dlg_find_button_pressed (GeditDi
 	gboolean entire_word;
 	gboolean wrap_around;
 	gboolean search_backwards;
+	gboolean current_selection_only;
 	gint flags = 0;
 
 	gedit_debug (DEBUG_SEARCH, "");
@@ -907,11 +946,13 @@ replace_dlg_find_button_pressed (GeditDi
 	case_sensitive = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->match_case_checkbutton));
 	entire_word = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->entire_word_checkbutton));
 	wrap_around = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->wrap_around_checkbutton));
+        current_selection_only = gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON (dialog->current_selection_only_checkbutton));
 	search_backwards = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->search_backwards_checkbutton));
 
 	/* setup quarks for next invocation */
 	g_object_set_qdata (G_OBJECT (doc), was_search_backwards_id,
GBOOLEAN_TO_POINTER (search_backwards));
 	g_object_set_qdata (G_OBJECT (doc), was_wrap_around_id, GBOOLEAN_TO_POINTER
(wrap_around));
+	g_object_set_qdata (G_OBJECT (doc), was_current_selection_only_id,
GBOOLEAN_TO_POINTER (current_selection_only));
 	g_object_set_qdata (G_OBJECT (doc), was_entire_word_id, GBOOLEAN_TO_POINTER
(entire_word));
 	g_object_set_qdata (G_OBJECT (doc), was_case_sensitive_id, GBOOLEAN_TO_POINTER
(case_sensitive));
 
@@ -958,6 +999,7 @@ replace_dlg_replace_button_pressed (Gedi
 	gboolean entire_word;
 	gboolean wrap_around;
 	gboolean search_backwards;
+	gboolean current_selection_only;
 	gint flags = 0;
 
 	gedit_debug (DEBUG_SEARCH, "");
@@ -1003,6 +1045,7 @@ replace_dlg_replace_button_pressed (Gedi
 	case_sensitive = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->match_case_checkbutton));
 	entire_word = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->entire_word_checkbutton));
 	wrap_around = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->wrap_around_checkbutton));
+	current_selection_only = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->current_selection_only_checkbutton));
 	search_backwards = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->search_backwards_checkbutton));
 
 	converted_search_string = gedit_utils_convert_search_text (search_string);
@@ -1086,6 +1129,7 @@ replace_dlg_replace_all_button_pressed (
 	
 	gboolean case_sensitive;
 	gboolean entire_word;
+	gboolean current_selection_only;
 	gint flags = 0;
 	
  	gedit_debug (DEBUG_SEARCH, "");
@@ -1121,6 +1165,7 @@ replace_dlg_replace_all_button_pressed (
 	/* retrieve search settings from the dialog */
 	case_sensitive = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->match_case_checkbutton));
 	entire_word = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->entire_word_checkbutton));
+	current_selection_only = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(dialog->current_selection_only_checkbutton));
 
 	/* setup search parameter bitfield */
 	GEDIT_SEARCH_SET_CASE_SENSITIVE (flags, case_sensitive);
@@ -1129,7 +1174,9 @@ replace_dlg_replace_all_button_pressed (
 	replaced_items = gedit_document_replace_all (doc, search_string,
replace_string, flags);
 
 	update_menu_items_sensitivity ();
-
+	
+	//printf("Bhuvana");
+	
 	if (replaced_items <= 0)
 	{
 		message_dlg = gtk_message_dialog_new (
Index: gedit-document.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-document.c,v
retrieving revision 1.111
diff -u -p -r1.111 gedit-document.c
--- gedit-document.c	27 Feb 2005 16:12:39 -0000	1.111
+++ gedit-document.c	12 May 2005 12:42:16 -0000
@@ -108,6 +108,11 @@ struct _GeditDocumentPrivate
 	const GeditEncoding *temp_encoding;
 	gchar		    *temp_uri;
 	gulong		     temp_size;
+
+
+	/* Info needed for implementing search within selection ----------Bhuvana*/
+	GtkTextIter         start_sel_bound;
+	GtkTextIter         end_sel_bound;
 };
 
 enum {
@@ -2154,6 +2159,26 @@ gedit_document_set_max_undo_levels (Gedi
 					       max_undo_levels);
 }
 
+
+/*Added by Bhuvana inorder to get the find-replace options effectively   */
+gboolean
+gedit_document_is_text_selected (const GeditDocument *doc)
+{
+	GtkTextIter start;
+	GtkTextIter end;
+    
+	gedit_debug (DEBUG_COMMANDS, "");
+    
+	g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+    
+	if(!gtk_text_buffer_get_selection_bounds(GTK_TEXT_BUFFER (doc), &start, &end))
+	    	return FALSE;
+	else
+        	return TRUE;
+}
+
+
+
 gboolean
 gedit_document_can_undo	(const GeditDocument *doc)
 {
@@ -2358,7 +2383,15 @@ gedit_document_find (GeditDocument* doc,
 						      &iter,
 						      &sel_bound);
 
-		if (!GEDIT_SEARCH_IS_BACKWARDS (flags))
+/*added by Bhuvana*/
+		if (GEDIT_SEARCH_IS_IN_SELECTION (flags)) 
+		{
+			if (!gtk_text_iter_in_range (&iter, &doc->priv->start_sel_bound,
+						     &doc->priv->end_sel_bound))
+				iter = doc->priv->start_sel_bound;
+		} 
+		else if (!GEDIT_SEARCH_IS_BACKWARDS (flags))/* Bhuvana-ends*/
+
 			gtk_text_iter_order (&sel_bound, &iter);		
 		else
 			gtk_text_iter_order (&iter, &sel_bound);		
@@ -2466,6 +2499,10 @@ gedit_document_find_again (GeditDocument
 	g_return_val_if_fail (doc->priv != NULL, FALSE);
 
 	last_searched_text = gedit_document_get_last_searched_text (doc);
+
+//Added by Bhuvana 
+//gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (last_searched_text));
+
 	
 	if (last_searched_text == NULL)
 		return FALSE;
@@ -2564,13 +2601,13 @@ gedit_document_replace_all (GeditDocumen
 	gedit_document_begin_user_action (doc);
 
 	GEDIT_SEARCH_SET_BACKWARDS (flags, FALSE);
-	GEDIT_SEARCH_SET_FROM_CURSOR (flags, FALSE);
+	GEDIT_SEARCH_SET_FROM_CURSOR (flags, FALSE); 
 
 	while (gedit_document_find (doc, find, flags)) 
 	{
 		gedit_document_replace_selected_text (doc, replace);
 		
-		GEDIT_SEARCH_SET_FROM_CURSOR (flags, TRUE);
+		GEDIT_SEARCH_SET_FROM_CURSOR (flags, TRUE); // Bhuvana - 
 		
 		++cont;
 	}
@@ -2735,4 +2772,16 @@ gedit_document_set_auto_save_interval (G
 		 		 		 (GSourceFunc)gedit_document_auto_save,	
 				  		 doc);		
 	}
+}
+
+/*Bhuvana*/
+void
+gedit_document_set_selection_bounds (GeditDocument* doc)
+{
+	if (!doc)
+		return;
+
+	gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),			
+					      &doc->priv->start_sel_bound,
+					      &doc->priv->end_sel_bound);	
 }
Index: gedit-document.h
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-document.h,v
retrieving revision 1.41
diff -u -p -r1.41 gedit-document.h
--- gedit-document.h	13 Dec 2004 20:10:53 -0000	1.41
+++ gedit-document.h	12 May 2005 17:32:23 -0000
@@ -51,6 +51,7 @@
 #define GEDIT_SEARCH_BACKWARDS     	(1 << 1 )
 #define GEDIT_SEARCH_CASE_SENSITIVE	(1 << 2 )
 #define GEDIT_SEARCH_FROM_CURSOR   	(1 << 3 )
+#define GEDIT_SEARCH_IN_SELECTION       (1 << 4 ) /*Bhuvana*/
 
 #define GEDIT_SEARCH_IS_ENTIRE_WORD(sflags) ((sflags &
GEDIT_SEARCH_ENTIRE_WORD) != 0)
 #define GEDIT_SEARCH_SET_ENTIRE_WORD(sflags,state) ((state == TRUE) ? \
@@ -68,6 +69,10 @@
 #define GEDIT_SEARCH_SET_FROM_CURSOR(sflags,state) ((state == TRUE) ? \
 (sflags |= GEDIT_SEARCH_FROM_CURSOR) : (sflags &= ~GEDIT_SEARCH_FROM_CURSOR))
 
+/*Bhuvana*/
+#define GEDIT_SEARCH_IS_IN_SELECTION(sflags) ((sflags &
GEDIT_SEARCH_IN_SELECTION) != 0)
+#define GEDIT_SEARCH_SET_IN_SELECTION(sflags,state) ((state == TRUE) ? \
+(sflags |= GEDIT_SEARCH_IN_SELECTION) : (sflags &= ~GEDIT_SEARCH_IN_SELECTION))
 
 typedef struct _GeditDocument           GeditDocument;
 typedef struct _GeditDocumentClass 	GeditDocumentClass;
@@ -210,6 +215,9 @@ void		gedit_document_set_auto_save_inter
 						(GeditDocument *doc, 
 						 gint           interval);
 
+void		gedit_document_set_selection_bounds 
+						(GeditDocument *doc); 
+
 
 #endif /* __GEDIT_DOCUMENT_H__ */
 


Other information:
This has be done only for Find dialogs, this could be implemented in the Repalce
dialogs, if this works well
Comment 1 Paolo Maggi 2005-07-25 12:51:24 UTC

*** This bug has been marked as a duplicate of 150010 ***