[gtk/popover-menu-custom-child: 1/3] popovermenu: 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: 1/3] popovermenu: Allow adding custom items in ui files
- Date: Mon, 26 Oct 2020 20:17:08 +0000 (UTC)
commit f160fdaceb8da80fe06503d8c6bac2574cb7f4b0
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Oct 26 13:21:28 2020 -0400
popovermenu: Allow adding custom items in ui files
Support <child type="ID"> to fill custom child slots.
gtk/gtkpopovermenu.c | 35 +++++++++++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c
index cd54fe600d..89b362956e 100644
--- a/gtk/gtkpopovermenu.c
+++ b/gtk/gtkpopovermenu.c
@@ -35,6 +35,7 @@
#include "gtkpopovermenubar.h"
#include "gtkshortcutmanager.h"
#include "gtkshortcutcontroller.h"
+#include "gtkbuildable.h"
/**
@@ -99,7 +100,8 @@
* Possible values include "action-disabled", "action-missing", "macos-menubar".
* This is mainly useful for exported menus, see gtk_application_set_menubar().
* - "custom": a string used to match against the ID of a custom child added
- * with gtk_popover_menu_add_child() or gtk_popover_menu_bar_add_child().
+ * with gtk_popover_menu_add_child(), gtk_popover_menu_bar_add_child(), or
+ * in the ui file with `<child type="ID">`.
*
* The following attributes are used when constructing sections:
* - "label": a user-visible string to use as section heading
@@ -149,7 +151,11 @@ enum {
PROP_MENU_MODEL
};
-G_DEFINE_TYPE (GtkPopoverMenu, gtk_popover_menu, GTK_TYPE_POPOVER)
+static void gtk_popover_menu_buildable_iface_init (GtkBuildableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GtkPopoverMenu, gtk_popover_menu, GTK_TYPE_POPOVER,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+ gtk_popover_menu_buildable_iface_init))
GtkWidget *
gtk_popover_menu_get_parent_menu (GtkPopoverMenu *menu)
@@ -549,6 +555,31 @@ gtk_popover_menu_class_init (GtkPopoverMenuClass *klass)
"activate-default", NULL);
}
+static GtkBuildableIface *parent_buildable_iface;
+
+static void
+gtk_popover_menu_buildable_add_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const char *type)
+{
+ if (GTK_IS_WIDGET (child))
+ {
+ if (!gtk_popover_menu_add_child (GTK_POPOVER_MENU (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_buildable_iface_init (GtkBuildableIface *iface)
+{
+ parent_buildable_iface = g_type_interface_peek_parent (iface);
+
+ iface->add_child = gtk_popover_menu_buildable_add_child;
+}
+
/**
* gtk_popover_menu_new:
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]