[gnome-builder] plugins/buildui: provide error messages for envvars
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/buildui: provide error messages for envvars
- Date: Wed, 12 Oct 2022 00:13:43 +0000 (UTC)
commit d5b0bc1e97c3765da3eedc05151a8a6a889347c9
Author: Christian Hergert <chergert redhat com>
Date: Tue Oct 11 18:37:10 2022 -0500
plugins/buildui: provide error messages for envvars
src/plugins/buildui/gbp-buildui-environment-editor.c | 18 +++++++++++++++++-
src/plugins/buildui/gbp-buildui-environment-editor.ui | 1 +
2 files changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/buildui/gbp-buildui-environment-editor.c
b/src/plugins/buildui/gbp-buildui-environment-editor.c
index 6996ad7f9..8a6493d86 100644
--- a/src/plugins/buildui/gbp-buildui-environment-editor.c
+++ b/src/plugins/buildui/gbp-buildui-environment-editor.c
@@ -22,6 +22,8 @@
#include "config.h"
+#include <glib/gi18n.h>
+
#include <libide-gtk.h>
#include "gbp-buildui-environment-editor.h"
@@ -134,6 +136,7 @@ static void
on_entry_changed_cb (GbpBuilduiEnvironmentEditor *self,
IdeEntryPopover *popover)
{
+ const char *errstr = NULL;
gboolean valid = FALSE;
const char *text;
const char *eq;
@@ -144,14 +147,26 @@ on_entry_changed_cb (GbpBuilduiEnvironmentEditor *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))
@@ -160,6 +175,7 @@ on_entry_changed_cb (GbpBuilduiEnvironmentEditor *self,
failure:
ide_entry_popover_set_ready (popover, valid);
+ ide_entry_popover_set_message (popover, errstr);
}
static void
diff --git a/src/plugins/buildui/gbp-buildui-environment-editor.ui
b/src/plugins/buildui/gbp-buildui-environment-editor.ui
index b29aa9e08..01c6c2ff1 100644
--- a/src/plugins/buildui/gbp-buildui-environment-editor.ui
+++ b/src/plugins/buildui/gbp-buildui-environment-editor.ui
@@ -28,6 +28,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="activate" handler="on_entry_activate_cb" swapped="true"
object="GbpBuilduiEnvironmentEditor"/>
<signal name="changed" handler="on_entry_changed_cb" swapped="true"
object="GbpBuilduiEnvironmentEditor"/>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]