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, ...@@ -2057,7 +2057,7 @@ gtk_menu_shell_tracker_insert_func (GtkMenuTrackerItem *item,
gtk_widget_show (widget); 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; GtkMenuShell *submenu;
...@@ -2070,10 +2070,11 @@ gtk_menu_shell_tracker_insert_func (GtkMenuTrackerItem *item, ...@@ -2070,10 +2070,11 @@ gtk_menu_shell_tracker_insert_func (GtkMenuTrackerItem *item,
* prevent arbitrary recursion depth. We could also do it * prevent arbitrary recursion depth. We could also do it
* lazy... * lazy...
*/ */
submenu->priv->tracker = gtk_menu_tracker_new_for_item_submenu (item, submenu->priv->tracker = gtk_menu_tracker_new_for_item_link (item,
gtk_menu_shell_tracker_insert_func, G_MENU_LINK_SUBMENU,
gtk_menu_shell_tracker_remove_func, gtk_menu_shell_tracker_insert_func,
submenu); gtk_menu_shell_tracker_remove_func,
submenu);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget), GTK_WIDGET (submenu)); gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget), GTK_WIDGET (submenu));
if (gtk_menu_tracker_item_get_should_request_show (item)) if (gtk_menu_tracker_item_get_should_request_show (item))
......
...@@ -560,17 +560,18 @@ gtk_menu_tracker_new (GtkActionObservable *observable, ...@@ -560,17 +560,18 @@ gtk_menu_tracker_new (GtkActionObservable *observable,
} }
GtkMenuTracker * GtkMenuTracker *
gtk_menu_tracker_new_for_item_submenu (GtkMenuTrackerItem *item, gtk_menu_tracker_new_for_item_link (GtkMenuTrackerItem *item,
GtkMenuTrackerInsertFunc insert_func, const gchar *link_name,
GtkMenuTrackerRemoveFunc remove_func, GtkMenuTrackerInsertFunc insert_func,
gpointer user_data) GtkMenuTrackerRemoveFunc remove_func,
gpointer user_data)
{ {
GtkMenuTracker *tracker; GtkMenuTracker *tracker;
GMenuModel *submenu; GMenuModel *submenu;
gchar *namespace; gchar *namespace;
submenu = _gtk_menu_tracker_item_get_submenu (item); submenu = _gtk_menu_tracker_item_get_link (item, link_name);
namespace = _gtk_menu_tracker_item_get_submenu_namespace (item); namespace = _gtk_menu_tracker_item_get_link_namespace (item);
tracker = gtk_menu_tracker_new (_gtk_menu_tracker_item_get_observable (item), submenu, tracker = gtk_menu_tracker_new (_gtk_menu_tracker_item_get_observable (item), submenu,
TRUE, namespace, insert_func, remove_func, user_data); TRUE, namespace, insert_func, remove_func, user_data);
......
...@@ -40,7 +40,8 @@ GtkMenuTracker * gtk_menu_tracker_new (GtkActi ...@@ -40,7 +40,8 @@ GtkMenuTracker * gtk_menu_tracker_new (GtkActi
GtkMenuTrackerRemoveFunc remove_func, GtkMenuTrackerRemoveFunc remove_func,
gpointer user_data); 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, GtkMenuTrackerInsertFunc insert_func,
GtkMenuTrackerRemoveFunc remove_func, GtkMenuTrackerRemoveFunc remove_func,
gpointer user_data); gpointer user_data);
......
...@@ -106,7 +106,6 @@ struct _GtkMenuTrackerItem ...@@ -106,7 +106,6 @@ struct _GtkMenuTrackerItem
enum { enum {
PROP_0, PROP_0,
PROP_IS_SEPARATOR, PROP_IS_SEPARATOR,
PROP_HAS_SUBMENU,
PROP_LABEL, PROP_LABEL,
PROP_ICON, PROP_ICON,
PROP_SENSITIVE, PROP_SENSITIVE,
...@@ -160,9 +159,6 @@ gtk_menu_tracker_item_get_property (GObject *object, ...@@ -160,9 +159,6 @@ gtk_menu_tracker_item_get_property (GObject *object,
case PROP_IS_SEPARATOR: case PROP_IS_SEPARATOR:
g_value_set_boolean (value, gtk_menu_tracker_item_get_is_separator (self)); g_value_set_boolean (value, gtk_menu_tracker_item_get_is_separator (self));
break; break;
case PROP_HAS_SUBMENU:
g_value_set_boolean (value, gtk_menu_tracker_item_get_has_submenu (self));
break;
case PROP_LABEL: case PROP_LABEL:
g_value_set_string (value, gtk_menu_tracker_item_get_label (self)); g_value_set_string (value, gtk_menu_tracker_item_get_label (self));
break; break;
...@@ -221,8 +217,6 @@ gtk_menu_tracker_item_class_init (GtkMenuTrackerItemClass *class) ...@@ -221,8 +217,6 @@ gtk_menu_tracker_item_class_init (GtkMenuTrackerItemClass *class)
gtk_menu_tracker_item_pspecs[PROP_IS_SEPARATOR] = gtk_menu_tracker_item_pspecs[PROP_IS_SEPARATOR] =
g_param_spec_boolean ("is-separator", "", "", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE); 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] = gtk_menu_tracker_item_pspecs[PROP_LABEL] =
g_param_spec_string ("label", "", "", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE); g_param_spec_string ("label", "", "", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
gtk_menu_tracker_item_pspecs[PROP_ICON] = gtk_menu_tracker_item_pspecs[PROP_ICON] =
...@@ -559,11 +553,12 @@ gtk_menu_tracker_item_get_is_separator (GtkMenuTrackerItem *self) ...@@ -559,11 +553,12 @@ gtk_menu_tracker_item_get_is_separator (GtkMenuTrackerItem *self)
* for #GtkMenuTrackerItem. * for #GtkMenuTrackerItem.
*/ */
gboolean 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; 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) if (link)
{ {
...@@ -652,13 +647,14 @@ gtk_menu_tracker_item_get_special (GtkMenuTrackerItem *self) ...@@ -652,13 +647,14 @@ gtk_menu_tracker_item_get_special (GtkMenuTrackerItem *self)
} }
GMenuModel * 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 * gchar *
_gtk_menu_tracker_item_get_submenu_namespace (GtkMenuTrackerItem *self) _gtk_menu_tracker_item_get_link_namespace (GtkMenuTrackerItem *self)
{ {
const gchar *namespace; const gchar *namespace;
......
...@@ -54,7 +54,8 @@ GtkActionObservable * _gtk_menu_tracker_item_get_observable (GtkMenu ...@@ -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_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); const gchar * gtk_menu_tracker_item_get_label (GtkMenuTrackerItem *self);
...@@ -68,9 +69,10 @@ gboolean gtk_menu_tracker_item_get_toggled (GtkMenu ...@@ -68,9 +69,10 @@ gboolean gtk_menu_tracker_item_get_toggled (GtkMenu
const gchar * gtk_menu_tracker_item_get_accel (GtkMenuTrackerItem *self); 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); gboolean gtk_menu_tracker_item_may_disappear (GtkMenuTrackerItem *self);
......
...@@ -2039,7 +2039,7 @@ gtk_popover_tracker_insert_func (GtkMenuTrackerItem *item, ...@@ -2039,7 +2039,7 @@ gtk_popover_tracker_insert_func (GtkMenuTrackerItem *item,
gtk_widget_show (widget); 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; GtkMenuTracker *tracker;
GtkWidget *child; GtkWidget *child;
...@@ -2084,7 +2084,9 @@ gtk_popover_tracker_insert_func (GtkMenuTrackerItem *item, ...@@ -2084,7 +2084,9 @@ gtk_popover_tracker_insert_func (GtkMenuTrackerItem *item,
gtk_widget_set_halign (content, GTK_ALIGN_FILL); gtk_widget_set_halign (content, GTK_ALIGN_FILL);
gtk_widget_show (content); gtk_widget_show (content);
gtk_container_add (GTK_CONTAINER (child), 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); 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