[gtksourceview/wip/regex-search] Possible to compile SearchContext
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/regex-search] Possible to compile SearchContext
- Date: Tue, 30 Jul 2013 14:40:07 +0000 (UTC)
commit 6e734fcabc2602afdd8506dddde44cb4359fd903
Author: Sébastien Wilmet <swilmet gnome org>
Date: Tue Jul 30 16:22:20 2013 +0200
Possible to compile SearchContext
(just SearchContext)
gtksourceview/gtksourcesearchcontext.c | 164 ++++++++++++++++++++-----------
gtksourceview/gtksourcesearchsettings.c | 1 +
2 files changed, 108 insertions(+), 57 deletions(-)
---
diff --git a/gtksourceview/gtksourcesearchcontext.c b/gtksourceview/gtksourcesearchcontext.c
index a685986..c8e67f1 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -26,6 +26,7 @@
#include "gtksourcestyle-private.h"
#include "gtksourceutils.h"
#include "gtktextregion.h"
+#include "gtksourceview-i18n.h"
#include <string.h>
@@ -485,6 +486,20 @@ clear_search (GtkSourceSearchContext *search)
search->priv->occurrences_count = 0;
}
+static GtkTextSearchFlags
+get_text_search_flags (GtkSourceSearchContext *search)
+{
+ GtkSourceSearchSettings *settings = get_settings (search);
+ GtkTextSearchFlags flags = GTK_TEXT_SEARCH_TEXT_ONLY | GTK_TEXT_SEARCH_VISIBLE_ONLY;
+
+ if (!gtk_source_search_settings_get_case_sensitive (settings))
+ {
+ flags |= GTK_TEXT_SEARCH_CASE_INSENSITIVE;
+ }
+
+ return flags;
+}
+
static void
regex_search_get_real_start (GtkSourceSearchContext *search,
const GtkTextIter *start,
@@ -661,13 +676,16 @@ basic_forward_search (GtkSourceSearchContext *search,
const GtkTextIter *limit)
{
GtkTextIter begin_search = *iter;
+ GtkSourceSearchSettings *settings = get_settings (search);
+ const gchar *search_text = gtk_source_search_settings_get_search_text (settings);
+ GtkTextSearchFlags flags;
- if (search->priv->text == NULL)
+ if (search_text == NULL)
{
return FALSE;
}
- if (search->priv->regex_enabled)
+ if (gtk_source_search_settings_get_regex_enabled (settings))
{
return basic_forward_regex_search (search,
iter,
@@ -676,16 +694,18 @@ basic_forward_search (GtkSourceSearchContext *search,
limit);
}
+ flags = get_text_search_flags (search);
+
while (TRUE)
{
gboolean found = gtk_text_iter_forward_search (&begin_search,
- search->priv->text,
- search->priv->flags,
+ search_text,
+ flags,
match_start,
match_end,
limit);
- if (!found || !search->priv->at_word_boundaries)
+ if (!found || !gtk_source_search_settings_get_at_word_boundaries (settings))
{
return found;
}
@@ -796,13 +816,16 @@ basic_backward_search (GtkSourceSearchContext *search,
const GtkTextIter *limit)
{
GtkTextIter begin_search = *iter;
+ GtkSourceSearchSettings *settings = get_settings (search);
+ const gchar *search_text = gtk_source_search_settings_get_search_text (settings);
+ GtkTextSearchFlags flags;
- if (search->priv->text == NULL)
+ if (search_text == NULL)
{
return FALSE;
}
- if (search->priv->regex_enabled)
+ if (gtk_source_search_settings_get_regex_enabled (settings))
{
return basic_backward_regex_search (search,
iter,
@@ -811,16 +834,18 @@ basic_backward_search (GtkSourceSearchContext *search,
limit);
}
+ flags = get_text_search_flags (search);
+
while (TRUE)
{
gboolean found = gtk_text_iter_backward_search (&begin_search,
- search->priv->text,
- search->priv->flags,
+ search_text,
+ flags,
match_start,
match_end,
limit);
- if (!found || !search->priv->at_word_boundaries)
+ if (!found || !gtk_source_search_settings_get_at_word_boundaries (settings))
{
return found;
}
@@ -858,12 +883,14 @@ smart_forward_search_async_step (GtkSourceSearchContext *search,
GtkTextIter region_start = *start_at;
GtkTextRegion *region = NULL;
ForwardBackwardData *task_data;
+ GtkSourceSearchSettings *settings = get_settings (search);
+ const gchar *search_text = gtk_source_search_settings_get_search_text (settings);
if (gtk_text_iter_is_end (start_at))
{
- if (search->priv->text != NULL &&
+ if (search_text != NULL &&
!*wrapped_around &&
- search->priv->wrap_around)
+ gtk_source_search_settings_get_wrap_around (settings))
{
gtk_text_buffer_get_start_iter (search->priv->buffer, start_at);
*wrapped_around = TRUE;
@@ -996,12 +1023,14 @@ smart_backward_search_async_step (GtkSourceSearchContext *search,
GtkTextIter region_end = *start_at;
GtkTextRegion *region = NULL;
ForwardBackwardData *task_data;
+ GtkSourceSearchSettings *settings = get_settings (search);
+ const gchar *search_text = gtk_source_search_settings_get_search_text (settings);
if (gtk_text_iter_is_start (start_at))
{
- if (search->priv->text != NULL &&
+ if (search_text != NULL &&
!*wrapped_around &&
- search->priv->wrap_around)
+ gtk_source_search_settings_get_wrap_around (settings))
{
gtk_text_buffer_get_end_iter (search->priv->buffer, start_at);
*wrapped_around = TRUE;
@@ -1277,6 +1306,8 @@ smart_forward_search_without_scanning (GtkSourceSearchContext *search,
const GtkTextIter *stop_at)
{
GtkTextIter iter;
+ GtkSourceSearchSettings *settings = get_settings (search);
+ const gchar *search_text = gtk_source_search_settings_get_search_text (settings);
g_assert (start_at != NULL);
g_assert (match_start != NULL);
@@ -1285,7 +1316,7 @@ smart_forward_search_without_scanning (GtkSourceSearchContext *search,
iter = *start_at;
- if (search->priv->text == NULL)
+ if (search_text == NULL)
{
return FALSE;
}
@@ -1405,6 +1436,8 @@ scan_subregion (GtkSourceSearchContext *search,
GtkTextIter iter;
GtkTextIter *limit;
gboolean found = TRUE;
+ GtkSourceSearchSettings *settings = get_settings (search);
+ const gchar *search_text = gtk_source_search_settings_get_search_text (settings);
if (search->priv->found_tag == NULL)
{
@@ -1439,7 +1472,7 @@ scan_subregion (GtkSourceSearchContext *search,
gtk_text_region_subtract (search->priv->task_region, start, end);
}
- if (search->priv->text == NULL)
+ if (search_text == NULL)
{
/* We have removed the found_tag, we are done. */
return;
@@ -1966,7 +1999,9 @@ idle_scan_regex_search (GtkSourceSearchContext *search)
static gboolean
idle_scan_cb (GtkSourceSearchContext *search)
{
- return search->priv->regex_enabled ?
+ GtkSourceSearchSettings *settings = get_settings (search);
+
+ return gtk_source_search_settings_get_regex_enabled (settings) ?
idle_scan_regex_search (search) :
idle_scan_normal_search (search);
}
@@ -2044,8 +2079,10 @@ smart_forward_search (GtkSourceSearchContext *search,
GtkTextIter *match_end)
{
GtkTextIter iter = *start_at;
+ GtkSourceSearchSettings *settings = get_settings (search);
+ const gchar *search_text = gtk_source_search_settings_get_search_text (settings);
- if (search->priv->text == NULL)
+ if (search_text == NULL)
{
return FALSE;
}
@@ -2132,8 +2169,10 @@ smart_backward_search (GtkSourceSearchContext *search,
GtkTextIter *match_end)
{
GtkTextIter iter = *start_at;
+ GtkSourceSearchSettings *settings = get_settings (search);
+ const gchar *search_text = gtk_source_search_settings_get_search_text (settings);
- if (search->priv->text == NULL)
+ if (search_text == NULL)
{
return FALSE;
}
@@ -2194,6 +2233,8 @@ static void
update_regex (GtkSourceSearchContext *search)
{
gboolean regex_error_changed = FALSE;
+ GtkSourceSearchSettings *settings = get_settings (search);
+ const gchar *search_text = gtk_source_search_settings_get_search_text (settings);
if (search->priv->regex != NULL)
{
@@ -2208,21 +2249,22 @@ update_regex (GtkSourceSearchContext *search)
regex_error_changed = TRUE;
}
- if (search->priv->regex_enabled && search->priv->text != NULL)
+ if (search_text != NULL &&
+ gtk_source_search_settings_get_regex_enabled (settings))
{
GRegexCompileFlags compile_flags = G_REGEX_OPTIMIZE | G_REGEX_MULTILINE;
- gchar *pattern = search->priv->text;
+ gchar *pattern = (gchar *)search_text;
search->priv->text_nb_lines = 0;
- if (search->priv->flags & GTK_TEXT_SEARCH_CASE_INSENSITIVE)
+ if (!gtk_source_search_settings_get_case_sensitive (settings))
{
compile_flags |= G_REGEX_CASELESS;
}
- if (search->priv->at_word_boundaries)
+ if (gtk_source_search_settings_get_at_word_boundaries (settings))
{
- pattern = g_strdup_printf ("\\b%s\\b", search->priv->text);
+ pattern = g_strdup_printf ("\\b%s\\b", search_text);
}
search->priv->regex = g_regex_new (pattern,
@@ -2235,7 +2277,7 @@ update_regex (GtkSourceSearchContext *search)
regex_error_changed = TRUE;
}
- if (search->priv->at_word_boundaries)
+ if (gtk_source_search_settings_get_at_word_boundaries (settings))
{
g_free (pattern);
}
@@ -2272,10 +2314,13 @@ insert_text_before_cb (GtkSourceSearchContext *search,
gchar *text,
gint length)
{
+ GtkSourceSearchSettings *settings = get_settings (search);
+ const gchar *search_text = gtk_source_search_settings_get_search_text (settings);
+
clear_task (search);
- if (!search->priv->regex_enabled &&
- search->priv->text != NULL)
+ if (search_text != NULL &&
+ !gtk_source_search_settings_get_regex_enabled (settings))
{
GtkTextIter start = *location;
GtkTextIter end = *location;
@@ -2291,7 +2336,9 @@ insert_text_after_cb (GtkSourceSearchContext *search,
gchar *text,
gint length)
{
- if (search->priv->regex_enabled)
+ GtkSourceSearchSettings *settings = get_settings (search);
+
+ if (gtk_source_search_settings_get_regex_enabled (settings))
{
update (search);
}
@@ -2316,10 +2363,12 @@ delete_range_before_cb (GtkSourceSearchContext *search,
{
GtkTextIter start_buffer;
GtkTextIter end_buffer;
+ GtkSourceSearchSettings *settings = get_settings (search);
+ const gchar *search_text = gtk_source_search_settings_get_search_text (settings);
clear_task (search);
- if (search->priv->regex_enabled)
+ if (gtk_source_search_settings_get_regex_enabled (settings))
{
return;
}
@@ -2334,7 +2383,7 @@ delete_range_before_cb (GtkSourceSearchContext *search,
return;
}
- if (search->priv->text != NULL)
+ if (search_text != NULL)
{
GtkTextIter start = *delete_start;
GtkTextIter end = *delete_end;
@@ -2352,7 +2401,9 @@ delete_range_after_cb (GtkSourceSearchContext *search,
GtkTextIter *start,
GtkTextIter *end)
{
- if (search->priv->regex_enabled)
+ GtkSourceSearchSettings *settings = get_settings (search);
+
+ if (gtk_source_search_settings_get_regex_enabled (settings))
{
update (search);
}
@@ -2442,7 +2493,7 @@ search_text_updated (GtkSourceSearchContext *search)
}
else
{
- gchar *text = gtk_source_search_settings_get_search_text (settings);
+ const gchar *text = gtk_source_search_settings_get_search_text (settings);
search->priv->text_nb_lines = compute_number_of_lines (text);
}
}
@@ -2476,7 +2527,8 @@ gtk_source_search_context_dispose (GObject *object)
clear_search (search);
- search->priv->buffer = NULL;
+ g_clear_object (&search->priv->buffer);
+ g_clear_object (&search->priv->settings);
G_OBJECT_CLASS (gtk_source_search_context_parent_class)->dispose (object);
}
@@ -2486,8 +2538,6 @@ gtk_source_search_context_finalize (GObject *object)
{
GtkSourceSearchContext *search = GTK_SOURCE_SEARCH_CONTEXT (object);
- g_free (search->priv->text);
-
if (search->priv->regex != NULL)
{
g_regex_unref (search->priv->regex);
@@ -2524,11 +2574,11 @@ gtk_source_search_context_get_property (GObject *object,
break;
case PROP_OCCURRENCES_COUNT:
- g_value_set_int (value, gtk_source_search_context_get_occurrences_count
(source_buffer->priv->search));
+ g_value_set_int (value, gtk_source_search_context_get_occurrences_count (search));
break;
case PROP_REGEX_ERROR:
- g_value_set_pointer (value, gtk_source_search_context_get_regex_error
(source_buffer->priv->search));
+ g_value_set_pointer (value, gtk_source_search_context_get_regex_error (search));
break;
default:
@@ -2576,21 +2626,6 @@ gtk_source_search_context_class_init (GtkSourceSearchContextClass *klass)
object_class->set_property = gtk_source_search_context_set_property;
/**
- * GtkSourceSearchContext:highlight:
- *
- * Whether to highlight search occurrences in the buffer.
- *
- * Since: 3.10
- */
- g_object_class_install_property (object_class,
- PROP_HIGHLIGHT,
- g_param_spec_boolean ("highlight",
- _("Highlight"),
- _("Whether to highlight search occurrences"),
- TRUE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
- /**
* GtkSourceSearchContext:buffer:
*
* The #GtkSourceBuffer associated to the search context.
@@ -2876,6 +2911,7 @@ gtk_source_search_context_forward (GtkSourceSearchContext *search,
GtkTextIter *match_end)
{
gboolean found;
+ GtkSourceSearchSettings *settings;
g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), FALSE);
g_return_val_if_fail (iter != NULL, FALSE);
@@ -2885,9 +2921,11 @@ gtk_source_search_context_forward (GtkSourceSearchContext *search,
return FALSE;
}
+ settings = get_settings (search);
+
found = smart_forward_search (search, iter, match_start, match_end);
- if (!found && search->priv->wrap_around)
+ if (!found && gtk_source_search_settings_get_wrap_around (settings))
{
GtkTextIter start_iter;
gtk_text_buffer_get_start_iter (search->priv->buffer, &start_iter);
@@ -3016,6 +3054,7 @@ gtk_source_search_context_backward (GtkSourceSearchContext *search,
GtkTextIter *match_end)
{
gboolean found;
+ GtkSourceSearchSettings *settings;
g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), FALSE);
g_return_val_if_fail (iter != NULL, FALSE);
@@ -3025,9 +3064,11 @@ gtk_source_search_context_backward (GtkSourceSearchContext *search,
return FALSE;
}
+ settings = get_settings (search);
+
found = smart_backward_search (search, iter, match_start, match_end);
- if (!found && search->priv->wrap_around)
+ if (!found && gtk_source_search_settings_get_wrap_around (settings))
{
GtkTextIter end_iter;
@@ -3181,6 +3222,7 @@ gtk_source_search_context_replace (GtkSourceSearchContext *search,
{
GtkTextIter start;
GtkTextIter end;
+ GtkSourceSearchSettings *settings;
g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), FALSE);
g_return_val_if_fail (match_start != NULL, FALSE);
@@ -3192,6 +3234,8 @@ gtk_source_search_context_replace (GtkSourceSearchContext *search,
return FALSE;
}
+ settings = get_settings (search);
+
if (!smart_forward_search (search, match_start, &start, &end))
{
return FALSE;
@@ -3203,7 +3247,7 @@ gtk_source_search_context_replace (GtkSourceSearchContext *search,
return FALSE;
}
- if (search->priv->regex_enabled)
+ if (gtk_source_search_settings_get_regex_enabled (settings))
{
return regex_replace (search, &start, &end, replace);
}
@@ -3243,6 +3287,7 @@ gtk_source_search_context_replace_all (GtkSourceSearchContext *search,
guint nb_matches_replaced = 0;
gboolean highlight_matching_brackets;
gboolean has_regex_references = FALSE;
+ GtkSourceSearchSettings *settings;
g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), 0);
g_return_val_if_fail (replace != NULL, 0);
@@ -3252,7 +3297,9 @@ gtk_source_search_context_replace_all (GtkSourceSearchContext *search,
return 0;
}
- if (search->priv->regex_enabled &&
+ settings = get_settings (search);
+
+ if (gtk_source_search_settings_get_regex_enabled (settings) &&
!g_regex_check_replacement (replace, &has_regex_references, NULL))
{
return 0;
@@ -3319,6 +3366,7 @@ _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
gboolean synchronous)
{
GtkTextRegion *region_to_highlight;
+ GtkSourceSearchSettings *settings;
g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search));
g_return_if_fail (start != NULL);
@@ -3330,6 +3378,8 @@ _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
return;
}
+ settings = get_settings (search);
+
region_to_highlight = gtk_text_region_intersect (search->priv->scan_region,
start,
end);
@@ -3361,7 +3411,7 @@ _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
return;
}
- if (search->priv->regex_enabled)
+ if (gtk_source_search_settings_get_regex_enabled (settings))
{
GtkTextIter start;
diff --git a/gtksourceview/gtksourcesearchsettings.c b/gtksourceview/gtksourcesearchsettings.c
index 869e2a6..14b7729 100644
--- a/gtksourceview/gtksourcesearchsettings.c
+++ b/gtksourceview/gtksourcesearchsettings.c
@@ -20,6 +20,7 @@
*/
#include "gtksourcesearchsettings.h"
+#include "gtksourceview-i18n.h"
enum
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]