[gnome-builder/gnome-builder-43] plugins/shellcmd: provide error messages for envvars



commit ee4944c514f4ea2f70215c60d87b871bfde8f653
Author: Christian Hergert <chergert redhat com>
Date:   Tue Oct 11 18:37:30 2022 -0500

    plugins/shellcmd: provide error messages for envvars
    
    Sorry translators! It's better for us to have any sort of error message
    than nothing at all. No rush to translate, but helpful if you do.
    
    Fixes #1854

 src/plugins/shellcmd/gbp-shellcmd-command-dialog.c  | 16 +++++++++++++++-
 src/plugins/shellcmd/gbp-shellcmd-command-dialog.ui |  1 +
 2 files changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command-dialog.c 
b/src/plugins/shellcmd/gbp-shellcmd-command-dialog.c
index 021f5d12c..5ac273b43 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command-dialog.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-command-dialog.c
@@ -146,6 +146,7 @@ static void
 on_env_entry_changed_cb (GbpShellcmdCommandDialog *self,
                          IdeEntryPopover          *popover)
 {
+  const char *errstr = NULL;
   gboolean valid = FALSE;
   const char *text;
   const char *eq;
@@ -156,14 +157,26 @@ on_env_entry_changed_cb (GbpShellcmdCommandDialog *self,
   text = ide_entry_popover_get_text (popover);
   eq = strchr (text, '=');
 
+  if (!ide_str_empty0 (text) && eq == NULL)
+    errstr = _("Use KEY=VALUE to set an environment variable");
+
   if (eq != NULL && eq != text)
     {
+      if (g_unichar_isdigit (g_utf8_get_char (text)))
+        {
+          errstr = _("Keys may not start with a number");
+          goto failure;
+
+        }
       for (const char *iter = text; iter < eq; iter = g_utf8_next_char (iter))
         {
           gunichar ch = g_utf8_get_char (iter);
 
           if (!g_unichar_isalnum (ch) && ch != '_')
-            goto failure;
+            {
+              errstr = _("Keys may only contain alpha-numerics or underline.");
+              goto failure;
+            }
         }
 
       if (g_ascii_isalpha (*text))
@@ -172,6 +185,7 @@ on_env_entry_changed_cb (GbpShellcmdCommandDialog *self,
 
 failure:
   ide_entry_popover_set_ready (popover, valid);
+  ide_entry_popover_set_message (popover, errstr);
 }
 
 static void
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command-dialog.ui 
b/src/plugins/shellcmd/gbp-shellcmd-command-dialog.ui
index ab2071864..d7a9f4451 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command-dialog.ui
+++ b/src/plugins/shellcmd/gbp-shellcmd-command-dialog.ui
@@ -209,6 +209,7 @@
                       <object class="IdeEntryPopover">
                         <property name="title" translatable="yes">Add Variable</property>
                         <property name="button-text" translatable="yes">_Add</property>
+                        <property name="width-request">400</property>
                         <signal name="changed" handler="on_env_entry_changed_cb" swapped="true" 
object="GbpShellcmdCommandDialog"/>
                         <signal name="activate" handler="on_env_entry_activate_cb" swapped="true" 
object="GbpShellcmdCommandDialog"/>
                       </object>


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