[gtksourceview] Support a current-line-number style in style schemes



commit 47191e4e804fbbfc2e9b3ec2b9377b13b5578fc3
Author: Paolo Borelli <pborelli gnome org>
Date:   Thu Jan 22 23:44:51 2015 +0100

    Support a current-line-number style in style schemes
    
    Recently we changed the gutter drawing to also draw the current
    line background in the gutter. This looks nice for some themes,
    like "classic" or gnome-builder's built in theme, but looks bad
    in themes like "oblivion" where the line number itself becomes
    unreadable. This commit restores the old behavior by default,
    but allows color schemes to have
    
      <style name="current-line-number" background="#yellow"/>
    
    to force a background color for the gutter of the current line
    and in particular if the same color of "current-line" is used
    then the same effect of the old patch is achieved.
    
    "classic" and "tango" are patched to take advantage of this.

 data/styles/classic.xml                 |    1 +
 data/styles/tango.xml                   |    1 +
 gtksourceview/gtksourcegutterrenderer.c |   46 +++++++++++++++----------------
 gtksourceview/gtksourcestylescheme.c    |    7 +++++
 4 files changed, 31 insertions(+), 24 deletions(-)
---
diff --git a/data/styles/classic.xml b/data/styles/classic.xml
index 621a454..8cf25c0 100644
--- a/data/styles/classic.xml
+++ b/data/styles/classic.xml
@@ -44,6 +44,7 @@
 
   <!-- Global Settings -->
   <style name="current-line"                background="#eeeeec"/>
+  <style name="current-line-number"         background="#eeeeec"/>
   <style name="draw-spaces"                 foreground="#babdb6"/>
 
   <!-- Bracket Matching -->
diff --git a/data/styles/tango.xml b/data/styles/tango.xml
index 62dddac..f2f9c92 100644
--- a/data/styles/tango.xml
+++ b/data/styles/tango.xml
@@ -57,6 +57,7 @@
   <!-- Global Settings -->
   <style name="cursor"                      foreground="aluminium4"/>
   <style name="current-line"                background="aluminium1"/>
+  <style name="current-line-number"         background="aluminium1"/>
   <style name="draw-spaces"                 foreground="aluminium3"/>
 
   <!-- Bracket Matching -->
diff --git a/gtksourceview/gtksourcegutterrenderer.c b/gtksourceview/gtksourcegutterrenderer.c
index c2a8cc1..58013ef 100644
--- a/gtksourceview/gtksourcegutterrenderer.c
+++ b/gtksourceview/gtksourcegutterrenderer.c
@@ -475,39 +475,37 @@ renderer_draw_impl (GtkSourceGutterRenderer      *renderer,
                     GtkTextIter                  *end,
                     GtkSourceGutterRendererState  state)
 {
+       gboolean draw_background = FALSE;
+       GdkRGBA background_color;
+
        if (renderer->priv->background_set)
        {
-               cairo_save (cr);
-               gdk_cairo_rectangle (cr, background_area);
-               gdk_cairo_set_source_rgba (cr, &renderer->priv->background_color);
-               cairo_fill (cr);
-               cairo_restore (cr);
+               background_color = renderer->priv->background_color;
+               draw_background = TRUE;
        }
        else if ((state & GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR) != 0 &&
                 GTK_SOURCE_IS_VIEW (renderer->priv->view))
        {
-               GtkSourceBuffer *buffer;
-               GtkSourceStyleScheme *style_scheme;
-               GdkRGBA line_color;
-
-               if (!gtk_source_view_get_highlight_current_line (GTK_SOURCE_VIEW (renderer->priv->view)))
-               {
-                       return;
-               }
+               GtkStyleContext *context;
 
-               buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (renderer->priv->view));
-               style_scheme = gtk_source_buffer_get_style_scheme (buffer);
+               context = gtk_widget_get_style_context (GTK_WIDGET (renderer->priv->view));
+               gtk_style_context_save (context);
+               gtk_style_context_add_class (context, "current-line-number");
+               gtk_style_context_get_background_color (context,
+                                                       gtk_style_context_get_state (context),
+                                                       &background_color);
+               gtk_style_context_restore (context);
 
-               if (style_scheme != NULL &&
-                   _gtk_source_style_scheme_get_current_line_color (style_scheme, &line_color))
-               {
-                       cairo_save (cr);
-                       gdk_cairo_rectangle (cr, background_area);
-                       gdk_cairo_set_source_rgba (cr, &line_color);
-                       cairo_fill (cr);
-                       cairo_restore (cr);
-               }
+               draw_background = TRUE;
+       }
 
+       if (draw_background)
+       {
+               cairo_save (cr);
+               gdk_cairo_rectangle (cr, background_area);
+               gdk_cairo_set_source_rgba (cr, &background_color);
+               cairo_fill (cr);
+               cairo_restore (cr);
        }
 }
 
diff --git a/gtksourceview/gtksourcestylescheme.c b/gtksourceview/gtksourcestylescheme.c
index 25ad907..120b709 100644
--- a/gtksourceview/gtksourcestylescheme.c
+++ b/gtksourceview/gtksourcestylescheme.c
@@ -52,6 +52,7 @@
 #define STYLE_SECONDARY_CURSOR         "secondary-cursor"
 #define STYLE_CURRENT_LINE             "current-line"
 #define STYLE_LINE_NUMBERS             "line-numbers"
+#define STYLE_CURRENT_LINE_NUMBER      "current-line-number"
 #define STYLE_RIGHT_MARGIN             "right-margin"
 #define STYLE_DRAW_SPACES              "draw-spaces"
 #define STYLE_BACKGROUND_PATTERN       "background-pattern"
@@ -857,6 +858,12 @@ generate_css_style (GtkSourceStyleScheme *scheme)
                append_css_style (final_style, style, "GtkSourceView");
        }
 
+       style = gtk_source_style_scheme_get_style (scheme, STYLE_CURRENT_LINE_NUMBER);
+       if (style != NULL)
+       {
+               append_css_style (final_style, style, ".current-line-number");
+       }
+
        if (*final_style->str != '\0')
        {
                GError *error = NULL;


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