[gnome-builder] style-schemes: use the style scheme for diagnostics underlining



commit 97607b9a6f0a75cf7e9de4a05d50af3ec4d2908f
Author: Matthew Leeds <mleeds redhat com>
Date:   Fri Jun 3 17:11:48 2016 -0400

    style-schemes: use the style scheme for diagnostics underlining
    
    Builder underlines segments of code in different colors depending on the
    condition reported by libclang (deprecated, error, note, or warning). As
    of v3.17.2, GtkSourceView supports the underline-color attribute in
    style schemes. So Builder now makes use of that, and falls back on hard-coded
    values in case our custom style scheme isn't installed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=767216

 data/style-schemes/builder-dark.xml |    7 ++
 data/style-schemes/builder.xml      |    7 ++
 libide/ide-buffer.c                 |  120 ++++++++++++++++++++++++++++-------
 libide/ide-source-style-scheme.c    |   23 +++++--
 4 files changed, 130 insertions(+), 27 deletions(-)
---
diff --git a/data/style-schemes/builder-dark.xml b/data/style-schemes/builder-dark.xml
index 9b7ecd8..9616f8e 100644
--- a/data/style-schemes/builder-dark.xml
+++ b/data/style-schemes/builder-dark.xml
@@ -57,6 +57,7 @@
   <color name="aluminium6"                  value="#2e3436"/>
   <color name="white"                       value="#ffffff"/>
   <color name="pink1"                       value="#dd4a68"/>
+  <color name="red1"                        value="#ff0000"/>
 
   <!-- Global Settings -->
   <style name="text"                        foreground="aluminium3" background="#232729"/>
@@ -69,6 +70,12 @@
   <style name="background-pattern"          background="#rgba(46,46,46,0.8)"/>
   <style name="map-overlay"                 background="#rgba(136,138,133,0.25)"/>
 
+  <!-- Diagnostics Underlining -->
+  <style name="diagnostician::deprecated"   underline="error" underline-color="aluminium3"/>
+  <style name="diagnostician::error"        underline="error" underline-color="red1"/>
+  <style name="diagnostician::note"         underline="error" underline-color="skyblue1"/>
+  <style name="diagnostician::warning"      underline="error" underline-color="orange1"/>
+
   <!-- Snippets -->
   <style name="snippet::tab-stop"           background="orange3" foreground="aluminium6"/>
   <style name="snippet::area"               background="#rgba(86,114,151,.5)"/>
diff --git a/data/style-schemes/builder.xml b/data/style-schemes/builder.xml
index d650245..c511696 100644
--- a/data/style-schemes/builder.xml
+++ b/data/style-schemes/builder.xml
@@ -40,6 +40,7 @@
   <color name="line1"                       value="#a2a3a3"/>
   <color name="white"                       value="#ffffff"/>
   <color name="yellow1"                     value="#fff9e5"/>
+  <color name="red1"                        value="#ff0000"/>
 
   <color name="butter1"                     value="#fce94f"/>
   <color name="butter2"                     value="#edd400"/>
@@ -80,6 +81,12 @@
   <style name="line-numbers"                foreground="line1" background="bg1"/>
   <style name="background-pattern"          background="#rgba(.125,.125,.125,.025)"/>
 
+  <!-- Diagnostics Underlining -->
+  <style name="diagnostician::deprecated"   underline="error" underline-color="aluminium3"/>
+  <style name="diagnostician::error"        underline="error" underline-color="red1"/>
+  <style name="diagnostician::note"         underline="error" underline-color="blue1"/>
+  <style name="diagnostician::warning"      underline="error" underline-color="orange1"/>
+
   <!-- Snippets -->
   <style name="snippet::tab-stop"           background="#fcaf3e" foreground="text1"/>
   <style name="snippet::area"               background="#rgba(32,74,135,.1)"/>
diff --git a/libide/ide-buffer.c b/libide/ide-buffer.c
index 10a52b1..d7186f7 100644
--- a/libide/ide-buffer.c
+++ b/libide/ide-buffer.c
@@ -59,6 +59,11 @@
 #define TAG_SNIPPET_TAB_STOP "snippet::tab-stop"
 #define TAG_DEFINITION       "action::hover-definition"
 
