[gtksourceview/wip/regex-search: 5/5] Search: move public functions from Buffer to SearchContext
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/regex-search: 5/5] Search: move public functions from Buffer to SearchContext
- Date: Sun, 28 Jul 2013 19:06:27 +0000 (UTC)
commit f10b9206b3521d562a957e2b7434590c091ea612
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Jul 28 17:48:14 2013 +0200
Search: move public functions from Buffer to SearchContext
The code doesn't compile.
gtksourceview/gtksourcebuffer.c | 612 --------------------------------
gtksourceview/gtksourcesearchcontext.c | 494 ++++++++++++++++++++++----
gtksourceview/gtksourcesearchcontext.h | 11 +-
3 files changed, 421 insertions(+), 696 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index b47e52a..af86c9c 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -2530,615 +2530,3 @@ gtk_source_buffer_get_undo_manager (GtkSourceBuffer *buffer)
return buffer->priv->undo_manager;
}
-
-/**
- * gtk_source_buffer_set_search_text:
- * @buffer: a #GtkSourceBuffer.
- * @text: (allow-none): the nul-terminated text to search, or %NULL to disable the search.
- *
- * Sets the text to search. If @text is %NULL or is empty, the search will be
- * disabled. A copy of @text will be made, so you can safely free @text after
- * a call to this function.
- *
- * You may be interested to call gtk_source_utils_unescape_search_text() before
- * this function.
- *
- * Since: 3.10
- */
-void
-gtk_source_buffer_set_search_text (GtkSourceBuffer *buffer,
- const gchar *text)
-{
- const gchar *cur_text;
-
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
- cur_text = gtk_source_search_context_get_text (buffer->priv->search);
-
- if (cur_text == NULL && (text == NULL || *text == '\0'))
- {
- return;
- }
-
- if (g_strcmp0 (cur_text, text) != 0)
- {
- gtk_source_search_context_set_text (buffer->priv->search, text);
- g_object_notify (G_OBJECT (buffer), "search-text");
- }
-}
-
-/**
- * gtk_source_buffer_get_search_text:
- * @buffer: a #GtkSourceBuffer.
- *
- * Gets the text to search. The return value must not be freed.
- *
- * You may be interested to call gtk_source_utils_escape_search_text() after
- * this function.
- *
- * Returns: the text to search, or %NULL if the search is disabled.
- * Since: 3.10
- */
-const gchar *
-gtk_source_buffer_get_search_text (GtkSourceBuffer *buffer)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
-
- return gtk_source_search_context_get_text (buffer->priv->search);
-}
-
-/**
- * gtk_source_buffer_set_case_sensitive_search:
- * @buffer: a #GtkSourceBuffer.
- * @case_sensitive: the setting.
- *
- * Enables or disables the case sensitivity for the search.
- *
- * Since: 3.10
- */
-void
-gtk_source_buffer_set_case_sensitive_search (GtkSourceBuffer *buffer,
- gboolean case_sensitive)
-{
- gboolean cur_val;
-
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
- case_sensitive = case_sensitive != FALSE;
-
- cur_val = gtk_source_search_context_get_case_sensitive (buffer->priv->search);
-
- if (cur_val != case_sensitive)
- {
- gtk_source_search_context_set_case_sensitive (buffer->priv->search,
- case_sensitive);
-
- g_object_notify (G_OBJECT (buffer), "case-sensitive-search");
- }
-}
-
-/**
- * gtk_source_buffer_get_case_sensitive_search:
- * @buffer: a #GtkSourceBuffer.
- *
- * Returns: whether the search is case sensitive.
- * Since: 3.10
- */
-gboolean
-gtk_source_buffer_get_case_sensitive_search (GtkSourceBuffer *buffer)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
- return gtk_source_search_context_get_case_sensitive (buffer->priv->search);
-}
-
-/**
- * gtk_source_buffer_set_search_at_word_boundaries:
- * @buffer: a #GtkSourceBuffer.
- * @at_word_boundaries: the setting.
- *
- * Change whether the search is done at word boundaries. If @at_word_boundaries
- * is %TRUE, a search match must start and end a word. The match can span
- * multiple words. See also gtk_text_iter_starts_word() and
- * gtk_text_iter_ends_word().
- *
- * Since: 3.10
- */
-void
-gtk_source_buffer_set_search_at_word_boundaries (GtkSourceBuffer *buffer,
- gboolean at_word_boundaries)
-{
- gboolean cur_val;
-
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
- at_word_boundaries = at_word_boundaries != FALSE;
-
- cur_val = gtk_source_search_context_get_at_word_boundaries (buffer->priv->search);
-
- if (cur_val != at_word_boundaries)
- {
- gtk_source_search_context_set_at_word_boundaries (buffer->priv->search,
- at_word_boundaries);
-
- g_object_notify (G_OBJECT (buffer), "search-at-word-boundaries");
- }
-}
-
-/**
- * gtk_source_buffer_get_search_at_word_boundaries:
- * @buffer: a #GtkSourceBuffer.
- *
- * Returns: whether to search at word boundaries.
- * Since: 3.10
- */
-gboolean
-gtk_source_buffer_get_search_at_word_boundaries (GtkSourceBuffer *buffer)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
- return gtk_source_search_context_get_at_word_boundaries (buffer->priv->search);
-}
-
-/**
- * gtk_source_buffer_set_search_wrap_around:
- * @buffer: a #GtkSourceBuffer.
- * @wrap_around: the setting.
- *
- * Enables or disables the wrap around search. If @wrap_around is %TRUE, the
- * forward search continues at the beginning of the buffer if no search
- * occurrences are found. Similarly, the backward search continues to search at
- * the end of the buffer.
- *
- * Since: 3.10
- */
-void
-gtk_source_buffer_set_search_wrap_around (GtkSourceBuffer *buffer,
- gboolean wrap_around)
-{
- gboolean cur_val;
-
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
- wrap_around = wrap_around != FALSE;
-
- cur_val = gtk_source_search_context_get_wrap_around (buffer->priv->search);
-
- if (cur_val != wrap_around)
- {
- gtk_source_search_context_set_wrap_around (buffer->priv->search,
- wrap_around);
-
- g_object_notify (G_OBJECT (buffer), "search-wrap-around");
- }
-}
-
-/**
- * gtk_source_buffer_get_search_wrap_around:
- * @buffer: a #GtkSourceBuffer.
- *
- * Returns: whether to wrap around the search.
- * Since: 3.10
- */
-gboolean
-gtk_source_buffer_get_search_wrap_around (GtkSourceBuffer *buffer)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
- return gtk_source_search_context_get_wrap_around (buffer->priv->search);
-}
-
-/**
- * gtk_source_buffer_set_regex_search:
- * @buffer: a #GtkSourceBuffer.
- * @regex: the setting.
- *
- * Enables or disables whether to search by regular expressions.
- * If enabled, the #GtkSourceBuffer:search-text property contains the pattern of
- * the regular expression.
- *
- * See also gtk_source_buffer_get_regex_search_error().
- *
- * Since: 3.10
- */
-void
-gtk_source_buffer_set_regex_search (GtkSourceBuffer *buffer,
- gboolean regex)
-{
- gboolean cur_val;
-
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
- regex = regex != FALSE;
-
- cur_val = gtk_source_search_context_get_regex_enabled (buffer->priv->search);
-
- if (cur_val != regex)
- {
- gtk_source_search_context_set_regex_enabled (buffer->priv->search, regex);
-
- g_object_notify (G_OBJECT (buffer), "regex-search");
- }
-}
-
-/**
- * gtk_source_buffer_get_regex_search:
- * @buffer: a #GtkSourceBuffer.
- *
- * Returns: whether to search by regular expressions.
- * Since: 3.10
- */
-gboolean
-gtk_source_buffer_get_regex_search (GtkSourceBuffer *buffer)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
- return gtk_source_search_context_get_regex_enabled (buffer->priv->search);
-}
-
-/**
- * gtk_source_buffer_get_regex_search_error:
- * @buffer: a #GtkSourceBuffer.
- *
- * Regular expression patterns must follow certain rules. If
- * #GtkSourceBuffer:search-text breaks a rule, the error can be retrieved with
- * this function. The error domain is #G_REGEX_ERROR.
- *
- * Free the return value with g_error_free().
- *
- * Returns: the #GError, or %NULL if the pattern is valid.
- * Since: 3.10
- */
-GError *
-gtk_source_buffer_get_regex_search_error (GtkSourceBuffer *buffer)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
-
- return gtk_source_search_context_get_regex_error (buffer->priv->search);
-}
-
-/**
- * gtk_source_buffer_set_highlight_search:
- * @buffer: a #GtkSourceBuffer.
- * @highlight: the setting.
- *
- * Enables or disables search highlighting. If you disable the search
- * highlighting, you can still use the other search and replace functions.
- *
- * Since: 3.10
- */
-void
-gtk_source_buffer_set_highlight_search (GtkSourceBuffer *buffer,
- gboolean highlight)
-{
- gboolean cur_val;
-
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
- highlight = highlight != FALSE;
-
- cur_val = gtk_source_search_context_get_highlight (buffer->priv->search);
-
- if (cur_val != highlight)
- {
- gtk_source_search_context_set_highlight (buffer->priv->search, highlight);
-
- g_object_notify (G_OBJECT (buffer), "highlight-search");
- }
-}
-
-/**
- * gtk_source_buffer_get_highlight_search:
- * @buffer: a #GtkSourceBuffer.
- *
- * Returns: whether to highlight search occurrences.
- * Since: 3.10
- */
-gboolean
-gtk_source_buffer_get_highlight_search (GtkSourceBuffer *buffer)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
- return gtk_source_search_context_get_highlight (buffer->priv->search);
-}
-
-/**
- * gtk_source_buffer_get_search_occurrences_count:
- * @buffer: a #GtkSourceBuffer.
- *
- * Gets the total number of search occurrences. If the buffer is not already
- * fully scanned, the total number of occurrences is unknown, and -1 is
- * returned.
- *
- * Returns: the total number of search occurrences, or -1 if unknown.
- * Since: 3.10
- */
-gint
-gtk_source_buffer_get_search_occurrences_count (GtkSourceBuffer *buffer)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), 0);
-
- return gtk_source_search_context_get_occurrences_count (buffer->priv->search);
-}
-
-/**
- * gtk_source_buffer_get_search_occurrence_position:
- * @buffer: a #GtkSourceBuffer.
- * @match_start: the start of the occurrence.
- * @match_end: the end of the occurrence.
- *
- * Gets the position of a search occurrence. If the buffer is not already fully
- * scanned, the position may be unknown, and -1 is returned. Therefore you
- * should call this function when you know that the buffer is fully scanned.
- *
- * Returns: the position of the search occurrence. The first occurrence has the
- * position 1 (not 0). Returns 0 if @match_start and @match_end doesn't delimit
- * an occurrence. Returns -1 if the position is not yet known.
- *
- * Since: 3.10
- */
-gint
-gtk_source_buffer_get_search_occurrence_position (GtkSourceBuffer *buffer,
- const GtkTextIter *match_start,
- const GtkTextIter *match_end)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), -1);
- g_return_val_if_fail (match_start != NULL, -1);
- g_return_val_if_fail (match_end != NULL, -1);
-
- return gtk_source_search_context_get_occurrence_position (buffer->priv->search,
- match_start,
- match_end);
-}
-
-/**
- * gtk_source_buffer_forward_search:
- * @buffer: a #GtkSourceBuffer.
- * @iter: start of search.
- * @match_start: (out) (allow-none): return location for start of match, or %NULL.
- * @match_end: (out) (allow-none): return location for end of match, 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.
- *
- * Returns: whether a match was found.
- * Since: 3.10
- */
-gboolean
-gtk_source_buffer_forward_search (GtkSourceBuffer *buffer,
- const GtkTextIter *iter,
- GtkTextIter *match_start,
- GtkTextIter *match_end)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
- g_return_val_if_fail (iter != NULL, FALSE);
-
- return gtk_source_search_context_forward (buffer->priv->search,
- iter,
- match_start,
- match_end);
-}
-
-/**
- * gtk_source_buffer_forward_search_async:
- * @buffer: a #GtkSourceBuffer.
- * @iter: start of search.
- * @cancellable: (allow-none): a #GCancellable, or %NULL.
- * @callback: a #GAsyncReadyCallback to call when the operation is finished.
- * @user_data: the data to pass to the @callback function.
- *
- * Asynchronous forward search. See the #GAsyncResult documentation to know
- * how to use this function.
- *
- * If the operation is cancelled, the @callback will only be called if
- * @cancellable was not %NULL. gtk_source_buffer_forward_search_async() takes
- * ownership of @cancellable, so you can unref it after calling this function.
- *
- * Since: 3.10
- */
-void
-gtk_source_buffer_forward_search_async (GtkSourceBuffer *buffer,
- const GtkTextIter *iter,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
- g_return_if_fail (iter != NULL);
-
- gtk_source_search_context_forward_async (buffer->priv->search,
- iter,
- cancellable,
- callback,
- user_data);
-}
-
-/**
- * gtk_source_buffer_forward_search_finish:
- * @buffer: a #GtkSourceBuffer.
- * @result: a #GAsyncResult.
- * @match_start: (out) (allow-none): return location for start of match, or %NULL.
- * @match_end: (out) (allow-none): return location for end of match, or %NULL.
- * @error: a #GError, or %NULL.
- *
- * Finishes a forward search started with
- * gtk_source_buffer_forward_search_async().
- *
- * Returns: whether a match was found.
- * Since: 3.10
- */
-gboolean
-gtk_source_buffer_forward_search_finish (GtkSourceBuffer *buffer,
- GAsyncResult *result,
- GtkTextIter *match_start,
- GtkTextIter *match_end,
- GError **error)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
- return gtk_source_search_context_forward_finish (buffer->priv->search,
- result,
- match_start,
- match_end,
- error);
-}
-
-/**
- * gtk_source_buffer_backward_search:
- * @buffer: a #GtkSourceBuffer.
- * @iter: start of search.
- * @match_start: (out) (allow-none): return location for start of match, or %NULL.
- * @match_end: (out) (allow-none): return location for end of match, 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.
- *
- * Returns: whether a match was found.
- * Since: 3.10
- */
-gboolean
-gtk_source_buffer_backward_search (GtkSourceBuffer *buffer,
- const GtkTextIter *iter,
- GtkTextIter *match_start,
- GtkTextIter *match_end)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
- g_return_val_if_fail (iter != NULL, FALSE);
-
- return gtk_source_search_context_backward (buffer->priv->search,
- iter,
- match_start,
- match_end);
-}
-
-/**
- * gtk_source_buffer_backward_search_async:
- * @buffer: a #GtkSourceBuffer.
- * @iter: start of search.
- * @cancellable: (allow-none): a #GCancellable, or %NULL.
- * @callback: a #GAsyncReadyCallback to call when the operation is finished.
- * @user_data: the data to pass to the @callback function.
- *
- * Asynchronous backward search. See the #GAsyncResult documentation to know
- * how to use this function.
- *
- * If the operation is cancelled, the @callback will only be called if
- * @cancellable was not %NULL. gtk_source_buffer_backward_search_async() takes
- * ownership of @cancellable, so you can unref it after calling this function.
- *
- * Since: 3.10
- */
-void
-gtk_source_buffer_backward_search_async (GtkSourceBuffer *buffer,
- const GtkTextIter *iter,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
- g_return_if_fail (iter != NULL);
-
- gtk_source_search_context_backward_async (buffer->priv->search,
- iter,
- cancellable,
- callback,
- user_data);
-}
-
-/**
- * gtk_source_buffer_backward_search_finish:
- * @buffer: a #GtkSourceBuffer.
- * @result: a #GAsyncResult.
- * @match_start: (out) (allow-none): return location for start of match, or %NULL.
- * @match_end: (out) (allow-none): return location for end of match, or %NULL.
- * @error: a #GError, or %NULL.
- *
- * Finishes a backward search started with
- * gtk_source_buffer_backward_search_async().
- *
- * Returns: whether a match was found.
- * Since: 3.10
- */
-gboolean
-gtk_source_buffer_backward_search_finish (GtkSourceBuffer *buffer,
- GAsyncResult *result,
- GtkTextIter *match_start,
- GtkTextIter *match_end,
- GError **error)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
- return gtk_source_search_context_backward_finish (buffer->priv->search,
- result,
- match_start,
- match_end,
- error);
-}
-
-/**
- * gtk_source_buffer_search_replace:
- * @buffer: a #GtkSourceBuffer.
- * @match_start: the start of the match to replace.
- * @match_end: the end of the match to replace.
- * @replace: the replacement text.
- * @replace_length: the length of @replace in bytes, or -1.
- *
- * Replaces a search match by another text. If @match_start and @match_end
- * doesn't correspond to a search match, %FALSE is returned.
- *
- * For a regular expression replacement, you can check if @replace is valid by
- * calling g_regex_check_replacement(). The @replace text can contain
- * backreferences; read the g_regex_replace() documentation for more details.
- *
- * Returns: whether the match has been replaced.
- * Since: 3.10
- */
-gboolean
-gtk_source_buffer_search_replace (GtkSourceBuffer *buffer,
- const GtkTextIter *match_start,
- const GtkTextIter *match_end,
- const gchar *replace,
- gint replace_length)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
- g_return_val_if_fail (match_start != NULL, FALSE);
- g_return_val_if_fail (match_end != NULL, FALSE);
- g_return_val_if_fail (replace != NULL, FALSE);
-
- return gtk_source_search_context_replace (buffer->priv->search,
- match_start,
- match_end,
- replace,
- replace_length);
-}
-
-/**
- * gtk_source_buffer_search_replace_all:
- * @buffer: a #GtkSourceBuffer.
- * @replace: the replacement text.
- * @replace_length: the length of @replace in bytes, or -1.
- *
- * Replaces all search matches by another text. It is a synchronous function, so
- * it can block the user interface.
- *
- * For a regular expression replacement, you can check if @replace is valid by
- * calling g_regex_check_replacement(). The @replace text can contain
- * backreferences; read the g_regex_replace() documentation for more details.
- *
- * Returns: the number of replaced matches.
- * Since: 3.10
- */
-guint
-gtk_source_buffer_search_replace_all (GtkSourceBuffer *buffer,
- const gchar *replace,
- gint replace_length)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), 0);
- g_return_val_if_fail (replace != NULL, 0);
-
- return gtk_source_search_context_replace_all (buffer->priv->search,
- replace,
- replace_length);
-}
diff --git a/gtksourceview/gtksourcesearchcontext.c b/gtksourceview/gtksourcesearchcontext.c
index fffaa4c..b97783d 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -192,7 +192,7 @@ enum
PROP_CASE_SENSITIVE,
PROP_AT_WORD_BOUNDARIES,
PROP_WRAP_AROUND,
- PROP_REGEX,
+ PROP_REGEX_ENABLED,
PROP_REGEX_ERROR
};
@@ -2455,7 +2455,7 @@ gtk_source_search_context_get_property (GObject *object,
g_value_set_boolean (value, gtk_source_search_context_get_wrap_around
(source_buffer->priv->search));
break;
- case PROP_REGEX:
+ case PROP_REGEX_ENABLED:
g_value_set_boolean (value, gtk_source_search_context_get_regex_enabled
(source_buffer->priv->search));
break;
@@ -2508,7 +2508,7 @@ gtk_source_search_context_set_property (GObject *object,
g_value_get_boolean (value));
break;
- case PROP_REGEX:
+ case PROP_REGEX_ENABLED:
gtk_source_search_context_set_regex_enabled (source_buffer->priv->search,
g_value_get_boolean (value));
break;
@@ -2629,7 +2629,7 @@ gtk_source_search_context_class_init (GtkSourceSearchContextClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
/**
- * GtkSourceSearchContext:regex:
+ * GtkSourceSearchContext:regex-enabled:
*
* Search by regular expressions with
* #GtkSourceSearchContext:search-text as the pattern.
@@ -2637,10 +2637,10 @@ gtk_source_search_context_class_init (GtkSourceSearchContextClass *klass)
* Since: 3.10
*/
g_object_class_install_property (object_class,
- PROP_REGEX,
- g_param_spec_boolean ("regex",
- _("Regex"),
- _("Search by regular expression"),
+ PROP_REGEX_ENABLED,
+ g_param_spec_boolean ("regex-enabled",
+ _("Regex enabled"),
+ _("Whether to search by regular expression"),
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
@@ -2717,13 +2717,33 @@ compute_number_of_lines (const gchar *text)
return nb_of_lines;
}
+/**
+ * gtk_source_search_context_set_search_text:
+ * @search: a #GtkSourceSearchContext.
+ * @text: (allow-none): the nul-terminated text to search, or %NULL to disable the search.
+ *
+ * Sets the text to search. If @text is %NULL or is empty, the search will be
+ * disabled. A copy of @text will be made, so you can safely free @text after
+ * a call to this function.
+ *
+ * You may be interested to call gtk_source_utils_unescape_search_text() before
+ * this function.
+ *
+ * Since: 3.10
+ */
void
-gtk_source_search_context_set_text (GtkSourceSearchContext *search,
- const gchar *text)
+gtk_source_search_context_set_search_text (GtkSourceSearchContext *search,
+ const gchar *text)
{
g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search));
g_return_if_fail (text == NULL || g_utf8_validate (text, -1, NULL));
+ if ((search->priv->text == NULL && (text == NULL || text[0] == '\0')) ||
+ g_strcmp0 (search->priv->text, text) == 0)
+ {
+ return;
+ }
+
g_free (search->priv->text);
if (text == NULL || *text == '\0')
@@ -2746,22 +2766,56 @@ gtk_source_search_context_set_text (GtkSourceSearchContext *search,
update_regex (search);
update (search);
+
+ g_object_notify (G_OBJECT (search), "search-text");
}
+/**
+ * gtk_source_search_context_get_search_text:
+ * @search: a #GtkSourceSearchContext.
+ *
+ * Gets the text to search. The return value must not be freed.
+ *
+ * You may be interested to call gtk_source_utils_escape_search_text() after
+ * this function.
+ *
+ * Returns: the text to search, or %NULL if the search is disabled.
+ * Since: 3.10
+ */
const gchar *
-gtk_source_search_context_get_text (GtkSourceSearchContext *search)
+gtk_source_search_context_get_search_text (GtkSourceSearchContext *search)
{
g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), NULL);
return search->priv->text;
}
+/**
+ * gtk_source_search_context_set_case_sensitive:
+ * @search: a #GtkSourceSearchContext.
+ * @case_sensitive: the setting.
+ *
+ * Enables or disables the case sensitivity for the search.
+ *
+ * Since: 3.10
+ */
void
gtk_source_search_context_set_case_sensitive (GtkSourceSearchContext *search,
gboolean case_sensitive)
{
+ gboolean cur_val;
+
g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search));
+ case_sensitive = case_sensitive != FALSE;
+
+ cur_val = gtk_source_search_context_get_case_sensitive (search);
+
+ if (cur_val == case_sensitive)
+ {
+ return;
+ }
+
if (case_sensitive)
{
search->priv->flags &= ~GTK_TEXT_SEARCH_CASE_INSENSITIVE;
@@ -2773,8 +2827,17 @@ gtk_source_search_context_set_case_sensitive (GtkSourceSearchContext *search,
update_regex (search);
update (search);
+
+ g_object_notify (G_OBJECT (buffer), "case-sensitive");
}
+/**
+ * gtk_source_search_context_get_case_sensitive:
+ * @search: a #GtkSourceSearchContext.
+ *
+ * Returns: whether the search is case sensitive.
+ * Since: 3.10
+ */
gboolean
gtk_source_search_context_get_case_sensitive (GtkSourceSearchContext *search)
{
@@ -2783,18 +2846,46 @@ gtk_source_search_context_get_case_sensitive (GtkSourceSearchContext *search)
return (search->priv->flags & GTK_TEXT_SEARCH_CASE_INSENSITIVE) == 0;
}
+/**
+ * gtk_source_search_context_set_at_word_boundaries:
+ * @search: a #GtkSourceSearchContext.
+ * @at_word_boundaries: the setting.
+ *
+ * Change whether the search is done at word boundaries. If @at_word_boundaries
+ * is %TRUE, a search match must start and end a word. The match can span
+ * multiple words. See also gtk_text_iter_starts_word() and
+ * gtk_text_iter_ends_word().
+ *
+ * Since: 3.10
+ */
void
gtk_source_search_context_set_at_word_boundaries (GtkSourceSearchContext *search,
gboolean at_word_boundaries)
{
g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search));
+ at_word_boundaries = at_word_boundaries != FALSE;
+
+ if (search->priv->at_word_boundaries == at_word_boundaries)
+ {
+ return;
+ }
+
search->priv->at_word_boundaries = at_word_boundaries;
update_regex (search);
update (search);
+
+ g_object_notify (G_OBJECT (buffer), "at-word-boundaries");
}
+/**
+ * gtk_source_search_context_get_at_word_boundaries:
+ * @search: a #GtkSourceSearchContext.
+ *
+ * Returns: whether to search at word boundaries.
+ * Since: 3.10
+ */
gboolean
gtk_source_search_context_get_at_word_boundaries (GtkSourceSearchContext *search)
{
@@ -2803,16 +2894,44 @@ gtk_source_search_context_get_at_word_boundaries (GtkSourceSearchContext *search
return search->priv->at_word_boundaries;
}
+/**
+ * gtk_source_search_context_set_wrap_around:
+ * @search: a #GtkSourceSearchContext.
+ * @wrap_around: the setting.
+ *
+ * Enables or disables the wrap around search. If @wrap_around is %TRUE, the
+ * forward search continues at the beginning of the buffer if no search
+ * occurrences are found. Similarly, the backward search continues to search at
+ * the end of the buffer.
+ *
+ * Since: 3.10
+ */
void
gtk_source_search_context_set_wrap_around (GtkSourceSearchContext *search,
gboolean wrap_around)
{
g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search));
+ wrap_around = wrap_around != FALSE;
+
+ if (search->priv->wrap_around == wrap_around)
+ {
+ return;
+ }
+
search->priv->wrap_around = wrap_around;
update (search);
+
+ g_object_notify (G_OBJECT (buffer), "wrap-around");
}
+/**
+ * gtk_source_search_context_get_wrap_around:
+ * @search: a #GtkSourceSearchContext.
+ *
+ * Returns: whether to wrap around the search.
+ * Since: 3.10
+ */
gboolean
gtk_source_search_context_get_wrap_around (GtkSourceSearchContext *search)
{
@@ -2821,18 +2940,45 @@ gtk_source_search_context_get_wrap_around (GtkSourceSearchContext *search)
return search->priv->wrap_around;
}
+/**
+ * gtk_source_search_context_set_regex_enabled:
+ * @search: a #GtkSourceSearchContext.
+ * @regex: the setting.
+ *
+ * Enables or disables whether to search by regular expressions.
+ * If enabled, the #GtkSourceSearchContext:search-text property contains the
+ * pattern of the regular expression.
+ *
+ * Since: 3.10
+ */
void
gtk_source_search_context_set_regex_enabled (GtkSourceSearchContext *search,
gboolean regex_enabled)
{
g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search));
+ regex_enabled = regex_enabled != FALSE;
+
+ if (search->priv->regex_enabled == regex)
+ {
+ return;
+ }
+
search->priv->regex_enabled = regex_enabled;
update_regex (search);
update (search);
+
+ g_object_notify (G_OBJECT (buffer), "regex-enabled");
}
+/**
+ * gtk_source_search_context_get_regex_enabled:
+ * @search: a #GtkSourceSearchContext.
+ *
+ * Returns: whether to search by regular expressions.
+ * Since: 3.10
+ */
gboolean
gtk_source_search_context_get_regex_enabled (GtkSourceSearchContext *search)
{
@@ -2841,6 +2987,19 @@ gtk_source_search_context_get_regex_enabled (GtkSourceSearchContext *search)
return search->priv->regex_enabled;
}
+/**
+ * gtk_source_search_context_get_regex_error:
+ * @search: a #GtkSourceSearchContext.
+ *
+ * Regular expression patterns must follow certain rules. If
+ * #GtkSourceSearchContext:search-text breaks a rule, the error can be retrieved
+ * with this function. The error domain is #G_REGEX_ERROR.
+ *
+ * Free the return value with g_error_free().
+ *
+ * Returns: the #GError, or %NULL if the pattern is valid.
+ * Since: 3.10
+ */
GError *
gtk_source_search_context_get_regex_error (GtkSourceSearchContext *search)
{
@@ -2854,20 +3013,46 @@ gtk_source_search_context_get_regex_error (GtkSourceSearchContext *search)
return g_error_copy (search->priv->regex_error);
}
+/**
+ * gtk_source_search_context_set_highlight:
+ * @search: a #GtkSourceSearchContext.
+ * @highlight: the setting.
+ *
+ * Enables or disables search highlighting. If you disable the search
+ * highlighting, you can still use the other search and replace functions.
+ *
+ * Since: 3.10
+ */
void
gtk_source_search_context_set_highlight (GtkSourceSearchContext *search,
gboolean highlight)
{
g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search));
+ highlight = highlight != FALSE;
+
+ if (search->priv->highlight == highlight)
+ {
+ return;
+ }
+
search->priv->highlight = highlight;
if (search->priv->found_tag != NULL)
{
sync_found_tag (search);
}
+
+ g_object_notify (G_OBJECT (buffer), "highlight");
}
+/**
+ * gtk_source_search_context_get_highlight:
+ * @search: a #GtkSourceSearchContext.
+ *
+ * Returns: whether to highlight search occurrences.
+ * Since: 3.10
+ */
gboolean
gtk_source_search_context_get_highlight (GtkSourceSearchContext *search)
{
@@ -2876,14 +3061,41 @@ gtk_source_search_context_get_highlight (GtkSourceSearchContext *search)
return search->priv->highlight;
}
+/**
+ * gtk_source_search_context_get_occurrences_count:
+ * @search: a #GtkSourceSearchContext.
+ *
+ * Gets the total number of search occurrences. If the buffer is not already
+ * fully scanned, the total number of occurrences is unknown, and -1 is
+ * returned.
+ *
+ * Returns: the total number of search occurrences, or -1 if unknown.
+ * Since: 3.10
+ */
gint
gtk_source_search_context_get_occurrences_count (GtkSourceSearchContext *search)
{
- g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), 0);
+ g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), -1);
return is_text_region_empty (search->priv->scan_region) ? search->priv->occurrences_count : -1;
}
+/**
+ * gtk_source_search_context_get_occurrence_position:
+ * @search: a #GtkSourceSearchContext.
+ * @match_start: the start of the occurrence.
+ * @match_end: the end of the occurrence.
+ *
+ * Gets the position of a search occurrence. If the buffer is not already fully
+ * scanned, the position may be unknown, and -1 is returned. Therefore you
+ * should call this function when you know that the buffer is fully scanned.
+ *
+ * Returns: the position of the search occurrence. The first occurrence has the
+ * position 1 (not 0). Returns 0 if @match_start and @match_end doesn't delimit
+ * an occurrence. Returns -1 if the position is not yet known.
+ *
+ * Since: 3.10
+ */
gint
gtk_source_search_context_get_occurrence_position (GtkSourceSearchContext *search,
const GtkTextIter *match_start,
@@ -2955,73 +3167,20 @@ gtk_source_search_context_get_occurrence_position (GtkSourceSearchContext *searc
return position + 1;
}
-void
-gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
- const GtkTextIter *start,
- const GtkTextIter *end,
- gboolean synchronous)
-{
- GtkTextRegion *region_to_highlight;
-
- g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search));
- g_return_if_fail (start != NULL);
- g_return_if_fail (end != NULL);
-
- if (dispose_has_run (search) ||
- is_text_region_empty (search->priv->scan_region))
- {
- return;
- }
-
- region_to_highlight = gtk_text_region_intersect (search->priv->scan_region,
- start,
- end);
-
- if (is_text_region_empty (region_to_highlight))
- {
- if (region_to_highlight != NULL)
- {
- gtk_text_region_destroy (region_to_highlight, TRUE);
- }
-
- return;
- }
-
- if (!synchronous)
- {
- if (search->priv->high_priority_region != NULL)
- {
- /* The high priority region is used to highlight the
- * region visible on screen. So if we are here, that
- * means that the visible region has changed. So we can
- * destroy the old high_priority_region.
- */
- gtk_text_region_destroy (search->priv->high_priority_region, TRUE);
- }
-
- search->priv->high_priority_region = region_to_highlight;
- install_idle_scan (search);
- return;
- }
-
- if (search->priv->regex_enabled)
- {
- GtkTextIter start;
-
- gtk_text_region_nth_subregion (search->priv->scan_region,
- 0,
- &start,
- NULL);
-
- regex_search_scan_chunk (search, &start, end);
- }
- else
- {
- scan_all_region (search, region_to_highlight);
- gtk_text_region_destroy (region_to_highlight, TRUE);
- }
-}
-
+/**
+ * gtk_source_search_context_forward:
+ * @search: a #GtkSourceSearchContext.
+ * @iter: start of search.
+ * @match_start: (out) (allow-none): return location for start of match, or %NULL.
+ * @match_end: (out) (allow-none): return location for end of match, 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.
+ *
+ * Returns: whether a match was found.
+ * Since: 3.10
+ */
gboolean
gtk_source_search_context_forward (GtkSourceSearchContext *search,
const GtkTextIter *iter,
@@ -3051,6 +3210,23 @@ gtk_source_search_context_forward (GtkSourceSearchContext *search,
return found;
}
+/**
+ * gtk_source_search_context_forward_async:
+ * @search: a #GtkSourceSearchContext.
+ * @iter: start of search.
+ * @cancellable: (allow-none): a #GCancellable, or %NULL.
+ * @callback: a #GAsyncReadyCallback to call when the operation is finished.
+ * @user_data: the data to pass to the @callback function.
+ *
+ * Asynchronous forward search. See the #GAsyncResult documentation to know
+ * how to use this function.
+ *
+ * If the operation is cancelled, the @callback will only be called if
+ * @cancellable was not %NULL. gtk_source_search_context_forward_async() takes
+ * ownership of @cancellable, so you can unref it after calling this function.
+ *
+ * Since: 3.10
+ */
void
gtk_source_search_context_forward_async (GtkSourceSearchContext *search,
const GtkTextIter *iter,
@@ -3072,6 +3248,20 @@ gtk_source_search_context_forward_async (GtkSourceSearchContext *search,
smart_forward_search_async (search, iter, FALSE);
}
+/**
+ * gtk_source_search_context_forward_finish:
+ * @search: a #GtkSourceSearchContext.
+ * @result: a #GAsyncResult.
+ * @match_start: (out) (allow-none): return location for start of match, or %NULL.
+ * @match_end: (out) (allow-none): return location for end of match, or %NULL.
+ * @error: a #GError, or %NULL.
+ *
+ * Finishes a forward search started with
+ * gtk_source_search_context_forward_async().
+ *
+ * Returns: whether a match was found.
+ * Since: 3.10
+ */
gboolean
gtk_source_search_context_forward_finish (GtkSourceSearchContext *search,
GAsyncResult *result,
@@ -3117,6 +3307,20 @@ gtk_source_search_context_forward_finish (GtkSourceSearchContext *search,
return found;
}
+/**
+ * gtk_source_search_context_backward:
+ * @search: a #GtkSourceSearchContext.
+ * @iter: start of search.
+ * @match_start: (out) (allow-none): return location for start of match, or %NULL.
+ * @match_end: (out) (allow-none): return location for end of match, 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.
+ *
+ * Returns: whether a match was found.
+ * Since: 3.10
+ */
gboolean
gtk_source_search_context_backward (GtkSourceSearchContext *search,
const GtkTextIter *iter,
@@ -3147,6 +3351,23 @@ gtk_source_search_context_backward (GtkSourceSearchContext *search,
return found;
}
+/**
+ * gtk_source_search_context_backward_async:
+ * @search: a #GtkSourceSearchContext.
+ * @iter: start of search.
+ * @cancellable: (allow-none): a #GCancellable, or %NULL.
+ * @callback: a #GAsyncReadyCallback to call when the operation is finished.
+ * @user_data: the data to pass to the @callback function.
+ *
+ * Asynchronous backward search. See the #GAsyncResult documentation to know
+ * how to use this function.
+ *
+ * If the operation is cancelled, the @callback will only be called if
+ * @cancellable was not %NULL. gtk_source_search_context_backward_async() takes
+ * ownership of @cancellable, so you can unref it after calling this function.
+ *
+ * Since: 3.10
+ */
void
gtk_source_search_context_backward_async (GtkSourceSearchContext *search,
const GtkTextIter *iter,
@@ -3168,6 +3389,20 @@ gtk_source_search_context_backward_async (GtkSourceSearchContext *search,
smart_backward_search_async (search, iter, FALSE);
}
+/**
+ * gtk_source_search_context_backward_finish:
+ * @search: a #GtkSourceSearchContext.
+ * @result: a #GAsyncResult.
+ * @match_start: (out) (allow-none): return location for start of match, or %NULL.
+ * @match_end: (out) (allow-none): return location for end of match, or %NULL.
+ * @error: a #GError, or %NULL.
+ *
+ * Finishes a backward search started with
+ * gtk_source_search_context_backward_async().
+ *
+ * Returns: whether a match was found.
+ * Since: 3.10
+ */
gboolean
gtk_source_search_context_backward_finish (GtkSourceSearchContext *search,
GAsyncResult *result,
@@ -3231,6 +3466,24 @@ regex_replace (GtkSourceSearchContext *search,
return TRUE;
}
+/**
+ * gtk_source_search_context_replace:
+ * @search: a #GtkSourceSearchContext.
+ * @match_start: the start of the match to replace.
+ * @match_end: the end of the match to replace.
+ * @replace: the replacement text.
+ * @replace_length: the length of @replace in bytes, or -1.
+ *
+ * Replaces a search match by another text. If @match_start and @match_end
+ * doesn't correspond to a search match, %FALSE is returned.
+ *
+ * For a regular expression replacement, you can check if @replace is valid by
+ * calling g_regex_check_replacement(). The @replace text can contain
+ * backreferences; read the g_regex_replace() documentation for more details.
+ *
+ * Returns: whether the match has been replaced.
+ * Since: 3.10
+ */
gboolean
gtk_source_search_context_replace (GtkSourceSearchContext *search,
const GtkTextIter *match_start,
@@ -3275,6 +3528,22 @@ gtk_source_search_context_replace (GtkSourceSearchContext *search,
return TRUE;
}
+/**
+ * gtk_source_search_context_replace_all:
+ * @search: a #GtkSourceSearchContext.
+ * @replace: the replacement text.
+ * @replace_length: the length of @replace in bytes, or -1.
+ *
+ * Replaces all search matches by another text. It is a synchronous function, so
+ * it can block the user interface.
+ *
+ * For a regular expression replacement, you can check if @replace is valid by
+ * calling g_regex_check_replacement(). The @replace text can contain
+ * backreferences; read the g_regex_replace() documentation for more details.
+ *
+ * Returns: the number of replaced matches.
+ * Since: 3.10
+ */
guint
gtk_source_search_context_replace_all (GtkSourceSearchContext *search,
const gchar *replace,
@@ -3354,3 +3623,70 @@ gtk_source_search_context_replace_all (GtkSourceSearchContext *search,
return nb_matches_replaced;
}
+
+void
+_gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
+ const GtkTextIter *start,
+ const GtkTextIter *end,
+ gboolean synchronous)
+{
+ GtkTextRegion *region_to_highlight;
+
+ g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search));
+ g_return_if_fail (start != NULL);
+ g_return_if_fail (end != NULL);
+
+ if (dispose_has_run (search) ||
+ is_text_region_empty (search->priv->scan_region))
+ {
+ return;
+ }
+
+ region_to_highlight = gtk_text_region_intersect (search->priv->scan_region,
+ start,
+ end);
+
+ if (is_text_region_empty (region_to_highlight))
+ {
+ if (region_to_highlight != NULL)
+ {
+ gtk_text_region_destroy (region_to_highlight, TRUE);
+ }
+
+ return;
+ }
+
+ if (!synchronous)
+ {
+ if (search->priv->high_priority_region != NULL)
+ {
+ /* The high priority region is used to highlight the
+ * region visible on screen. So if we are here, that
+ * means that the visible region has changed. So we can
+ * destroy the old high_priority_region.
+ */
+ gtk_text_region_destroy (search->priv->high_priority_region, TRUE);
+ }
+
+ search->priv->high_priority_region = region_to_highlight;
+ install_idle_scan (search);
+ return;
+ }
+
+ if (search->priv->regex_enabled)
+ {
+ GtkTextIter start;
+
+ gtk_text_region_nth_subregion (search->priv->scan_region,
+ 0,
+ &start,
+ NULL);
+
+ regex_search_scan_chunk (search, &start, end);
+ }
+ else
+ {
+ scan_all_region (search, region_to_highlight);
+ gtk_text_region_destroy (region_to_highlight, TRUE);
+ }
+}
diff --git a/gtksourceview/gtksourcesearchcontext.h b/gtksourceview/gtksourcesearchcontext.h
index 0c2c7cf..e835088 100644
--- a/gtksourceview/gtksourcesearchcontext.h
+++ b/gtksourceview/gtksourcesearchcontext.h
@@ -91,11 +91,6 @@ gint gtk_source_search_context_get_occurrence_position
(GtkSourceSearchContext
const GtkTextIter
*match_start,
const GtkTextIter
*match_end);
-void gtk_source_search_context_update_highlight (GtkSourceSearchContext
*search,
- const GtkTextIter
*start,
- const GtkTextIter *end,
- gboolean
synchronous);
-
gboolean gtk_source_search_context_forward (GtkSourceSearchContext
*search,
const GtkTextIter *iter,
GtkTextIter
*match_start,
@@ -140,6 +135,12 @@ guint gtk_source_search_context_replace_all
(GtkSourceSearchContext *search,
const gchar
*replace,
gint
replace_length);
+G_GNUC_INTERNAL
+void _gtk_source_search_context_update_highlight (GtkSourceSearchContext
*search,
+ const GtkTextIter
*start,
+ const GtkTextIter *end,
+ gboolean
synchronous);
+
G_END_DECLS
#endif /* __GTK_SOURCE_SEARCH_CONTEXT_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]