[gtksourceview/wip/search] SearchContext: add the "regex-state" property



commit d7a3ece82a613534d8db2d5b295b128a1c9d7bb3
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Aug 19 19:24:00 2013 +0200

    SearchContext: add the "regex-state" property
    
    It will be useful to know where to display the regex error in gedit.

 docs/reference/gtksourceview-3.0-sections.txt |    2 +
 gtksourceview/gtksourcesearchcontext.c        |   75 ++++++++++++++++++++++++-
 gtksourceview/gtksourcesearchcontext.h        |   20 +++++++
 3 files changed, 96 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index cde933e..33aa392 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -473,6 +473,7 @@ GtkSourcePrintCompositorClass
 <FILE>searchcontext</FILE>
 <TITLE>GtkSourceSearchContext</TITLE>
 GtkSourceSearchContext
+GtkSourceRegexSearchState
 gtk_source_search_context_new
 gtk_source_search_context_get_buffer
 gtk_source_search_context_get_settings
@@ -490,6 +491,7 @@ gtk_source_search_context_backward_finish
 gtk_source_search_context_replace
 gtk_source_search_context_replace_all
 gtk_source_search_context_get_regex_error
+gtk_source_search_context_get_regex_state
 <SUBSECTION Standard>
 GTK_SOURCE_IS_SEARCH_CONTEXT
 GTK_SOURCE_IS_SEARCH_CONTEXT_CLASS
diff --git a/gtksourceview/gtksourcesearchcontext.c b/gtksourceview/gtksourcesearchcontext.c
index 9202905..5b687de 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -28,6 +28,7 @@
 #include "gtksourceutils.h"
 #include "gtktextregion.h"
 #include "gtksourceview-i18n.h"
+#include "gtksourceview-typebuiltins.h"
 
 #include <string.h>
 
@@ -272,7 +273,8 @@ enum
        PROP_SETTINGS,
        PROP_HIGHLIGHT,
        PROP_OCCURRENCES_COUNT,
-       PROP_REGEX_ERROR
+       PROP_REGEX_ERROR,
+       PROP_REGEX_STATE
 };
 
 struct _GtkSourceSearchContextPrivate
@@ -306,6 +308,7 @@ struct _GtkSourceSearchContextPrivate
 
        GRegex *regex;
        GError *regex_error;
+       GtkSourceRegexSearchState regex_state;
 
        gint occurrences_count;
        gulong idle_scan_id;
@@ -541,6 +544,12 @@ clear_search (GtkSourceSearchContext *search)
                g_object_notify (G_OBJECT (search), "regex-error");
        }
 
+       if (search->priv->regex_state != GTK_SOURCE_REGEX_SEARCH_NO_ERROR)
+       {
+               search->priv->regex_state = GTK_SOURCE_REGEX_SEARCH_NO_ERROR;
+               g_object_notify (G_OBJECT (search), "regex-state");
+       }
+
        clear_task (search);
 
        search->priv->occurrences_count = 0;
