[gtk+] menubutton: dismiss menu/popover when toggling programmatically



commit d94379183a2fae089dcdffbead5744374edbacb1
Author: Paolo Borelli <pborelli gnome org>
Date:   Wed Aug 27 21:36:08 2014 +0200

    menubutton: dismiss menu/popover when toggling programmatically
    
    https://bugzilla.gnome.org/show_bug.cgi?id=735545

 gtk/gtkmenubutton.c |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkmenubutton.c b/gtk/gtkmenubutton.c
index 605937a..656392f 100644
--- a/gtk/gtkmenubutton.c
+++ b/gtk/gtkmenubutton.c
@@ -408,23 +408,28 @@ gtk_menu_button_toggled (GtkToggleButton *button)
 {
   GtkMenuButton *menu_button = GTK_MENU_BUTTON (button);
   GtkMenuButtonPrivate *priv = menu_button->priv;
+  gboolean active;
 
-  if (!gtk_toggle_button_get_active (button))
-    return;
+  active = gtk_toggle_button_get_active (button);
 
   if (priv->menu)
-    {  
-      if (!gtk_widget_get_visible (priv->menu))
+    {
+      if (active)
         {
-          /* we get here only when the menu is activated by a key
-           * press, so that we can select the first menu item
-           */
-          popup_menu (menu_button, NULL);
-          gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
+          if (!gtk_widget_get_visible (priv->menu))
+            {
+              /* we get here only when the menu is activated by a key
+               * press, so that we can select the first menu item
+               */
+              popup_menu (menu_button, NULL);
+              gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
+            }
         }
+      else
+        gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
     }
   else if (priv->popover)
-    gtk_widget_show (priv->popover); 
+    gtk_widget_set_visible (priv->popover, active);
 }
 
 static gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]