[gtksourceview/wip/search-has-wrapped-around: 2/2] SearchContext: add backward2() and deprecate backward()



commit a9971a2aed49481632a452492b545d3b947fc420
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jun 11 13:53:56 2016 +0200

    SearchContext: add backward2() and deprecate backward()
    
    https://bugzilla.gnome.org/show_bug.cgi?id=724420

 docs/reference/gtksourceview-3.0-sections.txt |    1 +
 gtksourceview/gtksourcesearchcontext.c        |   51 +++++++++++++++++++++++++
 gtksourceview/gtksourcesearchcontext.h        |    9 ++++-
 testsuite/test-search-context.c               |   13 +++---
 4 files changed, 67 insertions(+), 7 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index 2738641..e406972 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -665,6 +665,7 @@ gtk_source_search_context_forward2
 gtk_source_search_context_forward_async
 gtk_source_search_context_forward_finish
 gtk_source_search_context_backward
+gtk_source_search_context_backward2
 gtk_source_search_context_backward_async
 gtk_source_search_context_backward_finish
 gtk_source_search_context_replace
diff --git a/gtksourceview/gtksourcesearchcontext.c b/gtksourceview/gtksourcesearchcontext.c
index 9ef8003..d86b3b4 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -3373,6 +3373,7 @@ gtk_source_search_context_forward_finish (GtkSourceSearchContext  *search,
  *
  * Returns: whether a match was found.
  * Since: 3.10
+ * Deprecated: 3.22: Use gtk_source_search_context_backward2() instead.
  */
 gboolean
 gtk_source_search_context_backward (GtkSourceSearchContext *search,
@@ -3380,6 +3381,46 @@ gtk_source_search_context_backward (GtkSourceSearchContext *search,
                                    GtkTextIter            *match_start,
                                    GtkTextIter            *match_end)
 {
+       return gtk_source_search_context_backward2 (search,
+                                                   iter,
+                                                   match_start,
+                                                   match_end,
+                                                   NULL);
+}
+
+/**
+ * gtk_source_search_context_backward2:
+ * @search: a #GtkSourceSearchContext.
+ * @iter: start of search.
+ * @match_start: (out) (optional): return location for start of match, or %NULL.
+ * @match_end: (out) (optional): return location for end of match, or %NULL.
+ * @has_wrapped_around: (out) (optional): return location to know whether the
+ *   search has wrapped around, or %NULL.
+ *
+ * Synchronous backward search. It is recommended to use the asynchronous
+ * functions instead, to not block the user interface. However, if you are sure
+ * that the @buffer is small, this function is more convenient to use.
+ *
+ * The difference with gtk_source_search_context_backward() is that the
+ * @has_wrapped_around out parameter has been added for convenience.
+ *
+ * If the #GtkSourceSearchSettings:wrap-around property is %FALSE, this function
+ * doesn't try to wrap around.
+ *
+ * The @has_wrapped_around out parameter is set independently of whether a match
+ * is found. So if this function returns %FALSE, @has_wrapped_around will have
+ * the same value as the #GtkSourceSearchSettings:wrap-around property.
+ *
+ * Returns: whether a match was found.
+ * Since: 3.22
+ */
+gboolean
+gtk_source_search_context_backward2 (GtkSourceSearchContext *search,
+                                    const GtkTextIter      *iter,
+                                    GtkTextIter            *match_start,
+                                    GtkTextIter            *match_end,
+                                    gboolean               *has_wrapped_around)
+{
        GtkTextIter m_start;
        GtkTextIter m_end;
        gboolean found;
@@ -3387,6 +3428,11 @@ gtk_source_search_context_backward (GtkSourceSearchContext *search,
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), FALSE);
        g_return_val_if_fail (iter != NULL, FALSE);
 
+       if (has_wrapped_around != NULL)
+       {
+               *has_wrapped_around = FALSE;
+       }
+
        if (search->priv->buffer == NULL)
        {
                return FALSE;
@@ -3401,6 +3447,11 @@ gtk_source_search_context_backward (GtkSourceSearchContext *search,
                gtk_text_buffer_get_end_iter (search->priv->buffer, &end_iter);
 
                found = smart_backward_search (search, &end_iter, &m_start, &m_end);
+
+               if (has_wrapped_around != NULL)
+               {
+                       *has_wrapped_around = TRUE;
+               }
        }
 
        if (found && match_start != NULL)
diff --git a/gtksourceview/gtksourcesearchcontext.h b/gtksourceview/gtksourcesearchcontext.h
index 38a959f..582a15d 100644
--- a/gtksourceview/gtksourcesearchcontext.h
+++ b/gtksourceview/gtksourcesearchcontext.h
@@ -120,12 +120,19 @@ gboolean           gtk_source_search_context_forward_finish               
(GtkSourceSearchContext  *s
                                                                                 GtkTextIter             
*match_end,
                                                                                 GError                 
**error);
 
-GTK_SOURCE_AVAILABLE_IN_3_10
+GTK_SOURCE_DEPRECATED_IN_3_22_FOR (gtk_source_search_context_backward2)
 gboolean                gtk_source_search_context_backward                     (GtkSourceSearchContext  
*search,
                                                                                 const GtkTextIter       
*iter,
                                                                                 GtkTextIter             
*match_start,
                                                                                 GtkTextIter             
*match_end);
 
+GTK_SOURCE_AVAILABLE_IN_3_22
+gboolean                gtk_source_search_context_backward2                    (GtkSourceSearchContext 
*search,
+                                                                                const GtkTextIter      *iter,
+                                                                                GtkTextIter            
*match_start,
+                                                                                GtkTextIter            
*match_end,
+                                                                                gboolean               
*has_wrapped_around);
+
 GTK_SOURCE_AVAILABLE_IN_3_10
 void                    gtk_source_search_context_backward_async               (GtkSourceSearchContext  
*search,
                                                                                 const GtkTextIter       
*iter,
diff --git a/testsuite/test-search-context.c b/testsuite/test-search-context.c
index 14cff00..b94e3f4 100644
--- a/testsuite/test-search-context.c
+++ b/testsuite/test-search-context.c
@@ -423,10 +423,11 @@ check_search_results (GtkSourceBuffer        *source_buffer,
                }
                else
                {
-                       found = gtk_source_search_context_backward (context,
-                                                                   &iter,
-                                                                   &match_start,
-                                                                   &match_end);
+                       found = gtk_source_search_context_backward2 (context,
+                                                                    &iter,
+                                                                    &match_start,
+                                                                    &match_end,
+                                                                    NULL);
                }
 
                g_assert (found == results[i].found);
@@ -1104,7 +1105,7 @@ test_regex_look_behind (void)
 
        /* Backward search */
        gtk_text_buffer_get_end_iter (text_buffer, &iter);
-       found = gtk_source_search_context_backward (context, &iter, &match_start, &match_end);
+       found = gtk_source_search_context_backward2 (context, &iter, &match_start, &match_end, NULL);
        g_assert (found);
 
        offset = gtk_text_iter_get_offset (&match_start);
@@ -1179,7 +1180,7 @@ test_regex_look_ahead (void)
 
        /* Backward search */
        gtk_text_buffer_get_end_iter (text_buffer, &iter);
-       found = gtk_source_search_context_backward (context, &iter, &match_start, &match_end);
+       found = gtk_source_search_context_backward2 (context, &iter, &match_start, &match_end, NULL);
        g_assert (found);
 
        offset = gtk_text_iter_get_offset (&match_start);


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