[anjuta/gnome-3-2] search: 663385 - Replace all hangs when replace text contains search_text



commit 8ebb2e0d6861521af3d2536e35f4e08a047fd8cb
Author: Johannes Schmid <jhs gnome org>
Date:   Sun Nov 13 13:28:38 2011 +0100

    search: 663385 - Replace all hangs when replace text contains search_text
    
    Also clear the selection when there is no text in the search entry.

 plugins/document-manager/action-callbacks.c |    4 +-
 plugins/document-manager/search-box.c       |   44 ++++++++++++++++++++------
 plugins/document-manager/search-box.h       |    3 +-
 3 files changed, 38 insertions(+), 13 deletions(-)
---
diff --git a/plugins/document-manager/action-callbacks.c b/plugins/document-manager/action-callbacks.c
index da9f714..c7239f7 100644
--- a/plugins/document-manager/action-callbacks.c
+++ b/plugins/document-manager/action-callbacks.c
@@ -884,7 +884,7 @@ on_repeat_quicksearch (GtkAction *action, gpointer user_data)
 
 	if (!gtk_widget_get_visible (search_box))
 		gtk_widget_show (search_box);
-	search_box_incremental_search (SEARCH_BOX (search_box), TRUE);
+	search_box_incremental_search (SEARCH_BOX (search_box), TRUE, TRUE);
 }
 
 void
@@ -901,7 +901,7 @@ on_search_previous (GtkAction *action, gpointer user_data)
 
 	if (!gtk_widget_get_visible (search_box))
 		gtk_widget_show (search_box);
-	search_box_incremental_search (SEARCH_BOX (search_box), FALSE);
+	search_box_incremental_search (SEARCH_BOX (search_box), FALSE, TRUE);
 }
 
 void 
diff --git a/plugins/document-manager/search-box.c b/plugins/document-manager/search-box.c
index fd2ba11..0a935ad 100644
--- a/plugins/document-manager/search-box.c
+++ b/plugins/document-manager/search-box.c
@@ -282,7 +282,8 @@ incremental_regex_search (const gchar* search_entry, const gchar* editor_text, g
 }
 
 gboolean
-search_box_incremental_search (SearchBox* search_box, gboolean search_forward)
+search_box_incremental_search (SearchBox* search_box, gboolean search_forward,
+                               gboolean wrap)
 {
 	IAnjutaIterable* real_start;
 	IAnjutaEditorCell* search_start;
@@ -482,7 +483,7 @@ search_box_incremental_search (SearchBox* search_box, gboolean search_forward)
 	{
 		anjuta_status_pop (ANJUTA_STATUS (private->status));
 	}
-	else
+	else if (wrap)
 	{
 		/* Try to wrap if not found */
 		ianjuta_iterable_first (IANJUTA_ITERABLE (search_start), NULL);
@@ -666,7 +667,7 @@ search_box_search_highlight_all (SearchBox * search_box, gboolean search_forward
 	ianjuta_indicable_clear(IANJUTA_INDICABLE(private->current_editor), NULL);
 
 	/* Search through editor and highlight instances of search_entry */
-	while ((entry_found = search_box_incremental_search (search_box, search_forward)) == TRUE)
+	while ((entry_found = search_box_incremental_search (search_box, search_forward, TRUE)) == TRUE)
 	{
 		IAnjutaEditorCell * result_begin, * result_end;
 		selection = IANJUTA_EDITOR_SELECTION (private->current_editor);
@@ -705,13 +706,26 @@ search_box_search_highlight_all (SearchBox * search_box, gboolean search_forward
 }
 
 static void
-on_search_box_document_changed (GtkWidget * widget, SearchBox * search_box)
+on_search_box_entry_changed (GtkWidget * widget, SearchBox * search_box)
 {
 	SearchBoxPrivate* private = GET_PRIVATE(search_box);
 
 	if (!private->regex_mode)
 	{
-		search_box_incremental_search (search_box, TRUE);
+		GtkEntryBuffer* buffer = gtk_entry_get_buffer (GTK_ENTRY(widget));
+		if (gtk_entry_buffer_get_length (buffer))
+			search_box_incremental_search (search_box, TRUE, TRUE);
+		else
+		{
+			/* clear selection */
+			IAnjutaIterable* cursor = 
+				ianjuta_editor_get_position (IANJUTA_EDITOR (private->current_editor),
+				                             NULL);
+			ianjuta_editor_selection_set (IANJUTA_EDITOR_SELECTION (private->current_editor),
+			                              cursor,
+			                              cursor,
+			                              FALSE, NULL);
+		}
 	}
 }
 
@@ -726,7 +740,7 @@ search_box_forward_search (SearchBox * search_box, GtkWidget* widget)
 	}
 	else
 	{
-		search_box_incremental_search (search_box, TRUE);
+		search_box_incremental_search (search_box, TRUE, TRUE);
 	}
 
 }
@@ -742,7 +756,7 @@ on_search_box_backward_search (GtkWidget * widget, SearchBox * search_box)
 	}
 	else
 	{
-		search_box_incremental_search (search_box, FALSE);
+		search_box_incremental_search (search_box, FALSE, TRUE);
 	}
 }
 
