mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-06 00:30:08 +00:00
section: Add _gtk_css_section_to_string()
Mostly for debugging pruposes, but use it for printing CSS errors in GtkCssProvider, too.
This commit is contained in:
parent
8f96966178
commit
5e1ae36b2f
@ -1063,34 +1063,13 @@ gtk_css_provider_parsing_error (GtkCssProvider *provider,
|
||||
0,
|
||||
TRUE))
|
||||
{
|
||||
GFileInfo *info;
|
||||
GFile *file;
|
||||
const char *path;
|
||||
char *s = _gtk_css_section_to_string (section);
|
||||
|
||||
file = gtk_css_section_get_file (section);
|
||||
if (file)
|
||||
{
|
||||
info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, NULL);
|
||||
|
||||
if (info)
|
||||
path = g_file_info_get_display_name (info);
|
||||
else
|
||||
path = "<broken file>";
|
||||
}
|
||||
else
|
||||
{
|
||||
info = NULL;
|
||||
path = "<data>";
|
||||
}
|
||||
|
||||
g_warning ("Theme parsing error: %s:%u:%u: %s",
|
||||
path,
|
||||
gtk_css_section_get_end_line (section) + 1,
|
||||
gtk_css_section_get_end_position (section),
|
||||
g_warning ("Theme parsing error: %s: %s",
|
||||
s,
|
||||
error->message);
|
||||
|
||||
if (info)
|
||||
g_object_unref (info);
|
||||
g_free (s);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1826,32 +1805,14 @@ gtk_css_provider_propagate_error (GtkCssProvider *provider,
|
||||
GError **propagate_to)
|
||||
{
|
||||
|
||||
GFileInfo *info;
|
||||
GFile *file;
|
||||
const char *path;
|
||||
|
||||
file = gtk_css_section_get_file (section);
|
||||
if (file)
|
||||
{
|
||||
info = g_file_query_info (file,G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, NULL);
|
||||
|
||||
if (info)
|
||||
path = g_file_info_get_display_name (info);
|
||||
else
|
||||
path = "<broken file>";
|
||||
}
|
||||
else
|
||||
{
|
||||
info = NULL;
|
||||
path = "<unknown>";
|
||||
}
|
||||
char *s;
|
||||
|
||||
/* don't fail for deprecations */
|
||||
if (g_error_matches (error, GTK_CSS_PROVIDER_ERROR, GTK_CSS_PROVIDER_ERROR_DEPRECATED))
|
||||
{
|
||||
g_warning ("Theme parsing error: %s:%u:%u: %s", path,
|
||||
gtk_css_section_get_end_line (section) + 1,
|
||||
gtk_css_section_get_end_position (section), error->message);
|
||||
s = _gtk_css_section_to_string (section);
|
||||
g_warning ("Theme parsing error: %s: %s", s, error->message);
|
||||
g_free (s);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1860,12 +1821,9 @@ gtk_css_provider_propagate_error (GtkCssProvider *provider,
|
||||
return;
|
||||
|
||||
*propagate_to = g_error_copy (error);
|
||||
g_prefix_error (propagate_to, "%s:%u:%u: ", path,
|
||||
gtk_css_section_get_end_line (section) + 1,
|
||||
gtk_css_section_get_end_position (section));
|
||||
|
||||
if (info)
|
||||
g_object_unref (info);
|
||||
s = _gtk_css_section_to_string (section);
|
||||
g_prefix_error (propagate_to, "%s", s);
|
||||
g_free (s);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -303,3 +303,45 @@ gtk_css_section_get_end_position (const GtkCssSection *section)
|
||||
return section->end_position;
|
||||
}
|
||||
|
||||
void
|
||||
_gtk_css_section_print (const GtkCssSection *section,
|
||||
GString *string)
|
||||
{
|
||||
if (section->file)
|
||||
{
|
||||
GFileInfo *info;
|
||||
|
||||
info = g_file_query_info (section->file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, NULL);
|
||||
|
||||
if (info)
|
||||
{
|
||||
g_string_append (string, g_file_info_get_display_name (info));
|
||||
g_object_unref (info);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_string_append (string, "<broken file>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_string_append (string, "<data>");
|
||||
}
|
||||
|
||||
g_string_append_printf (string, ":%u:%u",
|
||||
gtk_css_section_get_end_line (section) + 1,
|
||||
gtk_css_section_get_end_position (section));
|
||||
}
|
||||
|
||||
char *
|
||||
_gtk_css_section_to_string (const GtkCssSection *section)
|
||||
{
|
||||
GString *string;
|
||||
|
||||
g_return_val_if_fail (section != NULL, NULL);
|
||||
|
||||
string = g_string_new (NULL);
|
||||
_gtk_css_section_print (section, string);
|
||||
|
||||
return g_string_free (string, FALSE);
|
||||
}
|
||||
|
@ -32,6 +32,10 @@ GtkCssSection * _gtk_css_section_new_for_file (GtkCssSectionType ty
|
||||
|
||||
void _gtk_css_section_end (GtkCssSection *section);
|
||||
|
||||
void _gtk_css_section_print (const GtkCssSection *section,
|
||||
GString *string);
|
||||
char * _gtk_css_section_to_string (const GtkCssSection *section);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_CSS_SECTION_PRIVATE_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user