[gtksourceview/wip/regex-search: 7/9] Search: move properties from Buffer to SearchContext



commit 8280fc0d648df4ed07e6baa90b715150c4d8097c
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jul 27 21:30:24 2013 +0200

    Search: move properties from Buffer to SearchContext

 gtksourceview/gtksourcebuffer.c        |  204 +--------------------------
 gtksourceview/gtksourcesearchcontext.c |  249 ++++++++++++++++++++++++++++++++
 2 files changed, 251 insertions(+), 202 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index 7bbf348..56f35bc 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -148,6 +148,7 @@
 #define PROFILE(x)
 #endif
 
+/* For bracket matching */
 #define MAX_CHARS_BEFORE_FINDING_A_MATCH    10000
 
 #define TAG_CONTEXT_CLASS_NAME "GtkSourceViewTagContextClassName"
@@ -169,18 +170,10 @@ enum {
        PROP_CAN_REDO,
        PROP_HIGHLIGHT_SYNTAX,
        PROP_HIGHLIGHT_MATCHING_BRACKETS,
-       PROP_HIGHLIGHT_SEARCH,
        PROP_MAX_UNDO_LEVELS,
        PROP_LANGUAGE,
        PROP_STYLE_SCHEME,
-       PROP_UNDO_MANAGER,
-       PROP_SEARCH_TEXT,
-       PROP_SEARCH_OCCURRENCES_COUNT,
-       PROP_CASE_SENSITIVE_SEARCH,
-       PROP_SEARCH_AT_WORD_BOUNDARIES,
-       PROP_SEARCH_WRAP_AROUND,
-       PROP_REGEX_SEARCH,
-       PROP_REGEX_SEARCH_ERROR
+       PROP_UNDO_MANAGER
 };
 
 struct _GtkSourceBufferPrivate
