inspector: Make css deprecations opt-in

Add a button to show deprecation warnings (since those will
unfortunately be common for while, due to backwards compat).
This commit is contained in:
Matthias Clasen 2024-05-31 11:25:11 -04:00
parent f790441505
commit f6ea3e1684
2 changed files with 51 additions and 1 deletions

View File

@ -47,6 +47,7 @@ struct _GtkInspectorCssEditorPrivate
GtkToggleButton *disable_button;
guint timeout;
GList *errors;
gboolean show_deprecations;
};
typedef struct {
@ -94,6 +95,12 @@ query_tooltip_cb (GtkWidget *widget,
{
CssError *css_error = l->data;
if (g_error_matches (css_error->error,
GTK_CSS_PARSER_WARNING,
GTK_CSS_PARSER_WARNING_DEPRECATED) &&
!ce->priv->show_deprecations)
continue;
if (gtk_text_iter_in_range (&iter, &css_error->start, &css_error->end))
{
gtk_tooltip_set_text (tooltip, css_error->error->message);
@ -170,6 +177,29 @@ disable_toggled (GtkToggleButton *button,
GTK_STYLE_PROVIDER_PRIORITY_USER);
}
static void
toggle_deprecations (GtkToggleButton *button,
GtkInspectorCssEditor *ce)
{
GtkTextTagTable *tags;
GtkTextTag *tag;
PangoUnderline underline;
if (!ce->priv->display)
return;
ce->priv->show_deprecations = gtk_toggle_button_get_active (button);
tags = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (ce->priv->text));
tag = gtk_text_tag_table_lookup (tags, "deprecation");
if (ce->priv->show_deprecations)
underline = PANGO_UNDERLINE_SINGLE;
else
underline = PANGO_UNDERLINE_NONE;
g_object_set (tag, "underline", underline, NULL);
}
static char *
get_current_text (GtkTextBuffer *buffer)
{
@ -316,7 +346,12 @@ show_parsing_error (GtkCssProvider *provider,
end->line_bytes);
if (error->domain == GTK_CSS_PARSER_WARNING)
tag_name = "warning";
{
if (error->code == GTK_CSS_PARSER_WARNING_DEPRECATED)
tag_name = "deprecation";
else
tag_name = "warning";
}
else
tag_name = "error";
@ -407,6 +442,7 @@ gtk_inspector_css_editor_class_init (GtkInspectorCssEditorClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssEditor, view);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssEditor, disable_button);
gtk_widget_class_bind_template_callback (widget_class, disable_toggled);
gtk_widget_class_bind_template_callback (widget_class, toggle_deprecations);
gtk_widget_class_bind_template_callback (widget_class, save_clicked);
gtk_widget_class_bind_template_callback (widget_class, text_changed);
gtk_widget_class_bind_template_callback (widget_class, query_tooltip_cb);

View File

@ -7,6 +7,13 @@
<property name="underline-rgba">darkorange</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag">
<property name="name">deprecation</property>
<property name="underline">none</property>
<property name="underline-rgba">blue</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag">
<property name="name">error</property>
@ -39,6 +46,13 @@
<signal name="clicked" handler="save_clicked"/>
</object>
</child>
<child>
<object class="GtkToggleButton" id="deprections_button">
<property name="tooltip-text" translatable="yes">Show deprecations</property>
<property name="icon-name">dialog-information-symbolic</property>
<signal name="toggled" handler="toggle_deprecations"/>
</object>
</child>
</object>
</child>
<child>