@@ -883,18 +897,28 @@ on_replace_all_activated (GtkWidget* widget, SearchBox* search_box)
 {
 
 	SearchBoxPrivate* private = GET_PRIVATE(search_box);
-	gboolean entry_found;
+	IAnjutaIterable* cursor;
 
 	if (!private->current_editor)
 		return;
 
+	/* Cache current position and search from begin */
+	cursor = ianjuta_editor_get_position (IANJUTA_EDITOR (private->current_editor),
+	                                      NULL);
+	ianjuta_editor_goto_start (IANJUTA_EDITOR (private->current_editor), NULL);
+	
 	/* Replace all instances of search_entry with replace_entry text */
 	ianjuta_document_begin_undo_action (IANJUTA_DOCUMENT (private->current_editor), NULL);
-	while ((entry_found = search_box_incremental_search (search_box, TRUE)) == TRUE)
+	while (search_box_incremental_search (search_box, TRUE, FALSE))
 	{
 		search_box_replace (search_box, widget, FALSE);
 	}
 	ianjuta_document_end_undo_action (IANJUTA_DOCUMENT (private->current_editor), NULL);
+
+	/* Back to cached position */
+	ianjuta_editor_selection_set (IANJUTA_EDITOR_SELECTION (private->current_editor),
+	                              cursor, cursor, TRUE, NULL);
+	g_object_unref (cursor);
 }
 
 static void
@@ -915,7 +939,7 @@ search_box_init (SearchBox *object)
 					  G_CALLBACK (on_entry_key_pressed),
 					  object);
 	g_signal_connect (G_OBJECT (private->search_entry), "changed",
-					  G_CALLBACK (on_search_box_document_changed),
+					  G_CALLBACK (on_search_box_entry_changed),
 					  object);
 	g_signal_connect (G_OBJECT (private->search_entry), "focus-out-event",
 					  G_CALLBACK (on_search_focus_out),
diff --git a/plugins/document-manager/search-box.h b/plugins/document-manager/search-box.h
index de31095..430873a 100644
--- a/plugins/document-manager/search-box.h
+++ b/plugins/document-manager/search-box.h
@@ -58,7 +58,8 @@ GtkWidget* search_box_new (AnjutaDocman* docman);
 void search_box_fill_search_focus (SearchBox* search_box, gboolean on_replace);
 void search_box_grab_line_focus (SearchBox* search_box);
 void search_box_set_replace (SearchBox* object, gboolean replace);
-gboolean search_box_incremental_search (SearchBox* search_box, gboolean search_forward);
+gboolean search_box_incremental_search (SearchBox* search_box, gboolean search_forward,
+                                        gboolean wrap);
 
 void search_box_clear_highlight (SearchBox * search_box);
 void search_box_toggle_highlight (SearchBox * search_box, gboolean status);



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