@@ -331,19 +324,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
                                                               G_PARAM_READWRITE));
 
        /**
-        * GtkSourceBuffer:highlight-search:
-        *
-        * Whether to highlight search occurrences in the buffer.
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_HIGHLIGHT_SEARCH,
-                                        g_param_spec_boolean ("highlight-search",
-                                                              _("Highlight Search"),
-                                                              _("Whether to highlight search occurrences"),
-                                                              TRUE,
-                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
-       /**
         * GtkSourceBuffer:max-undo-levels:
         *
         * Number of undo levels for the buffer. -1 means no limit. This property
@@ -410,124 +390,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
                                                              GTK_SOURCE_TYPE_UNDO_MANAGER,
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
-       /**
-        * GtkSourceBuffer:search-text:
-        *
-        * A search string, or %NULL if the search is disabled. If the regular
-        * expression search is enabled, #GtkSourceBuffer:search-text is the
-        * pattern.
-        *
-        * Since: 3.10
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_SEARCH_TEXT,
-                                        g_param_spec_string ("search-text",
-                                                             _("Search text"),
-                                                             _("The text to search"),
-                                                             NULL,
-                                                             G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
-       /**
-        * GtkSourceBuffer:search-occurrences-count:
-        *
-        * The total number of search occurrences. If the search is disabled,
-        * the value is 0. If the buffer is not already fully scanned, the value
-        * is -1.
-        *
-        * Since: 3.10
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_SEARCH_OCCURRENCES_COUNT,
-                                        g_param_spec_int ("search-occurrences-count",
-                                                          _("Search occurrences count"),
-                                                          _("Total number of search occurrences"),
-                                                          -1,
-                                                          G_MAXINT,
-                                                          0,
-                                                          G_PARAM_READABLE));
-
-       /**
-        * GtkSourceBuffer:case-sensitive-search:
-        *
-        * Whether the search is case sensitive.
-        *
-        * Since: 3.10
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_CASE_SENSITIVE_SEARCH,
-                                        g_param_spec_boolean ("case-sensitive-search",
-                                                              _("Case sensitive search"),
-                                                              _("Case sensitive search"),
-                                                              FALSE,
-                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
-       /**
-        * GtkSourceBuffer:search-at-word-boundaries:
-        *
-        * If %TRUE, a search match must start and end a word. The match can
-        * span multiple words.
-        *
-        * Since: 3.10
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_SEARCH_AT_WORD_BOUNDARIES,
-                                        g_param_spec_boolean ("search-at-word-boundaries",
-                                                              _("Search at word boundaries"),
-                                                              _("Search at word boundaries"),
-                                                              FALSE,
-                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
-       /**
-        * GtkSourceBuffer:search-wrap-around:
-        *
-        * For a forward search, continue at the beginning of the buffer if no
-        * search occurrence is found. For a backward search, continue at the
-        * end of the buffer.
-        *
-        * Since: 3.10
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_SEARCH_WRAP_AROUND,
-                                        g_param_spec_boolean ("search-wrap-around",
-                                                              _("Search: wrap around"),
-                                                              _("Search: wrap around"),
-                                                              TRUE,
-                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
-       /**
-        * GtkSourceBuffer:regex-search:
-        *
-        * Search by regular expressions with #GtkSourceBuffer:search-text as
-        * the pattern.
-        *
-        * Since: 3.10
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_REGEX_SEARCH,
-                                        g_param_spec_boolean ("regex-search",
-                                                              _("Regex search"),
-                                                              _("Search by regular expression"),
-                                                              FALSE,
-                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
-       /**
-        * GtkSourceBuffer:regex-search-error:
-        *
-        * If the regex search pattern doesn't follow all the rules,
-        * #GtkSourceBuffer:regex-search-error will be set. If the pattern
-        * is valid, #GtkSourceBuffer:regex-search-error is %NULL.
-        *
-        * Free with g_error_free().
-        *
-        * Since: 3.10
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_REGEX_SEARCH_ERROR,
-                                        g_param_spec_pointer ("regex-search-error",
-                                                              _("Regex search error"),
-                                                              _("Regular expression search error"),
-                                                              G_PARAM_READABLE));
-
        param_types[0] = GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE;
        param_types[1] = GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE;
 
@@ -737,11 +599,6 @@ gtk_source_buffer_set_property (GObject      *object,
                                                                           g_value_get_boolean (value));
                        break;
 
-               case PROP_HIGHLIGHT_SEARCH:
-                       gtk_source_search_context_set_highlight (source_buffer->priv->search,
-                                                                g_value_get_boolean (value));
-                       break;
-
                case PROP_MAX_UNDO_LEVELS:
                        gtk_source_buffer_set_max_undo_levels (source_buffer,
                                                               g_value_get_int (value));
@@ -762,31 +619,6 @@ gtk_source_buffer_set_property (GObject      *object,
                                                            g_value_get_object (value));
                        break;
 
-               case PROP_SEARCH_TEXT:
-                       gtk_source_search_context_set_text (source_buffer->priv->search,
-                                                           g_value_get_string (value));
-                       break;
-
-               case PROP_CASE_SENSITIVE_SEARCH:
-                       gtk_source_search_context_set_case_sensitive (source_buffer->priv->search,
-                                                                     g_value_get_boolean (value));
-                       break;
-
-               case PROP_SEARCH_AT_WORD_BOUNDARIES:
-                       gtk_source_search_context_set_at_word_boundaries (source_buffer->priv->search,
-                                                                         g_value_get_boolean (value));
-                       break;
-
-               case PROP_SEARCH_WRAP_AROUND:
-                       gtk_source_search_context_set_wrap_around (source_buffer->priv->search,
-                                                                  g_value_get_boolean (value));
-                       break;
-
-               case PROP_REGEX_SEARCH:
-                       gtk_source_search_context_set_regex_enabled (source_buffer->priv->search,
-                                                                    g_value_get_boolean (value));
-                       break;
-
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -817,10 +649,6 @@ gtk_source_buffer_get_property (GObject    *object,
                                             source_buffer->priv->highlight_brackets);
                        break;
 
-               case PROP_HIGHLIGHT_SEARCH:
-                       g_value_set_boolean (value, gtk_source_search_context_get_highlight 
(source_buffer->priv->search));
-                       break;
-
                case PROP_MAX_UNDO_LEVELS:
                        g_value_set_int (value,
                                         source_buffer->priv->max_undo_levels);
@@ -846,34 +674,6 @@ gtk_source_buffer_get_property (GObject    *object,
                        g_value_set_object (value, source_buffer->priv->undo_manager);
                        break;
 
-               case PROP_SEARCH_TEXT:
-                       g_value_set_string (value, gtk_source_search_context_get_text 
(source_buffer->priv->search));
-                       break;
-
-               case PROP_SEARCH_OCCURRENCES_COUNT:
-                       g_value_set_int (value, gtk_source_search_context_get_occurrences_count 
(source_buffer->priv->search));
-                       break;
-
-               case PROP_CASE_SENSITIVE_SEARCH:
-                       g_value_set_boolean (value, gtk_source_search_context_get_case_sensitive 
(source_buffer->priv->search));
-                       break;
-
-               case PROP_SEARCH_AT_WORD_BOUNDARIES:
-                       g_value_set_boolean (value, gtk_source_search_context_get_at_word_boundaries 
(source_buffer->priv->search));
-                       break;
-
-               case PROP_SEARCH_WRAP_AROUND:
-                       g_value_set_boolean (value, gtk_source_search_context_get_wrap_around 
(source_buffer->priv->search));
-                       break;
-
-               case PROP_REGEX_SEARCH:
-                       g_value_set_boolean (value, gtk_source_search_context_get_regex_enabled 
(source_buffer->priv->search));
-                       break;
-
-               case PROP_REGEX_SEARCH_ERROR:
-                       g_value_set_pointer (value, gtk_source_search_context_get_regex_error 
(source_buffer->priv->search));
-                       break;
-
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
diff --git a/gtksourceview/gtksourcesearchcontext.c b/gtksourceview/gtksourcesearchcontext.c
index 2544399..fffaa4c 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -183,6 +183,19 @@
  */
 #define SCAN_BATCH_SIZE 100
 
