Commit f6ee0076 authored by Allison Karlitskaya's avatar Allison Karlitskaya Committed by Matthias Clasen

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.
parent 48db8418
......@@ -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,7 +2070,8 @@ 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,
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);
......
......@@ -560,7 +560,8 @@ gtk_menu_tracker_new (GtkActionObservable *observable,
}
GtkMenuTracker *
gtk_menu_tracker_new_for_item_submenu (GtkMenuTrackerItem *item,
gtk_menu_tracker_new_for_item_link (GtkMenuTrackerItem *item,
const gchar *link_name,
GtkMenuTrackerInsertFunc insert_func,
GtkMenuTrackerRemoveFunc remove_func,
gpointer user_data)
......@@ -569,8 +570,8 @@ gtk_menu_tracker_new_for_item_submenu (GtkMenuTrackerItem *item,
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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment