[gtksourceview] Add _gtk_source_language_get_style_info utility



commit 9acd915c794ec3bf1dbb84ee21801f9aa5ff724d
Author: Paolo Borelli <pborelli gnome org>
Date:   Mon Dec 26 21:21:21 2011 +0100

    Add _gtk_source_language_get_style_info utility
    
    Use a semi-private helper function instead of accessing the priv
    structure with an ugly macro.

 gtksourceview/gtksourcecontextengine.c    |   10 +++-------
 gtksourceview/gtksourcelanguage-private.h |    3 +++
 gtksourceview/gtksourcelanguage.c         |   10 ++++------
 3 files changed, 10 insertions(+), 13 deletions(-)
---
diff --git a/gtksourceview/gtksourcecontextengine.c b/gtksourceview/gtksourcecontextengine.c
index ed17331..f21c504 100644
--- a/gtksourceview/gtksourcecontextengine.c
+++ b/gtksourceview/gtksourcecontextengine.c
@@ -112,8 +112,6 @@
 #define SEGMENT_IS_SIMPLE(s) CONTEXT_IS_SIMPLE ((s)->context)
 #define SEGMENT_IS_CONTAINER(s) CONTEXT_IS_CONTAINER ((s)->context)
 
-#define ENGINE_STYLES_MAP(ce) ((ce)->priv->ctx_data->lang->priv->styles)
-
 #define TAG_CONTEXT_CLASS_NAME "GtkSourceViewTagContextClassName"
 
 typedef struct _RegexInfo RegexInfo;
@@ -639,9 +637,7 @@ set_tag_style (GtkSourceContextEngine *ce,
 	       const gchar            *style_id)
 {
 	GtkSourceStyle *style;
-
-	const char *map_to = style_id;
-
+	const char *map_to;
 	int guard = 0;
 
 	g_return_if_fail (GTK_IS_TEXT_TAG (tag));
@@ -652,6 +648,7 @@ set_tag_style (GtkSourceContextEngine *ce,
 	if (ce->priv->style_scheme == NULL)
 		return;
 
+	map_to = style_id;
 	style = gtk_source_style_scheme_get_style (ce->priv->style_scheme, style_id);
 
 	while (style == NULL)
@@ -668,10 +665,9 @@ set_tag_style (GtkSourceContextEngine *ce,
 
 		/* FIXME Style references really must be fixed, both parser for
 		 * sane use in lang files, and engine for safe use. */
-		info = g_hash_table_lookup (ENGINE_STYLES_MAP(ce), map_to);
+		info = _gtk_source_language_get_style_info (ce->priv->ctx_data->lang, map_to);
 
 		map_to = (info != NULL) ? info->map_to : NULL;
-
 		if (!map_to)
 			break;
 
diff --git a/gtksourceview/gtksourcelanguage-private.h b/gtksourceview/gtksourcelanguage-private.h
index d2ac49a..7460330 100644
--- a/gtksourceview/gtksourcelanguage-private.h
+++ b/gtksourceview/gtksourcelanguage-private.h
@@ -83,6 +83,9 @@ gboolean 		  _gtk_source_language_file_parse_version2	(GtkSourceLanguage
 
 GtkSourceEngine 	 *_gtk_source_language_create_engine		(GtkSourceLanguage	  *language);
 
+GtkSourceStyleInfo 	 *_gtk_source_language_get_style_info		(GtkSourceLanguage	  *language,
+									 const gchar              *style_id);
+
 /* Utility functions for GtkSourceStyleInfo */
 GtkSourceStyleInfo 	 *_gtk_source_style_info_new 			(const gchar		  *name,
 									 const gchar              *map_to);
diff --git a/gtksourceview/gtksourcelanguage.c b/gtksourceview/gtksourcelanguage.c
index 27dfd61..9479688 100644
--- a/gtksourceview/gtksourcelanguage.c
+++ b/gtksourceview/gtksourcelanguage.c
@@ -853,8 +853,8 @@ gtk_source_language_get_style_ids (GtkSourceLanguage *language)
 	return get_style_ids (language);
 }
 
-static GtkSourceStyleInfo *
-get_style_info (GtkSourceLanguage *language, const char *style_id)
+GtkSourceStyleInfo *
+_gtk_source_language_get_style_info (GtkSourceLanguage *language, const char *style_id)
 {
 	GtkSourceStyleInfo *info;
 
@@ -890,11 +890,9 @@ gtk_source_language_get_style_name (GtkSourceLanguage *language,
 	g_return_val_if_fail (language->priv->id != NULL, NULL);
 	g_return_val_if_fail (style_id != NULL, NULL);
 
-	info = get_style_info (language, style_id);
-	if (info == NULL)
-		return NULL;
+	info = _gtk_source_language_get_style_info (language, style_id);
 
-	return info->name;
+	return info ? info->name : NULL;
 }
 
 /* Utility functions for GtkSourceStyleInfo */



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