[gnome-builder/gnome-builder-43] libide/code: add IdeSymbolNode:display-name



commit 433ff6498dc8b79df2ce9480980a00489a770a30
Author: Christian Hergert <chergert redhat com>
Date:   Wed Sep 21 16:30:47 2022 -0700

    libide/code: add IdeSymbolNode:display-name
    
    This way we can separate items that have names and their display format
    (which is pango markup). The only thing using that was the xml symbol
    node, which we can quick fixup.
    
    This fixes showing things like impl<foo> in the symbol tree from languages
    that, you know, aren't xml.

 src/libide/code/ide-symbol-node.c                 | 25 ++++++++++++++++++++++-
 src/plugins/symbol-tree/gbp-symbol-popover-row.ui |  2 +-
 src/plugins/xml-pack/ide-xml-symbol-node.c        |  3 ++-
 3 files changed, 27 insertions(+), 3 deletions(-)
---
diff --git a/src/libide/code/ide-symbol-node.c b/src/libide/code/ide-symbol-node.c
index 5feade1e5..8dea9b4ac 100644
--- a/src/libide/code/ide-symbol-node.c
+++ b/src/libide/code/ide-symbol-node.c
@@ -31,7 +31,8 @@
 
 typedef struct
 {
-  gchar          *name;
+  char           *name;
+  char           *display_name;
   IdeSymbolFlags  flags;
   IdeSymbolKind   kind;
   guint           use_markup : 1;
@@ -41,6 +42,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (IdeSymbolNode, ide_symbol_node, G_TYPE_OBJECT)
 
 enum {
   PROP_0,
+  PROP_DISPLAY_NAME,
   PROP_FLAGS,
   PROP_KIND,
   PROP_NAME,
@@ -104,6 +106,7 @@ ide_symbol_node_finalize (GObject *object)
   IdeSymbolNodePrivate *priv = ide_symbol_node_get_instance_private (self);
 
   g_clear_pointer (&priv->name, g_free);
+  g_clear_pointer (&priv->display_name, g_free);
 
   G_OBJECT_CLASS (ide_symbol_node_parent_class)->finalize (object);
 }
@@ -115,6 +118,7 @@ ide_symbol_node_get_property (GObject    *object,
                               GParamSpec *pspec)
 {
   IdeSymbolNode *self = IDE_SYMBOL_NODE (object);
+  IdeSymbolNodePrivate *priv = ide_symbol_node_get_instance_private (self);
 
   switch (prop_id)
     {
@@ -122,6 +126,15 @@ ide_symbol_node_get_property (GObject    *object,
       g_value_set_string (value, ide_symbol_node_get_name (self));
       break;
 
+    case PROP_DISPLAY_NAME:
+    {
+      if (priv->display_name)
+        g_value_set_string (value, priv->display_name);
+      else if (priv->name)
+        g_value_take_string (value, g_markup_escape_text (priv->name, -1));
+      break;
+    }
+
     case PROP_ICON_NAME:
       g_value_set_static_string (value, ide_symbol_node_get_icon_name (self));
       break;
@@ -159,6 +172,11 @@ ide_symbol_node_set_property (GObject      *object,
       priv->name = g_value_dup_string (value);
       break;
 
+    case PROP_DISPLAY_NAME:
+      g_free (priv->display_name);
+      priv->display_name = g_value_dup_string (value);
+      break;
+
     case PROP_KIND:
       priv->kind = g_value_get_enum (value);
       g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON_NAME]);
@@ -189,6 +207,11 @@ ide_symbol_node_class_init (IdeSymbolNodeClass *klass)
   object_class->get_property = ide_symbol_node_get_property;
   object_class->set_property = ide_symbol_node_set_property;
 
+  properties [PROP_DISPLAY_NAME] =
+    g_param_spec_string ("display-name", NULL, NULL,
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_NAME] =
     g_param_spec_string ("name",
                          "Name",
diff --git a/src/plugins/symbol-tree/gbp-symbol-popover-row.ui 
b/src/plugins/symbol-tree/gbp-symbol-popover-row.ui
index 329c9cfc4..c1ba86f8a 100644
--- a/src/plugins/symbol-tree/gbp-symbol-popover-row.ui
+++ b/src/plugins/symbol-tree/gbp-symbol-popover-row.ui
@@ -24,7 +24,7 @@
                 <property name="use-markup">true</property>
                 <property name="single-line-mode">true</property>
                 <binding name="label">
-                  <lookup name="name" type="IdeSymbolNode">
+                  <lookup name="display-name" type="IdeSymbolNode">
                     <lookup name="item">expander</lookup>
                   </lookup>
                 </binding>
diff --git a/src/plugins/xml-pack/ide-xml-symbol-node.c b/src/plugins/xml-pack/ide-xml-symbol-node.c
index 229f5456e..6d4afaa86 100644
--- a/src/plugins/xml-pack/ide-xml-symbol-node.c
+++ b/src/plugins/xml-pack/ide-xml-symbol-node.c
@@ -153,7 +153,8 @@ ide_xml_symbol_node_new (const gchar   *name,
   IdeSymbolFlags flags = IDE_SYMBOL_FLAGS_NONE;
 
   self = g_object_new (IDE_TYPE_XML_SYMBOL_NODE,
-                       "name", name,
+                       "name", ide_str_empty0 (element_name) ? "unknown" : element_name,
+                       "display-name", name,
                        "kind", kind,
                        "flags", flags,
                        NULL);


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