[gtksourceview] ContextEngine: set a GtkTextTag name for context classes
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] ContextEngine: set a GtkTextTag name for context classes
- Date: Sat, 9 May 2015 14:11:09 +0000 (UTC)
commit a3e289b2cde7f6cfb62cc9c24f64d8d2a8df39ad
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri May 8 11:57:17 2015 +0200
ContextEngine: set a GtkTextTag name for context classes
The use case is for GtkSpell to use the no-spell-check context class
without a hard-dependency on GtkSourceView (GtkSpell only depends on
GTK+).
There should be no visible performance difference. The tag is just
inserted in a hash table in the tag table.
https://bugzilla.gnome.org/show_bug.cgi?id=749100
gtksourceview/gtksourcebuffer.c | 11 +++++++++++
gtksourceview/gtksourcecontextengine.c | 8 +++++++-
2 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index 7663a86..7797e7f 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -106,6 +106,17 @@
* Custom language definition files can create their own context classes,
* since the functions like gtk_source_buffer_iter_has_context_class() take
* a string parameter as the context class.
+ *
+ * Each context class has an associated #GtkTextTag with the name
+ * <emphasis>gtksourceview:context-classes:<name></emphasis>. For example to
+ * retrieve the #GtkTextTag for the string context class, one can write:
+ * |[
+ * GtkTextTagTable *tag_table;
+ * GtkTextTag *tag;
+ *
+ * tag_table = gtk_text_buffer_get_tag_table (buffer);
+ * tag = gtk_text_tag_table_lookup (tag_table, "gtksourceview:context-classes:string");
+ * ]|
*/
/*
diff --git a/gtksourceview/gtksourcecontextengine.c b/gtksourceview/gtksourcecontextengine.c
index 7f3f504..0cfea5b 100644
--- a/gtksourceview/gtksourcecontextengine.c
+++ b/gtksourceview/gtksourcecontextengine.c
@@ -979,7 +979,11 @@ get_context_class_tag (GtkSourceContextEngine *ce,
if (ret == NULL)
{
- ret = gtk_text_buffer_create_tag (ce->priv->buffer, NULL, NULL);
+ gchar *tag_name;
+
+ 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),
@@ -988,6 +992,8 @@ get_context_class_tag (GtkSourceContextEngine *ce,
g_hash_table_insert (ce->priv->context_classes,
g_strdup (name),
ret);
+
+ g_free (tag_name);
}
return ret;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]