[gnome-builder/wip/gtk4-port: 629/736] libide/search: add GIcon property




commit 2a2c9099e5d4e916b8405f2bb995163c8bac13bc
Author: Christian Hergert <chergert redhat com>
Date:   Mon Apr 18 21:00:39 2022 -0700

    libide/search: add GIcon property
    
    It can be annoying to set paintables when we dont have a display widget
    because we wont know the scale to load it. So instead just allow stashing
    a GIcon so that we can restore it with a GtkImage widget later.

 src/libide/search/ide-search-result.c | 56 ++++++++++++++++++++++++++++++++---
 src/libide/search/ide-search-result.h |  5 ++++
 2 files changed, 57 insertions(+), 4 deletions(-)
---
diff --git a/src/libide/search/ide-search-result.c b/src/libide/search/ide-search-result.c
index 33bffd6d6..b9e900fae 100644
--- a/src/libide/search/ide-search-result.c
+++ b/src/libide/search/ide-search-result.c
@@ -28,6 +28,7 @@ typedef struct
 {
   char         *title;
   GdkPaintable *paintable;
+  GIcon        *gicon;
   float         score;
   guint         priority;
 } IdeSearchResultPrivate;
@@ -35,6 +36,7 @@ typedef struct
 enum {
   PROP_0,
   PROP_PAINTABLE,
+  PROP_GICON,
   PROP_PRIORITY,
   PROP_SCORE,
   PROP_TITLE,
@@ -71,6 +73,10 @@ ide_search_result_get_property (GObject    *object,
       g_value_set_object (value, ide_search_result_get_paintable (self));
       break;
 
+    case PROP_GICON:
+      g_value_set_object (value, ide_search_result_get_gicon (self));
+      break;
+
     case PROP_PRIORITY:
       g_value_set_int (value, ide_search_result_get_priority (self));
       break;
@@ -102,6 +108,10 @@ ide_search_result_set_property (GObject      *object,
       ide_search_result_set_paintable (self, g_value_get_object (value));
       break;
 
+    case PROP_GICON:
+      ide_search_result_set_gicon (self, g_value_get_object (value));
+      break;
+
     case PROP_PRIORITY:
       ide_search_result_set_priority (self, g_value_get_int (value));
       break;
@@ -130,10 +140,17 @@ ide_search_result_class_init (IdeSearchResultClass *klass)
 
   properties [PROP_PAINTABLE] =
     g_param_spec_object ("paintable",
-                      "Paintable",
-                      "The paintable for the row icon",
-                      GDK_TYPE_PAINTABLE,
-                      (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+                         "Paintable",
+                         "The paintable for the row icon",
+                         GDK_TYPE_PAINTABLE,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_GICON] =
+    g_param_spec_object ("gicon",
+                         "GIcon",
+                         "The GIcon for the row icon",
+                         G_TYPE_ICON,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   properties [PROP_PRIORITY] =
     g_param_spec_int ("priority",
@@ -321,3 +338,34 @@ ide_search_result_set_title (IdeSearchResult *self,
       g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]);
     }
 }
+
+void
+ide_search_result_set_gicon (IdeSearchResult *self,
+                             GIcon           *gicon)
+{
+  IdeSearchResultPrivate *priv = ide_search_result_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_SEARCH_RESULT (self));
+  g_return_if_fail (!gicon || G_IS_ICON (gicon));
+
+  if (g_set_object (&priv->gicon, gicon))
+    g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_GICON]);
+}
+
+/**
+ * ide_search_result_get_gicon:
+ * @self: a #IdeSearchResult
+ *
+ * Gets the #GIcon for the search result, if any.
+ *
+ * Returns: (transfer none) (nullable): a #GIcon or %NULL
+ */
+GIcon *
+ide_search_result_get_gicon (IdeSearchResult *self)
+{
+  IdeSearchResultPrivate *priv = ide_search_result_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_SEARCH_RESULT (self), NULL);
+
+  return priv->gicon;
+}
diff --git a/src/libide/search/ide-search-result.h b/src/libide/search/ide-search-result.h
index 90cf41618..3d39e587f 100644
--- a/src/libide/search/ide-search-result.h
+++ b/src/libide/search/ide-search-result.h
@@ -70,6 +70,11 @@ IDE_AVAILABLE_IN_ALL
 void             ide_search_result_set_paintable (IdeSearchResult *self,
                                                   GdkPaintable    *paintable);
 IDE_AVAILABLE_IN_ALL
+GIcon           *ide_search_result_get_gicon     (IdeSearchResult *self);
+IDE_AVAILABLE_IN_ALL
+void             ide_search_result_set_gicon     (IdeSearchResult *self,
+                                                  GIcon           *gicon);
+IDE_AVAILABLE_IN_ALL
 const char      *ide_search_result_get_title     (IdeSearchResult *self);
 IDE_AVAILABLE_IN_ALL
 void             ide_search_result_set_title     (IdeSearchResult *self,


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