summaryrefslogtreecommitdiff
path: root/gtk/gtkshortcutcontroller.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2018-08-24 07:00:12 +0200
committerMatthias Clasen <mclasen@redhat.com>2020-03-25 23:14:28 -0400
commit78e3e42042abc81a2710eb461070a040553e125c (patch)
treea0361ddb3d596701c1565c3f4a4b57615b49bc79 /gtk/gtkshortcutcontroller.c
parent33045c3e0b061f52d292b037449b1276d388ee8d (diff)
downloadgtk+-78e3e42042abc81a2710eb461070a040553e125c.tar.gz
shortcutcontroller: Implement GtkBuildable
Use it to allow adding shortcuts to the controller via the usual <child> method.
Diffstat (limited to 'gtk/gtkshortcutcontroller.c')
-rw-r--r--gtk/gtkshortcutcontroller.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/gtk/gtkshortcutcontroller.c b/gtk/gtkshortcutcontroller.c
index cd5a17bb56..f85662b332 100644
--- a/gtk/gtkshortcutcontroller.c
+++ b/gtk/gtkshortcutcontroller.c
@@ -35,6 +35,7 @@
#include "gtkshortcutcontrollerprivate.h"
#include "gtkflattenlistmodel.h"
+#include "gtkbuildable.h"
#include "gtkeventcontrollerprivate.h"
#include "gtkintl.h"
#include "gtkshortcut.h"
@@ -103,9 +104,37 @@ gtk_shortcut_controller_list_model_init (GListModelInterface *iface)
iface->get_item = gtk_shortcut_controller_list_model_get_item;
}
+static void
+gtk_shortcut_controller_buildable_add_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *type)
+{
+ if (type != NULL)
+ {
+ GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type);
+ }
+ if (GTK_IS_SHORTCUT (child))
+ {
+ gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (buildable), GTK_SHORTCUT (child));
+ }
+ else
+ {
+ g_warning ("Cannot add an object of type %s to a controller of type %s",
+ g_type_name (G_OBJECT_TYPE (child)), g_type_name (G_OBJECT_TYPE (buildable)));
+ }
+}
+
+static void
+gtk_shortcut_controller_buildable_init (GtkBuildableIface *iface)
+{
+ iface->add_child = gtk_shortcut_controller_buildable_add_child;
+}
+
G_DEFINE_TYPE_WITH_CODE (GtkShortcutController, gtk_shortcut_controller,
GTK_TYPE_EVENT_CONTROLLER,
- G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, gtk_shortcut_controller_list_model_init))
+ G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, gtk_shortcut_controller_list_model_init)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, gtk_shortcut_controller_buildable_init))
static gboolean
gtk_shortcut_controller_is_rooted (GtkShortcutController *self)