@@ -716,7 +725,11 @@ basic_forward_regex_search (GtkSourceSearchContext *search,
 
        if (search->priv->regex_error != NULL)
        {
+               search->priv->regex_state = GTK_SOURCE_REGEX_SEARCH_MATCHING_ERROR;
+
                g_object_notify (G_OBJECT (search), "regex-error");
+               g_object_notify (G_OBJECT (search), "regex-state");
+
                found = FALSE;
        }
 
@@ -854,7 +867,11 @@ basic_backward_regex_search (GtkSourceSearchContext *search,
 
        if (search->priv->regex_error != NULL)
        {
+               search->priv->regex_state = GTK_SOURCE_REGEX_SEARCH_MATCHING_ERROR;
+
                g_object_notify (G_OBJECT (search), "regex-error");
+               g_object_notify (G_OBJECT (search), "regex-state");
+
                found = FALSE;
        }
 
@@ -1900,7 +1917,10 @@ regex_search_scan_segment (GtkSourceSearchContext *search,
 
        if (search->priv->regex_error != NULL)
        {
+               search->priv->regex_state = GTK_SOURCE_REGEX_SEARCH_MATCHING_ERROR;
+
                g_object_notify (G_OBJECT (search), "regex-error");
+               g_object_notify (G_OBJECT (search), "regex-state");
        }
 
        if (g_match_info_is_partial_match (match_info))
@@ -2292,6 +2312,7 @@ static void
 update_regex (GtkSourceSearchContext *search)
 {
        gboolean regex_error_changed = FALSE;
+       GtkSourceRegexSearchState new_regex_state = GTK_SOURCE_REGEX_SEARCH_NO_ERROR;
        const gchar *search_text = gtk_source_search_settings_get_search_text (search->priv->settings);
 
        if (search->priv->regex != NULL)
@@ -2332,6 +2353,7 @@ update_regex (GtkSourceSearchContext *search)
 
                if (search->priv->regex_error != NULL)
                {
+                       new_regex_state = GTK_SOURCE_REGEX_SEARCH_COMPILATION_ERROR;
                        regex_error_changed = TRUE;
                }
 
@@ -2345,6 +2367,12 @@ update_regex (GtkSourceSearchContext *search)
        {
                g_object_notify (G_OBJECT (search), "regex-error");
        }
+
+       if (search->priv->regex_state != new_regex_state)
+       {
+               search->priv->regex_state = new_regex_state;
+               g_object_notify (G_OBJECT (search), "regex-state");
+       }
 }
 
 static void
@@ -2652,6 +2680,10 @@ gtk_source_search_context_get_property (GObject    *object,
                        g_value_set_pointer (value, gtk_source_search_context_get_regex_error (search));
                        break;
 
+               case PROP_REGEX_STATE:
+                       g_value_set_enum (value, gtk_source_search_context_get_regex_state (search));
+                       break;
+
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -2780,12 +2812,30 @@ gtk_source_search_context_class_init (GtkSourceSearchContextClass *klass)
                                                               _("Regex error"),
                                                               _("Regular expression error"),
                                                               G_PARAM_READABLE));
+
+       /**
+        * GtkSourceSearchContext:regex-state:
+        *
+        * The regex search state.
+        *
+        * Since: 3.10
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_REGEX_STATE,
+                                        g_param_spec_enum ("regex-state",
+                                                           _("Regex state"),
+                                                           _("State of the regular expression search"),
+                                                           GTK_SOURCE_TYPE_REGEX_SEARCH_STATE,
+                                                           GTK_SOURCE_REGEX_SEARCH_NO_ERROR,
+                                                           G_PARAM_READABLE));
 }
 
 static void
 gtk_source_search_context_init (GtkSourceSearchContext *search)
 {
        search->priv = gtk_source_search_context_get_instance_private (search);
+
+       search->priv->regex_state = GTK_SOURCE_REGEX_SEARCH_NO_ERROR;
 }
 
 /**
@@ -2961,6 +3011,21 @@ gtk_source_search_context_get_regex_error (GtkSourceSearchContext *search)
 }
 
 /**
+ * gtk_source_search_context_get_regex_state:
+ * @search: a #GtkSourceSearchContext.
+ *
+ * Returns: the regex search state.
+ * Since: 3.10
+ */
+GtkSourceRegexSearchState
+gtk_source_search_context_get_regex_state (GtkSourceSearchContext *search)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), GTK_SOURCE_REGEX_SEARCH_NO_ERROR);
+
+       return search->priv->regex_state;
+}
+
+/**
  * gtk_source_search_context_get_occurrences_count:
  * @search: a #GtkSourceSearchContext.
  *
@@ -3377,7 +3442,11 @@ regex_replace (GtkSourceSearchContext *search,
 
        if (search->priv->regex_error != NULL)
        {
+               search->priv->regex_state = GTK_SOURCE_REGEX_SEARCH_REPLACE_ERROR;
+
                g_object_notify (G_OBJECT (search), "regex-error");
+               g_object_notify (G_OBJECT (search), "regex-state");
+
                g_free (subject_replaced);
                return FALSE;
        }
@@ -3503,7 +3572,11 @@ gtk_source_search_context_replace_all (GtkSourceSearchContext *search,
 
                if (search->priv->regex_error != NULL)
                {
+                       search->priv->regex_state = GTK_SOURCE_REGEX_SEARCH_REPLACE_ERROR;
+
                        g_object_notify (G_OBJECT (search), "regex-error");
+                       g_object_notify (G_OBJECT (search), "regex-state");
+
                        return 0;
                }
        }
diff --git a/gtksourceview/gtksourcesearchcontext.h b/gtksourceview/gtksourcesearchcontext.h
index 7891524..6182c54 100644
--- a/gtksourceview/gtksourcesearchcontext.h
+++ b/gtksourceview/gtksourcesearchcontext.h
@@ -51,6 +51,24 @@ struct _GtkSourceSearchContextClass
        gpointer padding[10];
 };
 
+/**
+ * GtkSourceRegexSearchState:
+ * @GTK_SOURCE_REGEX_SEARCH_NO_ERROR: everything is fine, or the regex search is
+ * disabled.
+ * @GTK_SOURCE_REGEX_SEARCH_COMPILATION_ERROR: pattern compilation error.
+ * @GTK_SOURCE_REGEX_SEARCH_MATCHING_ERROR: error while matching the buffer.
+ * @GTK_SOURCE_REGEX_SEARCH_REPLACE_ERROR: replace error.
+ *
+ * Regular expression search state.
+ */
+typedef enum
+{
+       GTK_SOURCE_REGEX_SEARCH_NO_ERROR,
+       GTK_SOURCE_REGEX_SEARCH_COMPILATION_ERROR,
+       GTK_SOURCE_REGEX_SEARCH_MATCHING_ERROR,
+       GTK_SOURCE_REGEX_SEARCH_REPLACE_ERROR
+} GtkSourceRegexSearchState;
+
 GType                   gtk_source_search_context_get_type                     (void) G_GNUC_CONST;
 
 GtkSourceSearchContext *gtk_source_search_context_new                          (GtkSourceBuffer         
*buffer,
@@ -70,6 +88,8 @@ void                   gtk_source_search_context_set_highlight                
(GtkSourceSearchContext  *searc
 
 GError                 *gtk_source_search_context_get_regex_error              (GtkSourceSearchContext  
*search);
 
+GtkSourceRegexSearchState gtk_source_search_context_get_regex_state            (GtkSourceSearchContext  
*search);
+
 gint                    gtk_source_search_context_get_occurrences_count        (GtkSourceSearchContext  
*search);
 
 gint                    gtk_source_search_context_get_occurrence_position      (GtkSourceSearchContext  
*search,


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