popover: Fix submenu navigation

In commit 024d832d94, we introduced a
cascade-popdown property that makes closing a submenu
propagate up and close its parent menus. This is the
behavior we want when a menuitem in the submen is
activated.

What we overlooked is that we still need to be able to
close a submenu during navigation, before opening another
one. And in this case, propagating the closing is breaking
things. Fix this by adding a private close_submenu api
to GtkPopoverMenu that avoids the propagation.

Fixes: #3301
This commit is contained in:
Matthias Clasen 2020-11-16 21:27:15 -05:00
parent 2c9bf55eea
commit c2ae73f247
3 changed files with 17 additions and 21 deletions

View File

@ -1326,26 +1326,6 @@ gtk_model_button_class_init (GtkModelButtonClass *class)
g_object_unref (action);
}
static void
close_submenus (GtkPopover *popover)
{
GtkPopoverMenu *menu;
if (GTK_IS_POPOVER_MENU (popover))
{
GtkWidget *submenu;
menu = GTK_POPOVER_MENU (popover);
submenu = gtk_popover_menu_get_open_submenu (menu);
if (submenu)
{
close_submenus (GTK_POPOVER (submenu));
gtk_popover_popdown (GTK_POPOVER (submenu));
gtk_popover_menu_set_open_submenu (menu, NULL);
}
}
}
static gboolean
open_submenu (gpointer data)
{
@ -1363,7 +1343,7 @@ open_submenu (gpointer data)
GtkWidget *submenu = button->popover;
if (gtk_popover_menu_get_open_submenu (GTK_POPOVER_MENU (popover)) != submenu)
close_submenus (popover);
gtk_popover_menu_close_submenus (GTK_POPOVER_MENU (popover));
gtk_popover_popup (GTK_POPOVER (submenu));
gtk_popover_menu_set_open_submenu (GTK_POPOVER_MENU (popover), submenu);

View File

@ -189,6 +189,20 @@ gtk_popover_menu_set_open_submenu (GtkPopoverMenu *menu,
menu->open_submenu = submenu;
}
void
gtk_popover_menu_close_submenus (GtkPopoverMenu *menu)
{
GtkWidget *submenu;
submenu = menu->open_submenu;
if (submenu)
{
gtk_popover_menu_close_submenus (GTK_POPOVER_MENU (submenu));
gtk_widget_hide (submenu);
gtk_popover_menu_set_open_submenu (menu, NULL);
}
}
GtkWidget *
gtk_popover_menu_get_active_item (GtkPopoverMenu *menu)
{

View File

@ -28,6 +28,8 @@ void gtk_popover_menu_set_active_item (GtkPopoverMenu *menu,
GtkWidget *gtk_popover_menu_get_open_submenu (GtkPopoverMenu *menu);
void gtk_popover_menu_set_open_submenu (GtkPopoverMenu *menu,
GtkWidget *submenu);
void gtk_popover_menu_close_submenus (GtkPopoverMenu *menu);
GtkWidget *gtk_popover_menu_get_parent_menu (GtkPopoverMenu *menu);
void gtk_popover_menu_set_parent_menu (GtkPopoverMenu *menu,
GtkWidget *parent);