mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-05 16:20:10 +00:00
GtkMenuTracker: don't specialise "submenu" link
We have some API in GtkMenuTracker and GtkMenuTrackerItem that is specifically designed to deal with submenus. Generalise these APIs to take a 'link_name' parameter that we always give as G_MENU_SUBMENU for now. In the future, this will allow creating trackers for other types of links, such as sections.
This commit is contained in:
parent
48db841822
commit
f6ee00769a
@ -2057,7 +2057,7 @@ gtk_menu_shell_tracker_insert_func (GtkMenuTrackerItem *item,
|
||||
|
||||
gtk_widget_show (widget);
|
||||
}
|
||||
else if (gtk_menu_tracker_item_get_has_submenu (item))
|
||||
else if (gtk_menu_tracker_item_get_has_link (item, G_MENU_LINK_SUBMENU))
|
||||
{
|
||||
GtkMenuShell *submenu;
|
||||
|
||||
@ -2070,10 +2070,11 @@ gtk_menu_shell_tracker_insert_func (GtkMenuTrackerItem *item,
|
||||
* prevent arbitrary recursion depth. We could also do it
|
||||
* lazy...
|
||||
*/
|
||||
submenu->priv->tracker = gtk_menu_tracker_new_for_item_submenu (item,
|
||||
gtk_menu_shell_tracker_insert_func,
|
||||
gtk_menu_shell_tracker_remove_func,
|
||||
submenu);
|
||||
submenu->priv->tracker = gtk_menu_tracker_new_for_item_link (item,
|
||||
G_MENU_LINK_SUBMENU,
|
||||
gtk_menu_shell_tracker_insert_func,
|
||||
gtk_menu_shell_tracker_remove_func,
|
||||
submenu);
|
||||
gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget), GTK_WIDGET (submenu));
|
||||
|
||||
if (gtk_menu_tracker_item_get_should_request_show (item))
|
||||
|
@ -560,17 +560,18 @@ gtk_menu_tracker_new (GtkActionObservable *observable,
|
||||
}
|
||||
|
||||
GtkMenuTracker *
|
||||
gtk_menu_tracker_new_for_item_submenu (GtkMenuTrackerItem *item,
|
||||
GtkMenuTrackerInsertFunc insert_func,
|
||||
GtkMenuTrackerRemoveFunc remove_func,
|
||||
gpointer user_data)
|
||||
gtk_menu_tracker_new_for_item_link (GtkMenuTrackerItem *item,
|
||||
const gchar *link_name,
|
||||
GtkMenuTrackerInsertFunc insert_func,
|
||||
GtkMenuTrackerRemoveFunc remove_func,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkMenuTracker *tracker;
|
||||
GMenuModel *submenu;
|
||||
gchar *namespace;
|
||||
|
||||
submenu = _gtk_menu_tracker_item_get_submenu (item);
|
||||
namespace = _gtk_menu_tracker_item_get_submenu_namespace (item);
|
||||
submenu = _gtk_menu_tracker_item_get_link (item, link_name);
|
||||
namespace = _gtk_menu_tracker_item_get_link_namespace (item);
|
||||
|
||||
tracker = gtk_menu_tracker_new (_gtk_menu_tracker_item_get_observable (item), submenu,
|
||||
TRUE, namespace, insert_func, remove_func, user_data);
|
||||
|
@ -40,7 +40,8 @@ GtkMenuTracker * gtk_menu_tracker_new (GtkActi
|
||||
GtkMenuTrackerRemoveFunc remove_func,
|
||||
gpointer user_data);
|
||||
|
||||
GtkMenuTracker * gtk_menu_tracker_new_for_item_submenu (GtkMenuTrackerItem *item,
|
||||
GtkMenuTracker * gtk_menu_tracker_new_for_item_link (GtkMenuTrackerItem *item,
|
||||
const gchar *link_name,
|
||||
GtkMenuTrackerInsertFunc insert_func,
|
||||
GtkMenuTrackerRemoveFunc remove_func,
|
||||
gpointer user_data);
|
||||
|
@ -106,7 +106,6 @@ struct _GtkMenuTrackerItem
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_IS_SEPARATOR,
|
||||
PROP_HAS_SUBMENU,
|
||||
PROP_LABEL,
|
||||
PROP_ICON,
|
||||
PROP_SENSITIVE,
|
||||
@ -160,9 +159,6 @@ gtk_menu_tracker_item_get_property (GObject *object,
|
||||
case PROP_IS_SEPARATOR:
|
||||
g_value_set_boolean (value, gtk_menu_tracker_item_get_is_separator (self));
|
||||
break;
|
||||
case PROP_HAS_SUBMENU:
|
||||
g_value_set_boolean (value, gtk_menu_tracker_item_get_has_submenu (self));
|
||||
break;
|
||||
case PROP_LABEL:
|
||||
g_value_set_string (value, gtk_menu_tracker_item_get_label (self));
|
||||
break;
|
||||
@ -221,8 +217,6 @@ gtk_menu_tracker_item_class_init (GtkMenuTrackerItemClass *class)
|
||||
|
||||
gtk_menu_tracker_item_pspecs[PROP_IS_SEPARATOR] =
|
||||
g_param_spec_boolean ("is-separator", "", "", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
|
||||
gtk_menu_tracker_item_pspecs[PROP_HAS_SUBMENU] =
|
||||
g_param_spec_boolean ("has-submenu", "", "", 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_ICON] =
|
||||
@ -559,11 +553,12 @@ gtk_menu_tracker_item_get_is_separator (GtkMenuTrackerItem *self)
|
||||
* for #GtkMenuTrackerItem.
|
||||
*/
|
||||
gboolean
|
||||
gtk_menu_tracker_item_get_has_submenu (GtkMenuTrackerItem *self)
|
||||
gtk_menu_tracker_item_get_has_link (GtkMenuTrackerItem *self,
|
||||
const gchar *link_name)
|
||||
{
|
||||
GMenuModel *link;
|
||||
|
||||
link = g_menu_item_get_link (self->item, G_MENU_LINK_SUBMENU);
|
||||
link = g_menu_item_get_link (self->item, link_name);
|
||||
|
||||
if (link)
|
||||
{
|
||||
@ -652,13 +647,14 @@ gtk_menu_tracker_item_get_special (GtkMenuTrackerItem *self)
|
||||
}
|
||||
|
||||
GMenuModel *
|
||||
_gtk_menu_tracker_item_get_submenu (GtkMenuTrackerItem *self)
|
||||
_gtk_menu_tracker_item_get_link (GtkMenuTrackerItem *self,
|
||||
const gchar *link_name)
|
||||
{
|
||||
return g_menu_item_get_link (self->item, "submenu");
|
||||
return g_menu_item_get_link (self->item, link_name);
|
||||
}
|
||||
|
||||
gchar *
|
||||
_gtk_menu_tracker_item_get_submenu_namespace (GtkMenuTrackerItem *self)
|
||||
_gtk_menu_tracker_item_get_link_namespace (GtkMenuTrackerItem *self)
|
||||
{
|
||||
const gchar *namespace;
|
||||
|
||||
|
@ -54,7 +54,8 @@ GtkActionObservable * _gtk_menu_tracker_item_get_observable (GtkMenu
|
||||
|
||||
gboolean gtk_menu_tracker_item_get_is_separator (GtkMenuTrackerItem *self);
|
||||
|
||||
gboolean gtk_menu_tracker_item_get_has_submenu (GtkMenuTrackerItem *self);
|
||||
gboolean gtk_menu_tracker_item_get_has_link (GtkMenuTrackerItem *self,
|
||||
const gchar *link_name);
|
||||
|
||||
const gchar * gtk_menu_tracker_item_get_label (GtkMenuTrackerItem *self);
|
||||
|
||||
@ -68,9 +69,10 @@ gboolean gtk_menu_tracker_item_get_toggled (GtkMenu
|
||||
|
||||
const gchar * gtk_menu_tracker_item_get_accel (GtkMenuTrackerItem *self);
|
||||
|
||||
GMenuModel * _gtk_menu_tracker_item_get_submenu (GtkMenuTrackerItem *self);
|
||||
GMenuModel * _gtk_menu_tracker_item_get_link (GtkMenuTrackerItem *self,
|
||||
const gchar *link_name);
|
||||
|
||||
gchar * _gtk_menu_tracker_item_get_submenu_namespace (GtkMenuTrackerItem *self);
|
||||
gchar * _gtk_menu_tracker_item_get_link_namespace (GtkMenuTrackerItem *self);
|
||||
|
||||
gboolean gtk_menu_tracker_item_may_disappear (GtkMenuTrackerItem *self);
|
||||
|
||||
|
@ -2039,7 +2039,7 @@ gtk_popover_tracker_insert_func (GtkMenuTrackerItem *item,
|
||||
gtk_widget_show (widget);
|
||||
}
|
||||
}
|
||||
else if (gtk_menu_tracker_item_get_has_submenu (item))
|
||||
else if (gtk_menu_tracker_item_get_has_link (item, G_MENU_LINK_SUBMENU))
|
||||
{
|
||||
GtkMenuTracker *tracker;
|
||||
GtkWidget *child;
|
||||
@ -2084,7 +2084,9 @@ gtk_popover_tracker_insert_func (GtkMenuTrackerItem *item,
|
||||
gtk_widget_set_halign (content, GTK_ALIGN_FILL);
|
||||
gtk_widget_show (content);
|
||||
gtk_container_add (GTK_CONTAINER (child), content);
|
||||
tracker = gtk_menu_tracker_new_for_item_submenu (item, gtk_popover_tracker_insert_func, gtk_popover_tracker_remove_func, content);
|
||||
tracker = gtk_menu_tracker_new_for_item_link (item, G_MENU_LINK_SUBMENU,
|
||||
gtk_popover_tracker_insert_func,
|
||||
gtk_popover_tracker_remove_func, content);
|
||||
|
||||
g_object_set_data_full (G_OBJECT (widget), "submenutracker", tracker, (GDestroyNotify)gtk_menu_tracker_free);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user