[gnome-builder] libide/foundry: add read-only title property for run command



commit d0bf6b4884537b78e65efed95ecda342772c61b7
Author: Christian Hergert <chergert redhat com>
Date:   Fri Aug 26 17:31:43 2022 -0700

    libide/foundry: add read-only title property for run command
    
    This is meant to be like display-name but have various fallbacks to give
    you something non-NULL/empty for use in UI elements.

 src/libide/foundry/ide-run-command.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
---
diff --git a/src/libide/foundry/ide-run-command.c b/src/libide/foundry/ide-run-command.c
index 6f7027c1b..642473c93 100644
--- a/src/libide/foundry/ide-run-command.c
+++ b/src/libide/foundry/ide-run-command.c
@@ -55,6 +55,7 @@ enum {
   PROP_KIND,
   PROP_LANGUAGES,
   PROP_PRIORITY,
+  PROP_TITLE,
 
   /* Just for making listview's easier */
   PROP_CATEGORY,
@@ -160,6 +161,22 @@ ide_run_command_real_prepare_to_run (IdeRunCommand *self,
   IDE_EXIT;
 }
 
+static const char *
+ide_run_command_get_title (IdeRunCommand *self)
+{
+  IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
+
+  g_assert (IDE_IS_RUN_COMMAND (self));
+
+  if (!ide_str_empty0 (priv->display_name))
+    return priv->display_name;
+
+  if (priv->argv && !ide_str_empty0 (priv->argv[0]))
+    return priv->argv[0];
+
+  return _("Untitled command");
+}
+
 static void
 ide_run_command_finalize (GObject *object)
 {
@@ -248,6 +265,10 @@ ide_run_command_get_property (GObject    *object,
       g_value_take_string (value, ide_run_command_get_shell_command (self));
       break;
 
+    case PROP_TITLE:
+      g_value_set_string (value, ide_run_command_get_title (self));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -391,11 +412,18 @@ ide_run_command_class_init (IdeRunCommandClass *klass)
                       G_MININT, G_MAXINT, 0,
                       (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
 
+  /* Read-only helper for property bindings */
   properties [PROP_SHELL_COMMAND] =
     g_param_spec_string ("shell-command", NULL, NULL,
                          NULL,
                          (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
+  /* Read-only helper for binding to a non-empty title string in UI */
+  properties [PROP_TITLE] =
+    g_param_spec_string ("title", NULL, NULL,
+                         NULL,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_properties (object_class, N_PROPS, properties);
 }
 


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