summaryrefslogtreecommitdiff
path: root/gtk/gtkshortcutaction.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2018-08-24 06:58:44 +0200
committerMatthias Clasen <mclasen@redhat.com>2020-03-25 23:14:28 -0400
commit33045c3e0b061f52d292b037449b1276d388ee8d (patch)
tree5dc6fdcef82d960cb06dc20a18ce3cbdcf4dfca3 /gtk/gtkshortcutaction.c
parent7974751e2432178686b13f9057efcb7dbe39af60 (diff)
downloadgtk+-33045c3e0b061f52d292b037449b1276d388ee8d.tar.gz
shortcutaction: Integrate with GtkBuilder property parsing
<property name="action">action(win.quit)</property> style action specifications now work for GtkShortcutAction properties.
Diffstat (limited to 'gtk/gtkshortcutaction.c')
-rw-r--r--gtk/gtkshortcutaction.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/gtk/gtkshortcutaction.c b/gtk/gtkshortcutaction.c
index f919954e50..301985bd9a 100644
--- a/gtk/gtkshortcutaction.c
+++ b/gtk/gtkshortcutaction.c
@@ -37,8 +37,9 @@
#include "config.h"
-#include "gtkshortcutaction.h"
+#include "gtkshortcutactionprivate.h"
+#include "gtkbuilder.h"
#include "gtkwidgetprivate.h"
typedef struct _GtkShortcutActionClass GtkShortcutActionClass;
@@ -226,6 +227,62 @@ gtk_shortcut_action_activate (GtkShortcutAction *self,
return self->action_class->activate (self, flags, widget, args);
}
+static char *
+string_is_function (const char *string,
+ const char *function_name)
+{
+ gsize len;
+
+ if (!g_str_has_prefix (string, function_name))
+ return NULL;
+ string += strlen (function_name);
+
+ if (string[0] != '(')
+ return NULL;
+ string ++;
+
+ len = strlen (string);
+ if (len == 0 || string[len - 1] != ')')
+ return NULL;
+
+ return g_strndup (string, len - 1);
+}
+
+GtkShortcutAction *
+gtk_shortcut_action_parse_builder (GtkBuilder *builder,
+ const char *string,
+ GError **error)
+{
+ GtkShortcutAction *result;
+ char *arg;
+
+ if (g_str_equal (string, "nothing"))
+ return gtk_nothing_action_new ();
+ if (g_str_equal (string, "activate"))
+ return gtk_activate_action_new ();
+ if (g_str_equal (string, "mnemonic-activate"))
+ return gtk_mnemonic_action_new ();
+
+ if ((arg = string_is_function (string, "action")))
+ {
+ result = gtk_action_action_new (arg);
+ g_free (arg);
+ }
+ else if ((arg = string_is_function (string, "signal")))
+ {
+ result = gtk_signal_action_new (arg);
+ g_free (arg);
+ }
+ {
+ g_set_error (error,
+ GTK_BUILDER_ERROR, GTK_BUILDER_ERROR_INVALID_VALUE,
+ "String \"%s\" does not specify a GtkShortcutAction", string);
+ return NULL;
+ }
+
+ return result;
+}
+
/*** GTK_SHORTCUT_ACTION_NOTHING ***/
typedef struct _GtkNothingAction GtkNothingAction;