[gtksourceview/wip/search] Add gtk_source_buffer_search_replace_all()



commit 5f355066a91960bb0e577becb239c2e8e11653ab
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Jul 1 19:18:59 2013 +0200

    Add gtk_source_buffer_search_replace_all()

 gtksourceview/gtksourcebuffer.c |   14 ++++++++++++++
 gtksourceview/gtksourcebuffer.h |    4 ++++
 gtksourceview/gtksourcesearch.c |   28 ++++++++++++++++++++++++++++
 gtksourceview/gtksourcesearch.h |    5 +++++
 tests/test-search-ui.c          |    4 +++-
 5 files changed, 54 insertions(+), 1 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index 1563065..b01833a 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -2913,6 +2913,7 @@ gtk_source_buffer_search_replace (GtkSourceBuffer   *buffer,
                                  gint               replace_length)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
+       g_return_val_if_fail (replace != NULL, FALSE);
 
        return _gtk_source_search_replace (buffer->priv->search,
                                           match_start,
@@ -2920,3 +2921,16 @@ gtk_source_buffer_search_replace (GtkSourceBuffer   *buffer,
                                           replace,
                                           replace_length);
 }
+
+void
+gtk_source_buffer_search_replace_all (GtkSourceBuffer *buffer,
+                                     const gchar     *replace,
+                                     gint             replace_length)
+{
+       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
+       g_return_if_fail (replace != NULL);
+
+       _gtk_source_search_replace_all (buffer->priv->search,
+                                       replace,
+                                       replace_length);
+}
diff --git a/gtksourceview/gtksourcebuffer.h b/gtksourceview/gtksourcebuffer.h
index df0e7d2..ea25786 100644
--- a/gtksourceview/gtksourcebuffer.h
+++ b/gtksourceview/gtksourcebuffer.h
@@ -238,6 +238,10 @@ gboolean            gtk_source_buffer_search_replace       (GtkSourceBuffer        
*buffer,
                                                                 const gchar            *replace,
                                                                 gint                    replace_length);
 
+void                    gtk_source_buffer_search_replace_all   (GtkSourceBuffer        *buffer,
+                                                                const gchar            *replace,
+                                                                gint                    replace_length);
+
 /* private */
 void                    _gtk_source_buffer_update_highlight    (GtkSourceBuffer        *buffer,
                                                                 const GtkTextIter      *start,
diff --git a/gtksourceview/gtksourcesearch.c b/gtksourceview/gtksourcesearch.c
index d4c1393..3c03d0c 100644
--- a/gtksourceview/gtksourcesearch.c
+++ b/gtksourceview/gtksourcesearch.c
@@ -1894,6 +1894,7 @@ _gtk_source_search_replace (GtkSourceSearch   *search,
        GtkTextIter check_match_end;
 
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH (search), FALSE);
+       g_return_val_if_fail (replace != NULL, FALSE);
 
        if (match_start != NULL)
        {
@@ -1938,3 +1939,30 @@ _gtk_source_search_replace (GtkSourceSearch   *search,
 
        return TRUE;
 }
+
+void
+_gtk_source_search_replace_all (GtkSourceSearch *search,
+                               const gchar     *replace,
+                               gint             replace_length)
+{
+       GtkTextIter iter;
+       GtkTextIter match_start;
+       GtkTextIter match_end;
+
+       g_return_if_fail (GTK_SOURCE_IS_SEARCH (search));
+       g_return_if_fail (replace != NULL);
+
+       gtk_text_buffer_get_start_iter (search->priv->buffer, &iter);
+
+       gtk_text_buffer_begin_user_action (search->priv->buffer);
+
+       while (smart_forward_search (search, &iter, &match_start, &match_end))
+       {
+               gtk_text_buffer_delete (search->priv->buffer, &match_start, &match_end);
+               gtk_text_buffer_insert (search->priv->buffer, &match_end, replace, replace_length);
+
+               iter = match_end;
+       }
+
+       gtk_text_buffer_end_user_action (search->priv->buffer);
+}
diff --git a/gtksourceview/gtksourcesearch.h b/gtksourceview/gtksourcesearch.h
index 0ccfe05..181b3d6 100644
--- a/gtksourceview/gtksourcesearch.h
+++ b/gtksourceview/gtksourcesearch.h
@@ -141,6 +141,11 @@ gboolean           _gtk_source_search_replace                      (GtkSourceSearch      
  *search,
                                                                         const gchar            *replace,
                                                                         gint                    
replace_length);
 
+G_GNUC_INTERNAL
+void                   _gtk_source_search_replace_all                  (GtkSourceSearch        *search,
+                                                                        const gchar            *replace,
+                                                                        gint                    
replace_length);
+
 G_END_DECLS
 
 #endif /* __GTK_SOURCE_SEARCH_H__ */
diff --git a/tests/test-search-ui.c b/tests/test-search-ui.c
index f3a5a44..9fa028e 100644
--- a/tests/test-search-ui.c
+++ b/tests/test-search-ui.c
@@ -176,7 +176,9 @@ static void
 on_replace_all_cb (GtkButton      *button,
                   ReplaceWidgets *widgets)
 {
-       g_message ("Not implemented yet.");
+       gtk_source_buffer_search_replace_all (widgets->buffer,
+                                             gtk_entry_get_text (widgets->replace_entry),
+                                             -1);
 }
 
 static void


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