[gnome-software: 6/13] gs-category-tile: Add category-specific CSS classes




commit 52b8598bfb716e7451719f86f636892d268c0fa2
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Jul 29 15:06:42 2021 +0100

    gs-category-tile: Add category-specific CSS classes
    
    This should allow category-specific CSS to be set in the CSS file and
    used automatically.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 src/gs-category-tile.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
---
diff --git a/src/gs-category-tile.c b/src/gs-category-tile.c
index f1e147346..3d50026fa 100644
--- a/src/gs-category-tile.c
+++ b/src/gs-category-tile.c
@@ -112,10 +112,26 @@ gs_category_tile_refresh (GsCategoryTile *tile)
 void
 gs_category_tile_set_category (GsCategoryTile *tile, GsCategory *cat)
 {
+       GtkStyleContext *context;
+
        g_return_if_fail (GS_IS_CATEGORY_TILE (tile));
        g_return_if_fail (GS_IS_CATEGORY (cat));
 
+       context = gtk_widget_get_style_context (GTK_WIDGET (tile));
+
+       /* Remove the old category ID. */
+       if (tile->category != NULL) {
+               g_autofree gchar *class_name = g_strdup_printf ("category-%s", gs_category_get_id 
(tile->category));
+               gtk_style_context_remove_class (context, class_name);
+       }
+
        if (g_set_object (&tile->category, cat)) {
+               g_autofree gchar *class_name = g_strdup_printf ("category-%s", gs_category_get_id 
(tile->category));
+
+               /* Add the new category’s ID as a CSS class, to get
+                * category-specific styling. */
+               gtk_style_context_add_class (context, class_name);
+
                gs_category_tile_refresh (tile);
                g_object_notify_by_pspec (G_OBJECT (tile), obj_props[PROP_CATEGORY]);
        }


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