mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-17 14:30:15 +00:00
cssprovider: Keep track of passed in error differently
Instead of having an error member in the CSS provider's private struct, connect a signal handler when an error is passed in. This has two advantages: 1) It makes the code clearer as we don't have to keep track of an error member anywhere. 2) It causes a non-emission of the g_warning() when an error was passed in, because it only triggers when no signal handlers are connected. So we get identical behavior to GTK 3.0 where warnings where only emitted when no error was passed in.
This commit is contained in:
parent
8fb6fdd3e7
commit
607846879e
@ -800,9 +800,6 @@ struct _GtkCssProviderPrivate
|
|||||||
GHashTable *symbolic_colors;
|
GHashTable *symbolic_colors;
|
||||||
|
|
||||||
GPtrArray *selectors_info;
|
GPtrArray *selectors_info;
|
||||||
|
|
||||||
/* Current parser state */
|
|
||||||
GError *error;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ParserScope {
|
enum ParserScope {
|
||||||
@ -869,14 +866,6 @@ gtk_css_provider_parsing_error (GtkCssProvider *provider,
|
|||||||
guint position,
|
guint position,
|
||||||
const GError * error)
|
const GError * error)
|
||||||
{
|
{
|
||||||
GtkCssProviderPrivate *priv = provider->priv;
|
|
||||||
|
|
||||||
if (!priv->error)
|
|
||||||
{
|
|
||||||
priv->error = g_error_copy (error);
|
|
||||||
g_prefix_error (&priv->error, "%s:%u:%u: ", path ? path : "<unknown>", line, position);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Only emit a warning when we have no error handlers. This is our
|
/* Only emit a warning when we have no error handlers. This is our
|
||||||
* default handlers. And in this case erroneous CSS files are a bug
|
* default handlers. And in this case erroneous CSS files are a bug
|
||||||
* and should be fixed.
|
* and should be fixed.
|
||||||
@ -1774,10 +1763,6 @@ css_provider_reset_parser (GtkCssProvider *css_provider)
|
|||||||
priv = css_provider->priv;
|
priv = css_provider->priv;
|
||||||
|
|
||||||
gtk_css_scanner_reset (priv->scanner);
|
gtk_css_scanner_reset (priv->scanner);
|
||||||
|
|
||||||
if (priv->error)
|
|
||||||
g_error_free (priv->error);
|
|
||||||
priv->error = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2599,18 +2584,37 @@ gtk_css_provider_reset (GtkCssProvider *css_provider)
|
|||||||
g_ptr_array_remove_range (priv->selectors_info, 0, priv->selectors_info->len);
|
g_ptr_array_remove_range (priv->selectors_info, 0, priv->selectors_info->len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_css_provider_propagate_error (GtkCssProvider *provider,
|
||||||
|
const gchar *path,
|
||||||
|
guint line,
|
||||||
|
guint position,
|
||||||
|
const GError *error,
|
||||||
|
GError **propagate_to)
|
||||||
|
{
|
||||||
|
/* we already set an error. And we'd like to keep the first one */
|
||||||
|
if (*propagate_to)
|
||||||
|
return;
|
||||||
|
|
||||||
|
*propagate_to = g_error_copy (error);
|
||||||
|
g_prefix_error (propagate_to, "%s:%u:%u: ", path ? path : "<unknown>", line, position);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
parse_stylesheet (GtkCssProvider *css_provider,
|
parse_stylesheet (GtkCssProvider *css_provider,
|
||||||
GScanner *scanner,
|
GScanner *scanner,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GtkCssProviderPrivate *priv;
|
gulong error_handler;
|
||||||
gboolean result;
|
|
||||||
|
|
||||||
result = TRUE;
|
if (error)
|
||||||
|
error_handler = g_signal_connect (css_provider,
|
||||||
|
"parsing-error",
|
||||||
|
G_CALLBACK (gtk_css_provider_propagate_error),
|
||||||
|
error);
|
||||||
|
else
|
||||||
|
error_handler = 0; /* silence gcc */
|
||||||
|
|
||||||
priv = css_provider->priv;
|
|
||||||
g_scanner_get_next_token (scanner);
|
g_scanner_get_next_token (scanner);
|
||||||
|
|
||||||
while (!g_scanner_eof (scanner))
|
while (!g_scanner_eof (scanner))
|
||||||
@ -2634,7 +2638,19 @@ parse_stylesheet (GtkCssProvider *css_provider,
|
|||||||
g_scanner_get_next_token (scanner);
|
g_scanner_get_next_token (scanner);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
if (error)
|
||||||
|
{
|
||||||
|
g_signal_handler_disconnect (css_provider, error_handler);
|
||||||
|
|
||||||
|
if (*error)
|
||||||
|
{
|
||||||
|
/* We clear all contents from the provider for backwards compat reasons */
|
||||||
|
gtk_css_provider_reset (css_provider);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user