summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntónio Fernandes <antoniof@gnome.org>2020-12-20 22:26:44 +0000
committerAntónio Fernandes <antoniof@gnome.org>2020-12-20 23:27:58 +0000
commita736ae82a72fd6485cc685759015201d4c9e9caf (patch)
tree028eb483635eff9665c940dfb63a3c8d62803ad9
parenteec24a098226c752c6115335ff4b1dd7208b0ccb (diff)
downloadgtk+-wip/antoniof/popover_remove_submenus_recursively.tar.gz
menusectionbox: Remove submenus recursivelywip/antoniof/popover_remove_submenus_recursively
When a submenu link is removed in the menu model, the remove_func callback removes the submenu's page from the stack. But the submenu may contain links to other submenus. Let's remove them as well. Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/1705
-rw-r--r--gtk/gtkmenusectionbox.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/gtk/gtkmenusectionbox.c b/gtk/gtkmenusectionbox.c
index b790825a64..c9666dc531 100644
--- a/gtk/gtkmenusectionbox.c
+++ b/gtk/gtkmenusectionbox.c
@@ -191,6 +191,35 @@ gtk_popover_item_activate (GtkWidget *button,
}
static void
+remove_submenu_tree_from_stack (const char *submenu_name,
+ GtkStack *stack)
+{
+ GtkWidget *submenu;
+ GtkBox *item_box;
+ GList *children, *l;
+
+ submenu = gtk_stack_get_child_by_name (stack, submenu_name);
+ if (submenu == NULL)
+ return;
+
+ item_box = GTK_MENU_SECTION_BOX (submenu)->item_box;
+ children = gtk_container_get_children (GTK_CONTAINER (item_box));
+ for (l = children; l != NULL; l = l->next)
+ {
+ GtkMenuTrackerItem *item;
+
+ item = g_object_get_data (G_OBJECT (l->data), "GtkMenuTrackerItem");
+
+ if (gtk_menu_tracker_item_get_has_link (item, G_MENU_LINK_SUBMENU))
+ remove_submenu_tree_from_stack (gtk_menu_tracker_item_get_label (item),
+ stack);
+ }
+ g_list_free (children);
+
+ gtk_container_remove (GTK_CONTAINER (stack), submenu);
+}
+
+static void
gtk_menu_section_box_remove_func (gint position,
gpointer user_data)
{
@@ -206,12 +235,12 @@ gtk_menu_section_box_remove_func (gint position,
item = g_object_get_data (G_OBJECT (widget), "GtkMenuTrackerItem");
if (gtk_menu_tracker_item_get_has_link (item, G_MENU_LINK_SUBMENU))
{
- GtkWidget *stack, *subbox;
+ GtkWidget *stack;
stack = gtk_widget_get_ancestor (GTK_WIDGET (box->toplevel), GTK_TYPE_STACK);
- subbox = gtk_stack_get_child_by_name (GTK_STACK (stack), gtk_menu_tracker_item_get_label (item));
- if (subbox != NULL)
- gtk_container_remove (GTK_CONTAINER (stack), subbox);
+
+ remove_submenu_tree_from_stack (gtk_menu_tracker_item_get_label (item),
+ GTK_STACK (stack));
}
gtk_widget_destroy (g_list_nth_data (children, position));