[gnome-builder] snippets: use background color from style scheme



commit b01f5fd4e500f8c34c22cbc8bc2eb3fbc4a2974f
Author: Fangwen Yu <yynyygy gmail com>
Date:   Fri Mar 4 00:08:49 2016 +0800

    snippets: use background color from style scheme
    
    Add style "snippet::area", use its background color for snippets'
    background area, if this style is not present for the scheme or
    its background color is not set, fallback to #204a87. When the
    style scheme changes, we cache the color in the
    IdeSourceViewPrivate structure.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=762505

 data/style-schemes/builder.xml |    1 +
 libide/ide-source-view.c       |   28 +++++++++++++++++++---------
 2 files changed, 20 insertions(+), 9 deletions(-)
---
diff --git a/data/style-schemes/builder.xml b/data/style-schemes/builder.xml
index 2e4eb75..13d5453 100644
--- a/data/style-schemes/builder.xml
+++ b/data/style-schemes/builder.xml
@@ -82,6 +82,7 @@
 
   <!-- Snippets -->
   <style name="snippet::tab-stop"           background="#fcaf3e" foreground="text1"/>
+  <style name="snippet::area"               background="#rgba(32,74,135,.1)"/>
 
   <!-- Bracket Matching -->
   <style name="bracket-match"               foreground="aluminium3" background="aluminium1" bold="true"/>
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 2319538..9e4a5f5 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -147,6 +147,7 @@ typedef struct
 
   GdkRGBA                      bubble_color1;
   GdkRGBA                      bubble_color2;
+  GdkRGBA                      snippet_area_background_rgba;
 
   guint                        font_scale;
 
@@ -978,13 +979,18 @@ ide_source_view__buffer_notify_style_scheme_cb (IdeSourceView *self,
   IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
   GtkSourceStyleScheme *scheme = NULL;
   GtkSourceStyle *style = NULL;
+  GtkSourceStyle *snippet_area_style = NULL;
+  g_autofree gchar *snippet_background = NULL;
 
   g_assert (IDE_IS_SOURCE_VIEW (self));
   g_assert (IDE_IS_BUFFER (buffer));
 
   scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (buffer));
   if (scheme)
-    style = gtk_source_style_scheme_get_style (scheme, "search-match");
+    {
+      style = gtk_source_style_scheme_get_style (scheme, "search-match");
+      snippet_area_style = gtk_source_style_scheme_get_style (scheme, "snippet::area");
+    }
 
   if (style)
     {
@@ -1001,6 +1007,17 @@ ide_source_view__buffer_notify_style_scheme_cb (IdeSourceView *self,
       gdk_rgba_parse (&priv->bubble_color1, "#edd400");
       gdk_rgba_parse (&priv->bubble_color2, "#fce94f");
     }
+
+  if (snippet_area_style)
+    g_object_get (snippet_area_style, "background", &snippet_background, NULL);
+
+  if (snippet_background)
+    gdk_rgba_parse (&priv->snippet_area_background_rgba, snippet_background);
+  else
+    {
+      gdk_rgba_parse (&priv->snippet_area_background_rgba, "#204a87");
+      priv->snippet_area_background_rgba.alpha = 0.1;
+    }
 }
 
 static void
@@ -4176,7 +4193,6 @@ ide_source_view_draw_snippets_background (IdeSourceView *self,
                                           cairo_t       *cr)
 {
   static GdkRGBA rgba;
-  static gboolean did_rgba;
   IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
   IdeSourceSnippet *snippet;
   GtkTextView *text_view = GTK_TEXT_VIEW (self);
@@ -4188,13 +4204,7 @@ ide_source_view_draw_snippets_background (IdeSourceView *self,
   g_assert (IDE_IS_SOURCE_VIEW (self));
   g_assert (cr);
 
-  if (!did_rgba)
-    {
-      /* TODO: Get this from the style scheme? */
-      gdk_rgba_parse (&rgba, "#204a87");
-      rgba.alpha = 0.1;
-      did_rgba = TRUE;
-    }
+  rgba = priv->snippet_area_background_rgba;
 
   window = gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT);
   width = gdk_window_get_width (window);


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