summaryrefslogtreecommitdiff
path: root/gtk/gtkshortcuttrigger.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2020-03-26 16:58:55 +0000
committerEmmanuele Bassi <ebassi@gnome.org>2020-03-27 14:35:00 +0000
commit6719d3044dc1677c264086345f2ef6084a63e590 (patch)
tree0b979da3f780c9a03d08a0cc4c726e8ac7afc896 /gtk/gtkshortcuttrigger.c
parentc75fdda8ddb0c0593f2f7d5cb7aa43f215462808 (diff)
downloadgtk+-6719d3044dc1677c264086345f2ef6084a63e590.tar.gz
Add parsing for GtkAlternativeTrigger
Alternative triggers are separate by a pipe character.
Diffstat (limited to 'gtk/gtkshortcuttrigger.c')
-rw-r--r--gtk/gtkshortcuttrigger.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/gtk/gtkshortcuttrigger.c b/gtk/gtkshortcuttrigger.c
index 6840ef10d2..0fdc5edb17 100644
--- a/gtk/gtkshortcuttrigger.c
+++ b/gtk/gtkshortcuttrigger.c
@@ -120,6 +120,8 @@ gtk_shortcut_trigger_trigger (GtkShortcutTrigger *self,
* - `never`, for #GtkNeverTrigger
* - a string parsed by gtk_accelerator_parse(), for a #GtkKeyvalTrigger
* - underscore, followed by a single character, for #GtkMnemonicTrigger
+ * - two valid trigger strings, separated by a `|` character, for a
+ * #GtkAlternativeTrigger
*
* Returns: (nullable) (transfer full): a new #GtkShortcutTrigger
* or %NULL on error
@@ -129,9 +131,44 @@ gtk_shortcut_trigger_parse_string (const char *string)
{
GdkModifierType modifiers;
guint keyval;
+ const char *sep;
g_return_val_if_fail (string != NULL, NULL);
+ if ((sep = strchr (string, '|')) != NULL)
+ {
+ char *frag_a = g_strndup (string, sep - string);
+ const char *frag_b = sep + 1;
+ GtkShortcutTrigger *t1, *t2;
+
+ /* empty first slot */
+ if (*frag_a == '\0')
+ return NULL;
+
+ /* empty second slot */
+ if (*frag_b == '\0')
+ return NULL;
+
+ t1 = gtk_shortcut_trigger_parse_string (frag_a);
+ if (t1 == NULL)
+ {
+ g_free (frag_a);
+ return NULL;
+ }
+
+ t2 = gtk_shortcut_trigger_parse_string (frag_b);
+ if (t2 == NULL)
+ {
+ g_object_unref (t1);
+ g_free (frag_a);
+ return NULL;
+ }
+
+ g_free (frag_a);
+
+ return gtk_alternative_trigger_new (t1, t2);
+ }
+
if (g_str_equal (string, "never"))
return g_object_ref (gtk_never_trigger_get ());
@@ -398,7 +435,7 @@ static void
gtk_never_trigger_print (GtkShortcutTrigger *trigger,
GString *string)
{
- g_string_append (string, "<never>");
+ g_string_append (string, "never");
}
static gboolean
@@ -1091,7 +1128,7 @@ gtk_alternative_trigger_print (GtkShortcutTrigger *trigger,
GtkAlternativeTrigger *self = GTK_ALTERNATIVE_TRIGGER (trigger);
gtk_shortcut_trigger_print (self->first, string);
- g_string_append (string, ", ");
+ g_string_append (string, "|");
gtk_shortcut_trigger_print (self->second, string);
}