+#define DEPRECATED_COLOR "#babdb6"
+#define ERROR_COLOR      "#ff0000"
+#define NOTE_COLOR       "#708090"
+#define WARNING_COLOR    "#fcaf3e"
+
 typedef struct
 {
   IdeContext             *context;
@@ -1011,6 +1016,10 @@ ide_buffer_notify_style_scheme (IdeBuffer  *self,
 {
   GtkSourceStyleScheme *style_scheme;
   GtkTextTagTable *table;
+  GdkRGBA deprecated_rgba;
+  GdkRGBA error_rgba;
+  GdkRGBA note_rgba;
+  GdkRGBA warning_rgba;
 
   g_assert (IDE_IS_BUFFER (self));
   g_assert (pspec != NULL);
@@ -1022,6 +1031,46 @@ ide_buffer_notify_style_scheme (IdeBuffer  *self,
 
   if (style_scheme != NULL)
     {
+      /*
+       * These are used as a fall-back if our style scheme isn't installed.
+       */
+      gdk_rgba_parse (&deprecated_rgba, DEPRECATED_COLOR);
+      gdk_rgba_parse (&error_rgba, ERROR_COLOR);
+      gdk_rgba_parse (&note_rgba, NOTE_COLOR);
+      gdk_rgba_parse (&warning_rgba, WARNING_COLOR);
+
+      if (!ide_source_style_scheme_apply_style (style_scheme,
+                                                TAG_DEPRECATED,
+                                                GET_TAG (TAG_DEPRECATED)))
+        apply_style (GET_TAG (TAG_DEPRECATED),
+                     "underline", PANGO_UNDERLINE_ERROR,
+                     "underline-rgba", &deprecated_rgba,
+                     NULL);
+
+      if (!ide_source_style_scheme_apply_style (style_scheme,
+                                                TAG_ERROR,
+                                                GET_TAG (TAG_ERROR)))
+        apply_style (GET_TAG (TAG_ERROR),
+                     "underline", PANGO_UNDERLINE_ERROR,
+                     "underline-rgba", &error_rgba,
+                     NULL);
+
+      if (!ide_source_style_scheme_apply_style (style_scheme,
+                                                TAG_NOTE,
+                                                GET_TAG (TAG_NOTE)))
+        apply_style (GET_TAG (TAG_NOTE),
+                     "underline", PANGO_UNDERLINE_ERROR,
+                     "underline-rgba", &note_rgba,
+                     NULL);
+
+      if (!ide_source_style_scheme_apply_style (style_scheme,
+                                                TAG_WARNING,
+                                                GET_TAG (TAG_WARNING)))
+        apply_style (GET_TAG (TAG_WARNING),
+                     "underline", PANGO_UNDERLINE_ERROR,
+                     "underline-rgba", &warning_rgba,
+                     NULL);
+
       ide_source_style_scheme_apply_style (style_scheme,
                                            TAG_SNIPPET_TAB_STOP,
                                            GET_TAG (TAG_SNIPPET_TAB_STOP));
@@ -1063,6 +1112,12 @@ ide_buffer_constructed (GObject *object)
 {
   IdeBuffer *self = (IdeBuffer *)object;
   IdeBufferPrivate *priv = ide_buffer_get_instance_private (self);
+  GtkTextTagTable *tag_table;
+  GtkSourceStyleScheme *style_scheme;
+  g_autoptr(GtkTextTag) deprecated_tag = NULL;
+  g_autoptr(GtkTextTag) error_tag = NULL;
+  g_autoptr(GtkTextTag) note_tag = NULL;
+  g_autoptr(GtkTextTag) warning_tag = NULL;
   GdkRGBA deprecated_rgba;
   GdkRGBA error_rgba;
   GdkRGBA note_rgba;
@@ -1070,14 +1125,16 @@ ide_buffer_constructed (GObject *object)
 
   G_OBJECT_CLASS (ide_buffer_parent_class)->constructed (object);
 
+  tag_table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (self));
+  style_scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (self));
+
   /*
-   * TODO: Once we bump to GtkSourceView 3.17, these should be extracted
-   *       from the style scheme (or use the style scheme directly).
+   * These are used as a fall-back if our style scheme isn't installed.
    */
-  gdk_rgba_parse (&deprecated_rgba, "#babdb6");
-  gdk_rgba_parse (&error_rgba, "#ff0000");
-  gdk_rgba_parse (&note_rgba, "#708090");
-  gdk_rgba_parse (&warning_rgba, "#fcaf3e");
+  gdk_rgba_parse (&deprecated_rgba, DEPRECATED_COLOR);
+  gdk_rgba_parse (&error_rgba, ERROR_COLOR);
+  gdk_rgba_parse (&note_rgba, NOTE_COLOR);
+  gdk_rgba_parse (&warning_rgba, WARNING_COLOR);
 
   /*
    * NOTE:
@@ -1085,22 +1142,41 @@ ide_buffer_constructed (GObject *object)
    * The tag table assigns priority upon insert. Each successive insert
    * is higher priority than the last.
    */
-  gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (self), TAG_NOTE,
-                              "underline", PANGO_UNDERLINE_ERROR,
-                              "underline-rgba", &note_rgba,
-                              NULL);
-  gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (self), TAG_DEPRECATED,
-                              "underline", PANGO_UNDERLINE_ERROR,
-                              "underline-rgba", &deprecated_rgba,
-                              NULL);
-  gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (self), TAG_WARNING,
-                              "underline", PANGO_UNDERLINE_ERROR,
-                              "underline-rgba", &warning_rgba,
-                              NULL);
-  gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (self), TAG_ERROR,
-                              "underline", PANGO_UNDERLINE_ERROR,
-                              "underline-rgba", &error_rgba,
-                              NULL);
+
+  deprecated_tag = gtk_text_tag_new (TAG_DEPRECATED);
+  error_tag = gtk_text_tag_new (TAG_ERROR);
+  note_tag = gtk_text_tag_new (TAG_NOTE);
+  warning_tag = gtk_text_tag_new (TAG_WARNING);
+
+  if (!ide_source_style_scheme_apply_style (style_scheme, TAG_DEPRECATED, deprecated_tag))
+      apply_style (deprecated_tag,
+                   "underline", PANGO_UNDERLINE_ERROR,
+                   "underline-rgba", &deprecated_rgba,
+                   NULL);
+
+  if (!ide_source_style_scheme_apply_style (style_scheme, TAG_ERROR, error_tag))
+      apply_style (error_tag,
+                   "underline", PANGO_UNDERLINE_ERROR,
+                   "underline-rgba", &error_rgba,
+                   NULL);
+
+  if (!ide_source_style_scheme_apply_style (style_scheme, TAG_NOTE, note_tag))
+      apply_style (note_tag,
+                   "underline", PANGO_UNDERLINE_ERROR,
+                   "underline-rgba", &note_rgba,
+                   NULL);
+
+  if (!ide_source_style_scheme_apply_style (style_scheme, TAG_NOTE, warning_tag))
+      apply_style (warning_tag,
+                   "underline", PANGO_UNDERLINE_ERROR,
+                   "underline-rgba", &warning_rgba,
+                   NULL);
+
+  gtk_text_tag_table_add (tag_table, deprecated_tag);
+  gtk_text_tag_table_add (tag_table, error_tag);
+  gtk_text_tag_table_add (tag_table, note_tag);
+  gtk_text_tag_table_add (tag_table, warning_tag);
+
   gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (self), TAG_SNIPPET_TAB_STOP,
                               NULL);
   gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (self), TAG_DEFINITION,
