[gtk/wip/cdavis/menu-item-markup] Add support for pango markup in menu items
- From: Christopher Davis <christopherdavis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/cdavis/menu-item-markup] Add support for pango markup in menu items
- Date: Thu, 7 Oct 2021 09:49:19 +0000 (UTC)
commit 0775e2113106ec42e780780489f236e4317ea749
Author: Christopher Davis <christopherdavis gnome org>
Date: Thu Oct 7 02:32:31 2021 -0700
Add support for pango markup in menu items
Before https://gitlab.gnome.org/GNOME/gtk/-/commit/c4a2234a28456fda5034bbaa155a1f8f76a6bebc
menu models could use markup for items and the markup would
be parsed, but this was not intended behavior.
This commit adds official support for using markup
for menu items via the `use-markup` property.
Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/4306
gtk/gtkmenusectionbox.c | 1 +
gtk/gtkmenutrackeritem.c | 12 ++++++++++++
gtk/gtkmenutrackeritemprivate.h | 2 ++
gtk/gtkpopovermenu.c | 1 +
4 files changed, 16 insertions(+)
---
diff --git a/gtk/gtkmenusectionbox.c b/gtk/gtkmenusectionbox.c
index 6d3251e341..72ca8c8b1a 100644
--- a/gtk/gtkmenusectionbox.c
+++ b/gtk/gtkmenusectionbox.c
@@ -427,6 +427,7 @@ gtk_menu_section_box_insert_func (GtkMenuTrackerItem *item,
else
g_object_bind_property (item, "icon", widget, "icon", G_BINDING_SYNC_CREATE);
+ g_object_bind_property (item, "use-markup", widget, "use-markup", G_BINDING_SYNC_CREATE);
g_object_bind_property (item, "sensitive", widget, "sensitive", G_BINDING_SYNC_CREATE);
g_object_bind_property (item, "role", widget, "role", G_BINDING_SYNC_CREATE);
g_object_bind_property (item, "toggled", widget, "active", G_BINDING_SYNC_CREATE);
diff --git a/gtk/gtkmenutrackeritem.c b/gtk/gtkmenutrackeritem.c
index 4e191221e2..70ac0de8aa 100644
--- a/gtk/gtkmenutrackeritem.c
+++ b/gtk/gtkmenutrackeritem.c
@@ -106,6 +106,7 @@ enum {
PROP_0,
PROP_IS_SEPARATOR,
PROP_LABEL,
+ PROP_USE_MARKUP,
PROP_ICON,
PROP_VERB_ICON,
PROP_SENSITIVE,
@@ -162,6 +163,9 @@ gtk_menu_tracker_item_get_property (GObject *object,
case PROP_LABEL:
g_value_set_string (value, gtk_menu_tracker_item_get_label (self));
break;
+ case PROP_USE_MARKUP:
+ g_value_set_boolean (value, gtk_menu_tracker_item_get_use_markup (self));
+ break;
case PROP_ICON:
g_value_take_object (value, gtk_menu_tracker_item_get_icon (self));
break;
@@ -223,6 +227,8 @@ gtk_menu_tracker_item_class_init (GtkMenuTrackerItemClass *class)
g_param_spec_boolean ("is-separator", "", "", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
gtk_menu_tracker_item_pspecs[PROP_LABEL] =
g_param_spec_string ("label", "", "", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
+ gtk_menu_tracker_item_pspecs[PROP_USE_MARKUP] =
+ g_param_spec_boolean ("use-markup", "", "", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
gtk_menu_tracker_item_pspecs[PROP_ICON] =
g_param_spec_object ("icon", "", "", G_TYPE_ICON, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
gtk_menu_tracker_item_pspecs[PROP_VERB_ICON] =
@@ -628,6 +634,12 @@ gtk_menu_tracker_item_get_label (GtkMenuTrackerItem *self)
return label;
}
+gboolean
+gtk_menu_tracker_item_get_use_markup (GtkMenuTrackerItem *self)
+{
+ return g_menu_item_get_attribute (self->item, "use-markup", "&s", NULL);
+}
+
/*< private >
* gtk_menu_tracker_item_get_icon:
*
diff --git a/gtk/gtkmenutrackeritemprivate.h b/gtk/gtkmenutrackeritemprivate.h
index 6ebbc3764c..50343ba99e 100644
--- a/gtk/gtkmenutrackeritemprivate.h
+++ b/gtk/gtkmenutrackeritemprivate.h
@@ -66,6 +66,8 @@ gboolean gtk_menu_tracker_item_get_has_link (GtkMenu
const char * gtk_menu_tracker_item_get_label (GtkMenuTrackerItem *self);
+gboolean gtk_menu_tracker_item_get_use_markup (GtkMenuTrackerItem *self);
+
GIcon * gtk_menu_tracker_item_get_icon (GtkMenuTrackerItem *self);
GIcon * gtk_menu_tracker_item_get_verb_icon (GtkMenuTrackerItem *self);
diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c
index 9a3458584f..0c4f57ecf2 100644
--- a/gtk/gtkpopovermenu.c
+++ b/gtk/gtkpopovermenu.c
@@ -98,6 +98,7 @@
* The following attributes are used when constructing menu items:
*
* - "label": a user-visible string to display
+ * - "use-markup": whether the text in the menu item includes [Pango
markup](https://docs.gtk.org/Pango/pango_markup.html)
* - "action": the prefixed name of the action to trigger
* - "target": the parameter to use when activating the action
* - "icon" and "verb-icon": names of icons that may be displayed
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]