[gtksourceview] Introduce gtk_source_language_get_style_fallback



commit 051aaf5aca1c006b5a879622bd2c9fc26ab550bc
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Jan 7 14:57:50 2012 +0100

    Introduce gtk_source_language_get_style_fallback
    
    We need public access to this information since tools like a style
    scheme editor need to be able to resolve the style mappings.

 gtksourceview/gtksourcecontextengine.c    |    8 +-----
 gtksourceview/gtksourcelanguage-private.h |    3 --
 gtksourceview/gtksourcelanguage.c         |   36 ++++++++++++++++++++++++++--
 gtksourceview/gtksourcelanguage.h         |   11 +++++---
 4 files changed, 42 insertions(+), 16 deletions(-)
---
diff --git a/gtksourceview/gtksourcecontextengine.c b/gtksourceview/gtksourcecontextengine.c
index 7237c04..413ecdd 100644
--- a/gtksourceview/gtksourcecontextengine.c
+++ b/gtksourceview/gtksourcecontextengine.c
@@ -622,8 +622,6 @@ set_tag_style (GtkSourceContextEngine *ce,
 
 	while (style == NULL)
 	{
-		GtkSourceStyleInfo *info;
-
 		if (guard > MAX_STYLE_DEPENDENCY_DEPTH)
 		{
 			g_warning ("Potential circular dependency between styles detected for style '%s'", style_id);
@@ -634,10 +632,8 @@ 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 = _gtk_source_language_get_style_info (ce->priv->ctx_data->lang, map_to);
-
-		map_to = (info != NULL) ? info->map_to : NULL;
-		if (!map_to)
+		map_to = gtk_source_language_get_style_fallback (ce->priv->ctx_data->lang, map_to);
+		if (map_to == NULL)
 			break;
 
 		style = gtk_source_style_scheme_get_style (ce->priv->style_scheme, map_to);
diff --git a/gtksourceview/gtksourcelanguage-private.h b/gtksourceview/gtksourcelanguage-private.h
index 7460330..d2ac49a 100644
--- a/gtksourceview/gtksourcelanguage-private.h
+++ b/gtksourceview/gtksourcelanguage-private.h
@@ -83,9 +83,6 @@ 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 9479688..168a43a 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);
 }
 
-GtkSourceStyleInfo *
-_gtk_source_language_get_style_info (GtkSourceLanguage *language, const char *style_id)
+static GtkSourceStyleInfo *
+get_style_info (GtkSourceLanguage *language, const char *style_id)
 {
 	GtkSourceStyleInfo *info;
 
@@ -890,11 +890,41 @@ 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 = _gtk_source_language_get_style_info (language, style_id);
+	info = get_style_info (language, style_id);
 
 	return info ? info->name : NULL;
 }
 
+/**
+ * gtk_source_language_get_style_fallback:
+ * @language: a #GtkSourceLanguage.
+ * @style_id: a style ID.
+ *
+ * Returns the ID of the style to use if the specified @style_id
+ * is not present in the current style scheme.
+ *
+ * Returns: the ID of the style to use if the specified @style_id
+ * is not present in the current style scheme or %NULL if the style has
+ * no fallback defined.
+ * The returned string is owned by the @language and must not be modified.
+ *
+ * Since: 3.4
+ */
+const gchar *
+gtk_source_language_get_style_fallback (GtkSourceLanguage *language,
+					const gchar       *style_id)
+{
+	GtkSourceStyleInfo *info;
+
+	g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (language), NULL);
+	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);
+
+	return info ? info->map_to : NULL;
+}
+
 /* Utility functions for GtkSourceStyleInfo */
 
 GtkSourceStyleInfo *
diff --git a/gtksourceview/gtksourcelanguage.h b/gtksourceview/gtksourcelanguage.h
index 3c78641..d3db704 100644
--- a/gtksourceview/gtksourcelanguage.h
+++ b/gtksourceview/gtksourcelanguage.h
@@ -49,18 +49,18 @@ struct _GtkSourceLanguage
 
 struct _GtkSourceLanguageClass
 {
-	GObjectClass              parent_class;
+	GObjectClass parent_class;
 
 	/* Padding for future expansion */
 	void (*_gtk_source_reserved1) (void);
 	void (*_gtk_source_reserved2) (void);
 };
 
-GType             gtk_source_language_get_type 		(void) G_GNUC_CONST;
+GType		  gtk_source_language_get_type 		(void) G_GNUC_CONST;
 
-const gchar 	 *gtk_source_language_get_id		(GtkSourceLanguage *language);
+const gchar	 *gtk_source_language_get_id		(GtkSourceLanguage *language);
 
-const gchar 	 *gtk_source_language_get_name		(GtkSourceLanguage *language);
+const gchar	 *gtk_source_language_get_name		(GtkSourceLanguage *language);
 
 const gchar	 *gtk_source_language_get_section	(GtkSourceLanguage *language);
 
@@ -78,6 +78,9 @@ gchar		**gtk_source_language_get_style_ids 	(GtkSourceLanguage *language);
 const gchar	*gtk_source_language_get_style_name	(GtkSourceLanguage *language,
 							 const gchar       *style_id);
 
+const gchar	*gtk_source_language_get_style_fallback	(GtkSourceLanguage *language,
+							 const gchar       *style_id);
+
 G_END_DECLS
 
 #endif /* __GTK_SOURCE_LANGUAGE_H__ */



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