[gnome-builder] foundry: add plaintext name property



commit 1b478858571653f181c21b17225a29f89e3b28cd
Author: Christian Hergert <chergert redhat com>
Date:   Thu May 2 11:23:14 2019 -0700

    foundry: add plaintext name property
    
    This is useful for situations where you cannot use display-name with
    pango markup.

 src/libide/foundry/ide-runtime.c | 46 +++++++++++++++++++++++++++++++++++++++-
 src/libide/foundry/ide-runtime.h |  5 +++++
 2 files changed, 50 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/foundry/ide-runtime.c b/src/libide/foundry/ide-runtime.c
index 80c2227ec..b11586052 100644
--- a/src/libide/foundry/ide-runtime.c
+++ b/src/libide/foundry/ide-runtime.c
@@ -38,6 +38,7 @@ typedef struct
 {
   gchar *id;
   gchar *category;
+  gchar *name;
   gchar *display_name;
 } IdeRuntimePrivate;
 
@@ -48,6 +49,7 @@ enum {
   PROP_ID,
   PROP_CATEGORY,
   PROP_DISPLAY_NAME,
+  PROP_NAME,
   N_PROPS
 };
 
@@ -292,6 +294,7 @@ ide_runtime_finalize (GObject *object)
 
   g_clear_pointer (&priv->id, g_free);
   g_clear_pointer (&priv->display_name, g_free);
+  g_clear_pointer (&priv->name, g_free);
 
   G_OBJECT_CLASS (ide_runtime_parent_class)->finalize (object);
 }
@@ -318,6 +321,10 @@ ide_runtime_get_property (GObject    *object,
       g_value_set_string (value, ide_runtime_get_display_name (self));
       break;
 
+    case PROP_NAME:
+      g_value_set_string (value, ide_runtime_get_name (self));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -345,6 +352,10 @@ ide_runtime_set_property (GObject      *object,
       ide_runtime_set_display_name (self, g_value_get_string (value));
       break;
 
+    case PROP_NAME:
+      ide_runtime_set_name (self, g_value_get_string (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -389,6 +400,13 @@ ide_runtime_class_init (IdeRuntimeClass *klass)
                          NULL,
                          (G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_NAME] =
+    g_param_spec_string ("name",
+                         "Name",
+                         "Name",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_properties (object_class, N_PROPS, properties);
 }
 
@@ -454,6 +472,32 @@ ide_runtime_set_category (IdeRuntime  *self,
     }
 }
 
+const gchar *
+ide_runtime_get_name (IdeRuntime *self)
+{
+  IdeRuntimePrivate *priv = ide_runtime_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_RUNTIME (self), NULL);
+
+  return priv->name ? priv->name : priv->display_name;
+}
+
+void
+ide_runtime_set_name (IdeRuntime  *self,
+                      const gchar *name)
+{
+  IdeRuntimePrivate *priv = ide_runtime_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_RUNTIME (self));
+
+  if (g_strcmp0 (name, priv->name) != 0)
+    {
+      g_free (priv->name);
+      priv->name = g_strdup (name);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_NAME]);
+    }
+}
+
 const gchar *
 ide_runtime_get_display_name (IdeRuntime *self)
 {
@@ -461,7 +505,7 @@ ide_runtime_get_display_name (IdeRuntime *self)
 
   g_return_val_if_fail (IDE_IS_RUNTIME (self), NULL);
 
-  return priv->display_name;
+  return priv->display_name ? priv->display_name : priv->name;
 }
 
 void
diff --git a/src/libide/foundry/ide-runtime.h b/src/libide/foundry/ide-runtime.h
index eb3907027..aae54d3b4 100644
--- a/src/libide/foundry/ide-runtime.h
+++ b/src/libide/foundry/ide-runtime.h
@@ -103,6 +103,11 @@ IDE_AVAILABLE_IN_3_32
 void                    ide_runtime_set_display_name         (IdeRuntime      *self,
                                                               const gchar     *display_name);
 IDE_AVAILABLE_IN_3_32
+const gchar            *ide_runtime_get_name                 (IdeRuntime      *self);
+IDE_AVAILABLE_IN_3_32
+void                    ide_runtime_set_name                 (IdeRuntime      *self,
+                                                              const gchar     *name);
+IDE_AVAILABLE_IN_3_32
 GFile                  *ide_runtime_translate_file           (IdeRuntime      *self,
                                                               GFile           *file);
 IDE_AVAILABLE_IN_3_32


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