GtkMenuButton: use :toggled instead of :clicked

:toggled is triggered on :clicked, so using :toggled lead to the menu
to be popped up at the same time, while allowing to use the toggle state
and avoiding any need to a hack to prevent recursion, which somehow
wasn't enough for double emission of GtkMenuToolButton:show-popup.

https://bugzilla.gnome.org/show_bug.cgi?id=769287
This commit is contained in:
Colomban Wendling 2016-07-29 00:39:30 +02:00 committed by Carlos Garnacho
parent 41be1e7e1f
commit 64521345b9

View File

@ -137,7 +137,6 @@ struct _GtkMenuButtonPrivate
GtkArrowType arrow_type;
gboolean use_popover;
guint press_handled : 1;
guint in_click : 1;
};
enum
@ -395,21 +394,15 @@ popup_menu (GtkMenuButton *menu_button,
}
static void
gtk_menu_button_clicked (GtkButton *button)
gtk_menu_button_toggled (GtkToggleButton *button)
{
GtkMenuButton *menu_button = GTK_MENU_BUTTON (button);
GtkMenuButtonPrivate *priv = menu_button->priv;
gboolean active;
if (priv->in_click)
return;
priv->in_click = TRUE;
gboolean active = gtk_toggle_button_get_active (button);
if (priv->menu)
{
active = !gtk_widget_get_visible (priv->menu);
if (active)
if (active && !gtk_widget_get_visible (priv->menu))
{
GdkEvent *event;
@ -428,20 +421,14 @@ gtk_menu_button_clicked (GtkButton *button)
}
else if (priv->popover)
{
active = !gtk_widget_get_visible (priv->popover);
if (active)
gtk_widget_show (priv->popover);
else
gtk_widget_hide (priv->popover);
}
else
active = FALSE;
GTK_BUTTON_CLASS (gtk_menu_button_parent_class)->clicked (button);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), active);
gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (button));
priv->in_click = FALSE;
if (GTK_TOGGLE_BUTTON_CLASS (gtk_menu_button_parent_class)->toggled)
GTK_TOGGLE_BUTTON_CLASS (gtk_menu_button_parent_class)->toggled (button);
}
static void
@ -474,7 +461,7 @@ gtk_menu_button_class_init (GtkMenuButtonClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
GtkToggleButtonClass *toggle_button_class = GTK_TOGGLE_BUTTON_CLASS (klass);
gobject_class->set_property = gtk_menu_button_set_property;
gobject_class->get_property = gtk_menu_button_get_property;
@ -485,7 +472,7 @@ gtk_menu_button_class_init (GtkMenuButtonClass *klass)
container_class->add = gtk_menu_button_add;
container_class->remove = gtk_menu_button_remove;
button_class->clicked = gtk_menu_button_clicked;
toggle_button_class->toggled = gtk_menu_button_toggled;
/**
* GtkMenuButton:popup: