[gtk/wip/matthiasc/shortcut: 82/91] shortcuttrigger: Add gtk_shortcut_triger_new_parse_string()
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/shortcut: 82/91] shortcuttrigger: Add gtk_shortcut_triger_new_parse_string()
- Date: Sun, 15 Mar 2020 18:48:41 +0000 (UTC)
commit 9895383de9385ed02d01414914d4303d49e6b268
Author: Benjamin Otte <otte redhat com>
Date: Thu Aug 23 21:07:36 2018 +0200
shortcuttrigger: Add gtk_shortcut_triger_new_parse_string()
And hook it up into the GtkBuilder infrastructure.
docs/reference/gtk/gtk4-sections.txt | 1 +
gtk/gtkbuilder.c | 20 +++++++++++++++++++-
gtk/gtkshortcuttrigger.c | 29 +++++++++++++++++++++++++++++
gtk/gtkshortcuttrigger.h | 3 +++
4 files changed, 52 insertions(+), 1 deletion(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index ecdd4e3b8c..d532947dd0 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -6008,6 +6008,7 @@ gtk_shortcut_trigger_ref
gtk_shortcut_trigger_unref
GtkShortcutTriggerType
gtk_shortcut_trigger_get_trigger_type
+gtk_shortcut_trigger_parse_string
gtk_shortcut_trigger_trigger
gtk_shortcut_trigger_hash
gtk_shortcut_trigger_equal
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index ba3f367ddc..e841be2ea1 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -219,12 +219,14 @@
#include "gtkbuilderscopeprivate.h"
#include "gtkdebug.h"
#include "gtkmain.h"
+#include "gtkicontheme.h"
#include "gtkintl.h"
#include "gtkprivate.h"
+#include "gtkshortcuttrigger.h"
+#include "gtktestutils.h"
#include "gtktypebuiltins.h"
#include "gtkicontheme.h"
#include "gtkiconthemeprivate.h"
-#include "gdkpixbufutilsprivate.h"
static void gtk_builder_finalize (GObject *object);
static void gtk_builder_set_property (GObject *object,
@@ -2092,6 +2094,22 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
ret = FALSE;
}
}
+ else if (G_VALUE_HOLDS (value, GTK_TYPE_SHORTCUT_TRIGGER))
+ {
+ GtkShortcutTrigger *trigger = gtk_shortcut_trigger_parse_string (string);
+
+ if (trigger)
+ g_value_take_boxed (value, trigger);
+ else
+ {
+ g_set_error (error,
+ GTK_BUILDER_ERROR,
+ GTK_BUILDER_ERROR_INVALID_VALUE,
+ "Could not parse shortcut trigger '%s'",
+ string);
+ ret = FALSE;
+ }
+ }
else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
{
gchar **vector = g_strsplit (string, "\n", 0);
diff --git a/gtk/gtkshortcuttrigger.c b/gtk/gtkshortcuttrigger.c
index 2f4a25ddb7..4990677755 100644
--- a/gtk/gtkshortcuttrigger.c
+++ b/gtk/gtkshortcuttrigger.c
@@ -181,6 +181,35 @@ gtk_shortcut_trigger_trigger (GtkShortcutTrigger *self,
return self->trigger_class->trigger (self, event, enable_mnemonics);
}
+/**
+ * gtk_shortcut_trigger_parse_string:
+ * @string: the string to parse
+ *
+ * Tries to parse the given string into a trigger. On success,
+ * the parsed trigger is returned. When parsing failed, %NULL is
+ * returned.
+ *
+ * FIXME: Document the supported format here once we've figured
+ * it out.
+ * For now, this function only supports gtk_accelerator_parse() and
+ * can only return a trigger of type %GTK_SHORTCUT_TRIGGER_KEYVAL.
+ *
+ * Returns: a new #GtkShortcutTrigger or %NULL on error
+ **/
+GtkShortcutTrigger *
+gtk_shortcut_trigger_parse_string (const char *string)
+{
+ GdkModifierType modifiers;
+ guint keyval;
+
+ g_return_val_if_fail (string != NULL, NULL);
+
+ if (gtk_accelerator_parse (string, &keyval, &modifiers))
+ return gtk_keyval_trigger_new (keyval, modifiers);
+
+ return NULL;
+}
+
/**
* gtk_shortcut_trigger_to_string:
* @self: a #GtkShortcutTrigger
diff --git a/gtk/gtkshortcuttrigger.h b/gtk/gtkshortcuttrigger.h
index 85bbd441ff..b0ab8af862 100644
--- a/gtk/gtkshortcuttrigger.h
+++ b/gtk/gtkshortcuttrigger.h
@@ -62,6 +62,9 @@ void gtk_shortcut_trigger_unref (GtkShortcutTrig
GDK_AVAILABLE_IN_ALL
GtkShortcutTriggerType gtk_shortcut_trigger_get_trigger_type (GtkShortcutTrigger *self);
+GDK_AVAILABLE_IN_ALL
+GtkShortcutTrigger * gtk_shortcut_trigger_parse_string (const char *string);
+
GDK_AVAILABLE_IN_ALL
char * gtk_shortcut_trigger_to_string (GtkShortcutTrigger *self);
GDK_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]