[gtk/popover-menu-custom-child] popovermenubar: Allow adding custom items in ui files
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/popover-menu-custom-child] popovermenubar: Allow adding custom items in ui files
- Date: Mon, 26 Oct 2020 17:28:46 +0000 (UTC)
commit 33447e1e92ef9003c05bbc1f1f730f2f239a7584
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Oct 26 13:26:55 2020 -0400
popovermenubar: Allow adding custom items in ui files
Just as for popover menus, support <child type="ID"> to fill
custom child slots.
gtk/gtkpopovermenubar.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkpopovermenubar.c b/gtk/gtkpopovermenubar.c
index cb00bba68a..148d182e92 100644
--- a/gtk/gtkpopovermenubar.c
+++ b/gtk/gtkpopovermenubar.c
@@ -67,6 +67,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))
@@ -350,7 +351,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,
@@ -611,6 +616,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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]