[gtksourceview/wip/search-has-wrapped-around: 1/2] SearchContext: add forward2() and deprecate forward()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/search-has-wrapped-around: 1/2] SearchContext: add forward2() and deprecate forward()
- Date: Sat, 11 Jun 2016 11:58:20 +0000 (UTC)
commit 13ffca52123451590b0789b5e5bc1142af2b17d8
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Jun 11 13:00:10 2016 +0200
SearchContext: add forward2() and deprecate forward()
To add a has_wrapped_around out param.
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 ++++-
tests/test-search-performances.c | 14 +++---
testsuite/test-search-context.c | 17 ++++----
5 files changed, 76 insertions(+), 16 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index 6b8c4fa..2738641 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -661,6 +661,7 @@ gtk_source_search_context_set_match_style
gtk_source_search_context_get_occurrences_count
gtk_source_search_context_get_occurrence_position
gtk_source_search_context_forward
+gtk_source_search_context_forward2
gtk_source_search_context_forward_async
gtk_source_search_context_forward_finish
gtk_source_search_context_backward
diff --git a/gtksourceview/gtksourcesearchcontext.c b/gtksourceview/gtksourcesearchcontext.c
index d1f947d..9ef8003 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -3170,6 +3170,7 @@ gtk_source_search_context_get_occurrence_position (GtkSourceSearchContext *searc
*
* Returns: whether a match was found.
* Since: 3.10
+ * Deprecated: 3.22: Use gtk_source_search_context_forward2() instead.
*/
gboolean
gtk_source_search_context_forward (GtkSourceSearchContext *search,
@@ -3177,6 +3178,46 @@ gtk_source_search_context_forward (GtkSourceSearchContext *search,
GtkTextIter *match_start,
GtkTextIter *match_end)
{
+ return gtk_source_search_context_forward2 (search,
+ iter,
+ match_start,
+ match_end,
+ NULL);
+}
+
+/**
+ * gtk_source_search_context_forward2:
+ * @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 forward 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_forward() 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_forward2 (GtkSourceSearchContext *search,
+ const GtkTextIter *iter,
+ GtkTextIter *match_start,
+ GtkTextIter *match_end,
+ gboolean *has_wrapped_around)
+{
GtkTextIter m_start;
GtkTextIter m_end;
gboolean found;
@@ -3184,6 +3225,11 @@ gtk_source_search_context_forward (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;
@@ -3197,6 +3243,11 @@ gtk_source_search_context_forward (GtkSourceSearchContext *search,
gtk_text_buffer_get_start_iter (search->priv->buffer, &start_iter);
found = smart_forward_search (search, &start_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 eb427d1..38a959f 100644
--- a/gtksourceview/gtksourcesearchcontext.h
+++ b/gtksourceview/gtksourcesearchcontext.h
@@ -93,12 +93,19 @@ gint gtk_source_search_context_get_occurrence_position
(GtkSourceSearchContex
const GtkTextIter
*match_start,
const GtkTextIter
*match_end);
-GTK_SOURCE_AVAILABLE_IN_3_10
+GTK_SOURCE_DEPRECATED_IN_3_22_FOR (gtk_source_search_context_forward2)
gboolean gtk_source_search_context_forward (GtkSourceSearchContext
*search,
const GtkTextIter
*iter,
GtkTextIter
*match_start,
GtkTextIter
*match_end);
+GTK_SOURCE_AVAILABLE_IN_3_22
+gboolean gtk_source_search_context_forward2 (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_forward_async (GtkSourceSearchContext
*search,
const GtkTextIter
*iter,
diff --git a/tests/test-search-performances.c b/tests/test-search-performances.c
index c4a2588..136e0ed 100644
--- a/tests/test-search-performances.c
+++ b/tests/test-search-performances.c
@@ -140,7 +140,7 @@ main (int argc, char *argv[])
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter);
- while (gtk_source_search_context_forward (search_context, &iter, NULL, &match_end))
+ while (gtk_source_search_context_forward2 (search_context, &iter, NULL, &match_end, NULL))
{
iter = match_end;
}
@@ -159,7 +159,7 @@ main (int argc, char *argv[])
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter);
- while (gtk_source_search_context_forward (search_context, &iter, NULL, &match_end))
+ while (gtk_source_search_context_forward2 (search_context, &iter, NULL, &match_end, NULL))
{
iter = match_end;
}
@@ -178,7 +178,7 @@ main (int argc, char *argv[])
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter);
- while (gtk_source_search_context_forward (search_context, &iter, NULL, &match_end))
+ while (gtk_source_search_context_forward2 (search_context, &iter, NULL, &match_end, NULL))
{
iter = match_end;
}
@@ -195,7 +195,7 @@ main (int argc, char *argv[])
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter);
- while (gtk_source_search_context_forward (search_context, &iter, NULL, &match_end))
+ while (gtk_source_search_context_forward2 (search_context, &iter, NULL, &match_end, NULL))
{
iter = match_end;
}
@@ -212,7 +212,7 @@ main (int argc, char *argv[])
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter);
- while (gtk_source_search_context_forward (search_context, &iter, NULL, &match_end))
+ while (gtk_source_search_context_forward2 (search_context, &iter, NULL, &match_end, NULL))
{
iter = match_end;
}
@@ -232,7 +232,7 @@ main (int argc, char *argv[])
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter);
- while (gtk_source_search_context_forward (search_context, &iter, NULL, &match_end))
+ while (gtk_source_search_context_forward2 (search_context, &iter, NULL, &match_end, NULL))
{
iter = match_end;
}
@@ -251,7 +251,7 @@ main (int argc, char *argv[])
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter);
- while (gtk_source_search_context_forward (search_context, &iter, NULL, &match_end))
+ while (gtk_source_search_context_forward2 (search_context, &iter, NULL, &match_end, NULL))
{
iter = match_end;
}
diff --git a/testsuite/test-search-context.c b/testsuite/test-search-context.c
index f755518..14cff00 100644
--- a/testsuite/test-search-context.c
+++ b/testsuite/test-search-context.c
@@ -415,10 +415,11 @@ check_search_results (GtkSourceBuffer *source_buffer,
if (forward)
{
- found = gtk_source_search_context_forward (context,
- &iter,
- &match_start,
- &match_end);
+ found = gtk_source_search_context_forward2 (context,
+ &iter,
+ &match_start,
+ &match_end,
+ NULL);
}
else
{
@@ -1010,7 +1011,7 @@ test_regex_at_word_boundaries (void)
gtk_text_buffer_get_start_iter (text_buffer, &iter);
- gtk_source_search_context_forward (context, &iter, &match_start, &match_end);
+ gtk_source_search_context_forward2 (context, &iter, &match_start, &match_end, NULL);
offset = gtk_text_iter_get_offset (&match_start);
g_assert_cmpint (offset, ==, 0);
@@ -1018,7 +1019,7 @@ test_regex_at_word_boundaries (void)
g_assert_cmpint (offset, ==, 4);
iter = match_end;
- gtk_source_search_context_forward (context, &iter, &match_start, &match_end);
+ gtk_source_search_context_forward2 (context, &iter, &match_start, &match_end, NULL);
offset = gtk_text_iter_get_offset (&match_start);
g_assert_cmpint (offset, ==, 11);
@@ -1093,7 +1094,7 @@ test_regex_look_behind (void)
/* Forward search */
gtk_text_buffer_get_start_iter (text_buffer, &iter);
- found = gtk_source_search_context_forward (context, &iter, &match_start, &match_end);
+ found = gtk_source_search_context_forward2 (context, &iter, &match_start, &match_end, NULL);
g_assert (found);
offset = gtk_text_iter_get_offset (&match_start);
@@ -1168,7 +1169,7 @@ test_regex_look_ahead (void)
/* Forward search */
gtk_text_buffer_get_start_iter (text_buffer, &iter);
- found = gtk_source_search_context_forward (context, &iter, &match_start, &match_end);
+ found = gtk_source_search_context_forward2 (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]