[gtksourceview] ContextEngine: don't set context class name to GObject data



commit 7feea2b3d2ad614b3870ce56eff4b3f8cb232727
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun May 10 13:49:41 2015 +0200

    ContextEngine: don't set context class name to GObject data
    
    The context class name is now present in the GtkTextTag name. It's
    better to avoid duplicated data.

 gtksourceview/gtksourcebuffer.c        |   22 ++++++++++++++--------
 gtksourceview/gtksourcecontextengine.c |    6 ------
 2 files changed, 14 insertions(+), 14 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index 7797e7f..21860df 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -141,8 +141,6 @@
 /* For bracket matching */
 #define MAX_CHARS_BEFORE_FINDING_A_MATCH    10000
 
-#define TAG_CONTEXT_CLASS_NAME "GtkSourceViewTagContextClassName"
-
 /* Signals */
 enum
 {
@@ -2212,8 +2210,10 @@ gtk_source_buffer_get_context_classes_at_iter (GtkSourceBuffer   *buffer,
                                                const GtkTextIter *iter)
 {
        GSList *tags;
-       GSList *item;
+       GSList *l;
        GPtrArray *ret;
+       const gchar prefix[] = "gtksourceview:context-classes:";
+       const gsize prefix_len = strlen (prefix);
 
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
        g_return_val_if_fail (iter != NULL, NULL);
@@ -2221,15 +2221,21 @@ gtk_source_buffer_get_context_classes_at_iter (GtkSourceBuffer   *buffer,
        tags = gtk_text_iter_get_tags (iter);
        ret = g_ptr_array_new ();
 
-       for (item = tags; item != NULL; item = g_slist_next (item))
+       for (l = tags; l != NULL; l = l->next)
        {
-               gchar const *name = g_object_get_data (G_OBJECT (item->data),
-                                                      TAG_CONTEXT_CLASS_NAME);
+               GtkTextTag *tag = l->data;
+               gchar *tag_name;
+
+               g_object_get (tag, "name", &tag_name, NULL);
 
-               if (name != NULL)
+               if (tag_name != NULL && g_str_has_prefix (tag_name, prefix))
                {
-                       g_ptr_array_add (ret, g_strdup (name));
+                       gchar *context_class_name = g_strdup (tag_name + prefix_len);
+
+                       g_ptr_array_add (ret, context_class_name);
                }
+
+               g_free (tag_name);
        }
 
        g_slist_free (tags);
diff --git a/gtksourceview/gtksourcecontextengine.c b/gtksourceview/gtksourcecontextengine.c
index 0cfea5b..1114ab6 100644
--- a/gtksourceview/gtksourcecontextengine.c
+++ b/gtksourceview/gtksourcecontextengine.c
@@ -118,8 +118,6 @@
 #define SEGMENT_IS_SIMPLE(s) CONTEXT_IS_SIMPLE ((s)->context)
 #define SEGMENT_IS_CONTAINER(s) CONTEXT_IS_CONTAINER ((s)->context)
 
-#define TAG_CONTEXT_CLASS_NAME "GtkSourceViewTagContextClassName"
-
 typedef struct _SubPatternDefinition SubPatternDefinition;
 typedef struct _SubPattern SubPattern;
 typedef struct _Segment Segment;
@@ -984,10 +982,6 @@ get_context_class_tag (GtkSourceContextEngine *ce,
                tag_name = g_strdup_printf ("gtksourceview:context-classes:%s", name);
 
                ret = gtk_text_buffer_create_tag (ce->priv->buffer, tag_name, NULL);
-               g_object_set_data_full (G_OBJECT (ret),
-                                       TAG_CONTEXT_CLASS_NAME,
-                                       g_strdup (name),
-                                       (GDestroyNotify)g_free);
 
                g_hash_table_insert (ce->priv->context_classes,
                                     g_strdup (name),


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