+enum
+{
+       PROP_0,
+       PROP_HIGHLIGHT,
+       PROP_SEARCH_TEXT,
+       PROP_OCCURRENCES_COUNT,
+       PROP_CASE_SENSITIVE,
+       PROP_AT_WORD_BOUNDARIES,
+       PROP_WRAP_AROUND,
+       PROP_REGEX,
+       PROP_REGEX_ERROR
+};
+
 struct _GtkSourceSearchContextPrivate
 {
        GtkTextBuffer *buffer;
@@ -2405,12 +2418,248 @@ gtk_source_search_context_finalize (GObject *object)
 }
 
 static void
+gtk_source_search_context_get_property (GObject    *object,
+                                       guint       prop_id,
+                                       GValue     *value,
+                                       GParamSpec *pspec)
+{
+       GtkSourceSearchContext *search;
+
+       g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (object));
+
+       search = GTK_SOURCE_SEARCH_CONTEXT (object);
+
+       switch (prop_id)
+       {
+               case PROP_HIGHLIGHT:
+                       g_value_set_boolean (value, gtk_source_search_context_get_highlight 
(source_buffer->priv->search));
+                       break;
+
+               case PROP_SEARCH_TEXT:
+                       g_value_set_string (value, gtk_source_search_context_get_text 
(source_buffer->priv->search));
+                       break;
+
+               case PROP_OCCURRENCES_COUNT:
+                       g_value_set_int (value, gtk_source_search_context_get_occurrences_count 
(source_buffer->priv->search));
+                       break;
+
+               case PROP_CASE_SENSITIVE:
+                       g_value_set_boolean (value, gtk_source_search_context_get_case_sensitive 
(source_buffer->priv->search));
+                       break;
+
+               case PROP_AT_WORD_BOUNDARIES:
+                       g_value_set_boolean (value, gtk_source_search_context_get_at_word_boundaries 
(source_buffer->priv->search));
+                       break;
+
+               case PROP_WRAP_AROUND:
+                       g_value_set_boolean (value, gtk_source_search_context_get_wrap_around 
(source_buffer->priv->search));
+                       break;
+
+               case PROP_REGEX:
+                       g_value_set_boolean (value, gtk_source_search_context_get_regex_enabled 
(source_buffer->priv->search));
+                       break;
+
+               case PROP_REGEX_ERROR:
+                       g_value_set_pointer (value, gtk_source_search_context_get_regex_error 
(source_buffer->priv->search));
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
+gtk_source_search_context_set_property (GObject      *object,
+                                       guint         prop_id,
+                                       const GValue *value,
+                                       GParamSpec   *pspec)
+{
+       GtkSourceSearchContext *search;
+
+       g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (object));
+
+       search = GTK_SOURCE_SEARCH_CONTEXT (object);
+
+       switch (prop_id)
+       {
+               case PROP_HIGHLIGHT:
+                       gtk_source_search_context_set_highlight (source_buffer->priv->search,
+                                                                g_value_get_boolean (value));
+                       break;
+
+               case PROP_SEARCH_TEXT:
+                       gtk_source_search_context_set_text (source_buffer->priv->search,
+                                                           g_value_get_string (value));
+                       break;
+
+               case PROP_CASE_SENSITIVE:
+                       gtk_source_search_context_set_case_sensitive (source_buffer->priv->search,
+                                                                     g_value_get_boolean (value));
+                       break;
+
+               case PROP_AT_WORD_BOUNDARIES:
+                       gtk_source_search_context_set_at_word_boundaries (source_buffer->priv->search,
+                                                                         g_value_get_boolean (value));
+                       break;
+
+               case PROP_WRAP_AROUND:
+                       gtk_source_search_context_set_wrap_around (source_buffer->priv->search,
+                                                                  g_value_get_boolean (value));
+                       break;
+
+               case PROP_REGEX:
+                       gtk_source_search_context_set_regex_enabled (source_buffer->priv->search,
+                                                                    g_value_get_boolean (value));
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
 gtk_source_search_context_class_init (GtkSourceSearchContextClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
        object_class->dispose = gtk_source_search_context_dispose;
        object_class->finalize = gtk_source_search_context_finalize;
+       object_class->get_property = gtk_source_search_context_get_property;
+       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:search-text:
+        *
+        * A search string, or %NULL if the search is disabled. If the regular
+        * expression search is enabled, #GtkSourceSearchContext:search-text is
+        * the pattern.
+        *
+        * Since: 3.10
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_SEARCH_TEXT,
+                                        g_param_spec_string ("search-text",
+                                                             _("Search text"),
+                                                             _("The text to search"),
+                                                             NULL,
+                                                             G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+       /**
+        * GtkSourceSearchContext:occurrences-count:
+        *
+        * The total number of search occurrences. If the search is disabled,
+        * the value is 0. If the buffer is not already fully scanned, the value
+        * is -1.
+        *
+        * Since: 3.10
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_OCCURRENCES_COUNT,
+                                        g_param_spec_int ("occurrences-count",
+                                                          _("Occurrences count"),
+                                                          _("Total number of search occurrences"),
+                                                          -1,
+                                                          G_MAXINT,
+                                                          0,
+                                                          G_PARAM_READABLE));
+
+       /**
+        * GtkSourceSearchContext:case-sensitive:
+        *
+        * Whether the search is case sensitive.
+        *
+        * Since: 3.10
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_CASE_SENSITIVE,
+                                        g_param_spec_boolean ("case-sensitive",
+                                                              _("Case sensitive"),
+                                                              _("Case sensitive"),
+                                                              FALSE,
+                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+       /**
+        * GtkSourceSearchContext:at-word-boundaries:
+        *
+        * If %TRUE, a search match must start and end a word. The match can
+        * span multiple words.
+        *
+        * Since: 3.10
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_AT_WORD_BOUNDARIES,
+                                        g_param_spec_boolean ("at-word-boundaries",
+                                                              _("At word boundaries"),
+                                                              _("Search at word boundaries"),
+                                                              FALSE,
+                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+       /**
+        * GtkSourceSearchContext:wrap-around:
+        *
+        * For a forward search, continue at the beginning of the buffer if no
+        * search occurrence is found. For a backward search, continue at the
+        * end of the buffer.
+        *
+        * Since: 3.10
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_WRAP_AROUND,
+                                        g_param_spec_boolean ("wrap-around",
+                                                              _("Wrap around"),
+                                                              _("Wrap around"),
+                                                              TRUE,
+                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+       /**
+        * GtkSourceSearchContext:regex:
+        *
+        * Search by regular expressions with
+        * #GtkSourceSearchContext:search-text as the pattern.
+        *
+        * Since: 3.10
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_REGEX,
+                                        g_param_spec_boolean ("regex",
+                                                              _("Regex"),
+                                                              _("Search by regular expression"),
+                                                              FALSE,
+                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+       /**
+        * GtkSourceSearchContext:regex-error:
+        *
+        * If the regex search pattern doesn't follow all the rules, this
+        * property will be set. If the pattern is valid, the value is %NULL.
+        *
+        * Free with g_error_free().
+        *
+        * Since: 3.10
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_REGEX_ERROR,
+                                        g_param_spec_pointer ("regex-error",
+                                                              _("Regex error"),
+                                                              _("Regular expression error"),
+                                                              G_PARAM_READABLE));
 }
 
 static void


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