[gnome-builder] code: add gicon getter for symbol kind icons
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] code: add gicon getter for symbol kind icons
- Date: Wed, 13 Jul 2022 06:31:08 +0000 (UTC)
commit f6fb2f3730300257948b04c54b2c55e791ff0482
Author: Christian Hergert <chergert redhat com>
Date: Tue Jul 12 21:40:21 2022 -0700
code: add gicon getter for symbol kind icons
src/libide/code/ide-symbol.c | 33 +++++++++++++++++++++++++++++++++
src/libide/code/ide-symbol.h | 4 +++-
2 files changed, 36 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/code/ide-symbol.c b/src/libide/code/ide-symbol.c
index 7991226f6..a7df53a9e 100644
--- a/src/libide/code/ide-symbol.c
+++ b/src/libide/code/ide-symbol.c
@@ -416,6 +416,39 @@ ide_symbol_kind_get_icon_name (IdeSymbolKind kind)
return icon_name;
}
+/**
+ * ide_symbol_kind_get_gicon:
+ * @kind: a #IdeSymbolKind
+ *
+ * Gets a #GIcon to represent the symbol kind.
+ *
+ * Returns: (transfer none) (nullable): a #GIcon or %NULL
+ */
+GIcon *
+ide_symbol_kind_get_gicon (IdeSymbolKind kind)
+{
+ const char *icon_name;
+ GIcon *ret = NULL;
+
+ if ((icon_name = ide_symbol_kind_get_icon_name (kind)))
+ {
+ static GHashTable *cached;
+
+ if (cached == NULL)
+ cached = g_hash_table_new (NULL, NULL);
+
+ ret = g_hash_table_lookup (cached, icon_name);
+
+ if (ret == NULL)
+ {
+ ret = g_themed_icon_new (icon_name);
+ g_hash_table_insert (cached, (char *)icon_name, ret);
+ }
+ }
+
+ return ret;
+}
+
/**
* ide_symbol_to_variant:
* @self: a #IdeSymbol
diff --git a/src/libide/code/ide-symbol.h b/src/libide/code/ide-symbol.h
index cb3fa2f1b..20021bd45 100644
--- a/src/libide/code/ide-symbol.h
+++ b/src/libide/code/ide-symbol.h
@@ -131,6 +131,8 @@ IdeSymbol *ide_symbol_new_from_variant (GVariant *variant);
IDE_AVAILABLE_IN_ALL
GVariant *ide_symbol_to_variant (IdeSymbol *self);
IDE_AVAILABLE_IN_ALL
-const gchar *ide_symbol_kind_get_icon_name (IdeSymbolKind kind);
+const char *ide_symbol_kind_get_icon_name (IdeSymbolKind kind);
+IDE_AVAILABLE_IN_ALL
+GIcon *ide_symbol_kind_get_gicon (IdeSymbolKind kind);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]