[gnome-builder/wip/gtk4-port: 1116/1774] plugins/buildui: add command as a subtitle




commit d7d57a98d26067ef2a8c0867818624e2decd4ae9
Author: Christian Hergert <chergert redhat com>
Date:   Sun May 22 10:51:02 2022 -0700

    plugins/buildui: add command as a subtitle

 src/plugins/buildui/gbp-buildui-runnables-dialog.c | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
---
diff --git a/src/plugins/buildui/gbp-buildui-runnables-dialog.c 
b/src/plugins/buildui/gbp-buildui-runnables-dialog.c
index 766b0d6d2..ccd1837b7 100644
--- a/src/plugins/buildui/gbp-buildui-runnables-dialog.c
+++ b/src/plugins/buildui/gbp-buildui-runnables-dialog.c
@@ -55,6 +55,8 @@ create_run_command_row (gpointer item,
 {
   IdeRunCommand *run_command = item;
   g_autoptr(GVariant) idv = NULL;
+  g_autoptr(GString) subtitle = NULL;
+  const char * const *argv;
   AdwActionRow *row;
   const char *id;
   GtkWidget *check;
@@ -63,6 +65,38 @@ create_run_command_row (gpointer item,
 
   id = ide_run_command_get_id (run_command);
   idv = g_variant_take_ref (g_variant_new_string (id ? id : ""));
+  argv = ide_run_command_get_argv (run_command);
+
+  if (argv != NULL)
+    {
+      subtitle = g_string_new (NULL);
+
+      for (guint i = 0; argv[i]; i++)
+        {
+          const char *arg = argv[i];
+          g_autofree char *quote = NULL;
+
+          if (i > 0)
+            g_string_append_c (subtitle, ' ');
+
+          /* NOTE: Params can be file-system encoding, but everywhere we run
+           * that is UTF-8. May need to adjust should that change.
+           */
+          for (const char *c = arg; *c; c = g_utf8_next_char (c))
+            {
+              if (*c == ' ' || *c == '"' || *c == '\'')
+                {
+                  quote = g_shell_quote (arg);
+                  break;
+                }
+            }
+
+          if (quote)
+            g_string_append (subtitle, quote);
+          else
+            g_string_append (subtitle, arg);
+        }
+    }
 
   check = g_object_new (GTK_TYPE_CHECK_BUTTON,
                         "action-name", "run-manager.default-run-command",
@@ -73,6 +107,7 @@ create_run_command_row (gpointer item,
                         NULL);
   row = g_object_new (ADW_TYPE_ACTION_ROW,
                       "title", ide_run_command_get_display_name (item),
+                      "subtitle", subtitle ? subtitle->str : NULL,
                       "activatable-widget", check,
                       NULL);
   adw_action_row_add_suffix (row, check);


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