[gtksourceview/wip/gutter] GutterRendererLines: recalculate size on view style updated



commit acf0f7df4fea014b944dcc170f14c006aa25d021
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Sep 3 19:21:04 2013 +0200

    GutterRendererLines: recalculate size on view style updated
    
    This fixes a bug with the line numbers, when we change the font size of
    the text view (the gutter width was not updated).

 gtksourceview/gtksourcegutterrendererlines.c |   38 ++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/gtksourceview/gtksourcegutterrendererlines.c b/gtksourceview/gtksourcegutterrendererlines.c
index e1ff46f..581289a 100644
--- a/gtksourceview/gtksourcegutterrendererlines.c
+++ b/gtksourceview/gtksourcegutterrendererlines.c
@@ -128,6 +128,43 @@ gutter_renderer_change_buffer (GtkSourceGutterRenderer *renderer,
 }
 
 static void
+on_view_style_updated (GtkTextView                  *view,
+                      GtkSourceGutterRendererLines *renderer)
+{
+       /* Force to recalculate the size. */
+       renderer->priv->num_line_digits = -1;
+       recalculate_size (renderer);
+}
+
+static void
+gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
+                            GtkTextView             *old_view)
+{
+       GtkSourceGutterRendererClass *parent_class;
+       GtkTextView *new_view;
+
+       if (old_view != NULL)
+       {
+               g_signal_handlers_disconnect_by_func (old_view,
+                                                     on_view_style_updated,
+                                                     renderer);
+       }
+
+       new_view = gtk_source_gutter_renderer_get_view (renderer);
+
+       if (new_view != NULL)
+       {
+               g_signal_connect (new_view,
+                                 "style-updated",
+                                 G_CALLBACK (on_view_style_updated),
+                                 renderer);
+       }
+
+       parent_class = GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_lines_parent_class);
+       parent_class->change_view (renderer, old_view);
+}
+
+static void
 gutter_renderer_query_data (GtkSourceGutterRenderer      *renderer,
                             GtkTextIter                  *start,
                             GtkTextIter                  *end,
@@ -278,6 +315,7 @@ gtk_source_gutter_renderer_lines_class_init (GtkSourceGutterRendererLinesClass *
        renderer_class->query_activatable = gutter_renderer_query_activatable;
        renderer_class->activate = gutter_renderer_activate;
        renderer_class->change_buffer = gutter_renderer_change_buffer;
+       renderer_class->change_view = gutter_renderer_change_view;
 }
 
 static void


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