[gedit] open file selector: get the label style at init



commit 8afe0bc91fdf562b51b683666a9f2c2ff2bb83f9
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Aug 15 20:56:44 2015 +0200

    open file selector: get the label style at init
    
    With the new gtk setting the css class in the cell data function
    causes extreme CPU usage since gtk keeps invalidating and redrawing.
    To avoid this we retrieve the color and font size at the beginning
    and then use it.

 gedit/gedit-open-document-selector.c |   53 +++++++++++++--------------------
 1 files changed, 21 insertions(+), 32 deletions(-)
---
diff --git a/gedit/gedit-open-document-selector.c b/gedit/gedit-open-document-selector.c
index 917481b..0f27535 100644
--- a/gedit/gedit-open-document-selector.c
+++ b/gedit/gedit-open-document-selector.c
@@ -51,6 +51,11 @@ struct _GeditOpenDocumentSelector
        GtkWidget *placeholder_box;
        GtkWidget *scrolled_window;
 
+       GdkRGBA name_label_color;
+       gdouble name_font_size;
+       GdkRGBA path_label_color;
+       gdouble path_font_size;
+
        GeditOpenDocumentSelectorStore *selector_store;
        GList *recent_items;
        GList *home_dir_items;
@@ -1039,22 +1044,8 @@ name_renderer_datafunc (GtkTreeViewColumn         *column,
                         GtkTreeIter               *iter,
                         GeditOpenDocumentSelector *selector)
 {
-       GtkStyleContext *context;
-       GdkRGBA label_color;
-       gdouble font_size;
-
-       context = gtk_widget_get_style_context (selector->treeview);
-
-       /* Name label foreground and font size styling */
-       gtk_style_context_add_class (context, "open-document-selector-name-label");
-
-       gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &label_color);
-       g_object_set (selector->name_renderer, "foreground-rgba", &label_color, NULL);
-
-       gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL, "font-size", &font_size, NULL);
-       g_object_set (selector->name_renderer, "size-points", font_size, NULL);
-
-       gtk_style_context_remove_class (context, "open-document-selector-name-label");
+       g_object_set (selector->name_renderer, "foreground-rgba", &selector->name_label_color, NULL);
+       g_object_set (selector->name_renderer, "size-points", selector->name_font_size, NULL);
 }
 
 static void
@@ -1064,22 +1055,8 @@ path_renderer_datafunc (GtkTreeViewColumn         *column,
                         GtkTreeIter               *iter,
                         GeditOpenDocumentSelector *selector)
 {
-       GtkStyleContext *context;
-       GdkRGBA label_color;
-       gdouble font_size;
-
-       context = gtk_widget_get_style_context (selector->treeview);
-
-       /* Path label foreground and font size styling */
-       gtk_style_context_add_class (context, "open-document-selector-path-label");
-
-       gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &label_color);
-       g_object_set (selector->path_renderer, "foreground-rgba", &label_color, NULL);
-
-       gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL, "font-size", &font_size, NULL);
-       g_object_set (selector->path_renderer, "size-points", font_size, NULL);
-
-       gtk_style_context_remove_class (context, "open-document-selector-path-label");
+       g_object_set (selector->path_renderer, "foreground-rgba", &selector->path_label_color, NULL);
+       g_object_set (selector->path_renderer, "size-points", selector->path_font_size, NULL);
 }
 
 static void
@@ -1114,6 +1091,18 @@ setup_treeview (GeditOpenDocumentSelector *selector)
        context = gtk_widget_get_style_context (selector->treeview);
        gtk_style_context_add_class (context, "open-document-selector-treeview");
 
+       /* Name label foreground and font size styling */
+       gtk_style_context_add_class (context, "open-document-selector-name-label");
+       gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &selector->name_label_color);
+       gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL, "font-size", &selector->name_font_size, NULL);
+       gtk_style_context_remove_class (context, "open-document-selector-name-label");
+
+       /* Path label foreground and font size styling */
+       gtk_style_context_add_class (context, "open-document-selector-path-label");
+       gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &selector->path_label_color);
+       gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL, "font-size", &selector->path_font_size, NULL);
+       gtk_style_context_remove_class (context, "open-document-selector-path-label");
+
        gtk_tree_view_column_set_cell_data_func (column,
                                                 selector->name_renderer,
                                                 (GtkTreeCellDataFunc)name_renderer_datafunc,


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