diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-10-26 13:21:28 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-10-26 22:42:28 -0400 |
commit | af6c3017fb0010dcba884da9bef686a92ae7215f (patch) | |
tree | 5512b1353306f5fbc301565024e53190fdcbcbe0 /gtk/gtkpopovermenubar.c | |
parent | 8157abe591059116cbea1a8ad7007fdd061ab0ba (diff) | |
download | gtk+-af6c3017fb0010dcba884da9bef686a92ae7215f.tar.gz |
popovermenu: Allow adding custom items in ui files
Support <child type="ID"> to fill custom child slots
in both GtkPopoverMenus and GtkPopoverMenuBars that
are created in ui files.
Diffstat (limited to 'gtk/gtkpopovermenubar.c')
-rw-r--r-- | gtk/gtkpopovermenubar.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/gtk/gtkpopovermenubar.c b/gtk/gtkpopovermenubar.c index 0d5658c224..8e7f2a22d0 100644 --- a/gtk/gtkpopovermenubar.c +++ b/gtk/gtkpopovermenubar.c @@ -73,6 +73,7 @@ #include "gtkwidgetprivate.h" #include "gtkmain.h" #include "gtknative.h" +#include "gtkbuildable.h" #define GTK_TYPE_POPOVER_MENU_BAR_ITEM (gtk_popover_menu_bar_item_get_type ()) #define GTK_POPOVER_MENU_BAR_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_POPOVER_MENU_BAR_ITEM, GtkPopoverMenuBarItem)) @@ -384,7 +385,11 @@ enum static GParamSpec * bar_props[LAST_PROP]; -G_DEFINE_TYPE (GtkPopoverMenuBar, gtk_popover_menu_bar, GTK_TYPE_WIDGET) +static void gtk_popover_menu_bar_buildable_iface_init (GtkBuildableIface *iface); + +G_DEFINE_TYPE_WITH_CODE (GtkPopoverMenuBar, gtk_popover_menu_bar, GTK_TYPE_WIDGET, + G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, + gtk_popover_menu_bar_buildable_iface_init)) static void tracker_remove (int position, @@ -650,6 +655,31 @@ gtk_popover_menu_bar_init (GtkPopoverMenuBar *bar) gtk_widget_add_controller (GTK_WIDGET (bar), controller); } +static GtkBuildableIface *parent_buildable_iface; + +static void +gtk_popover_menu_bar_buildable_add_child (GtkBuildable *buildable, + GtkBuilder *builder, + GObject *child, + const char *type) +{ + if (GTK_IS_WIDGET (child)) + { + if (!gtk_popover_menu_bar_add_child (GTK_POPOVER_MENU_BAR (buildable), GTK_WIDGET (child), type)) + g_warning ("No such custom attribute: %s", type); + } + else + parent_buildable_iface->add_child (buildable, builder, child, type); +} + +static void +gtk_popover_menu_bar_buildable_iface_init (GtkBuildableIface *iface) +{ + parent_buildable_iface = g_type_interface_peek_parent (iface); + + iface->add_child = gtk_popover_menu_bar_buildable_add_child; +} + /** * gtk_popover_menu_bar_new_from_model: * @model: (allow-none): a #GMenuModel, or %NULL |