diff --git a/libide/ide-source-style-scheme.c b/libide/ide-source-style-scheme.c
index 0dfe0e2..8a25625 100644
--- a/libide/ide-source-style-scheme.c
+++ b/libide/ide-source-style-scheme.c
@@ -25,17 +25,20 @@ ide_source_style_scheme_apply_style (GtkSourceStyleScheme *style_scheme,
                                      const gchar          *style_name,
                                      GtkTextTag           *tag)
 {
+  g_autofree gchar *tag_name = NULL;
   g_autofree gchar *foreground = NULL;
   g_autofree gchar *background = NULL;
-  g_autofree gchar *tag_name = NULL;
+  g_autofree gchar *underline_color = NULL;
+  GdkRGBA underline_rgba;
   GtkSourceStyle *style;
   const gchar *colon;
+  PangoUnderline pango_underline;
   gboolean foreground_set = FALSE;
   gboolean background_set = FALSE;
   gboolean bold = FALSE;
   gboolean bold_set = FALSE;
-  gboolean underline = FALSE;
   gboolean underline_set = FALSE;
+  gboolean underline_color_set = FALSE;
   gboolean italic = FALSE;
   gboolean italic_set = FALSE;
 
@@ -47,6 +50,7 @@ ide_source_style_scheme_apply_style (GtkSourceStyleScheme *style_scheme,
                 "background-set", FALSE,
                 "weight-set", FALSE,
                 "underline-set", FALSE,
+                "underline-rgba-set", FALSE,
                 "style-set", FALSE,
                 NULL);
 
@@ -71,8 +75,10 @@ ide_source_style_scheme_apply_style (GtkSourceStyleScheme *style_scheme,
                 "foreground-set", &foreground_set,
                 "bold", &bold,
                 "bold-set", &bold_set,
-                "underline", &underline,
+                "pango-underline", &pango_underline,
                 "underline-set", &underline_set,
+                "underline-color", &underline_color,
+                "underline-color-set", &underline_color_set,
                 "italic", &italic,
                 "italic-set", &italic_set,
                 NULL);
@@ -89,8 +95,15 @@ ide_source_style_scheme_apply_style (GtkSourceStyleScheme *style_scheme,
   if (italic_set && italic)
     g_object_set (tag, "style", PANGO_STYLE_ITALIC, NULL);
 
-  if (underline_set && underline)
-    g_object_set (tag, "underline", PANGO_UNDERLINE_SINGLE, NULL);
+  if (underline_set)
+    g_object_set (tag, "underline", pango_underline, NULL);
 
+  if (underline_color_set && underline_color != NULL)
+    {
+      gdk_rgba_parse (&underline_rgba, underline_color);
+      g_object_set (tag,
+                    "underline-rgba", &underline_rgba,
+                    NULL);
+    }
   return TRUE;
 }


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