[glade] Don't clear selection too eagerly



commit f29a6871927425b927840802360ad073cc1a1a31
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Nov 17 23:49:46 2015 -0500

    Don't clear selection too eagerly
    
    When the current submenu in a GtkPopoverMenu is selected, and we
    are editing its submenu child property, we get change notification
    for the popovers visible-submenu property. Don't clear the selection
    in this case because the visible submenu did not actually change
    to a different widget, it just changed its name.

 plugins/gtk+/glade-gtk-popover-menu.c |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/plugins/gtk+/glade-gtk-popover-menu.c b/plugins/gtk+/glade-gtk-popover-menu.c
index 465837a..d74d25c 100644
--- a/plugins/gtk+/glade-gtk-popover-menu.c
+++ b/plugins/gtk+/glade-gtk-popover-menu.c
@@ -116,7 +116,7 @@ glade_gtk_popover_menu_project_changed (GladeWidget * gwidget,
 }
 
 static gint
-get_visible_child (GtkPopoverMenu *popover)
+get_visible_child (GtkPopoverMenu *popover, GtkWidget **visible_child)
 {
   gchar *visible;
   GList *children, *l;
@@ -137,6 +137,8 @@ get_visible_child (GtkPopoverMenu *popover)
       g_free (name);
       if (found)
         {
+          if (visible_child)
+            *visible_child = child;
           ret = i;
           break;
         }
@@ -156,18 +158,23 @@ glade_gtk_popover_menu_visible_submenu_changed (GObject *popover,
   GladeProject *project = glade_widget_get_project (gwidget);
   gint current;
   GList *list;
+  GtkWidget *visible_child;
 
-  current = get_visible_child (GTK_POPOVER_MENU (popover));
+  current = get_visible_child (GTK_POPOVER_MENU (popover), &visible_child);
   glade_widget_property_set (gwidget, "current", current);
 
   if ((list = glade_project_selection_get (project)) != NULL &&
-      g_list_length (list) == 1)
+      list->next == NULL)
     {
       GObject *selected = list->data;
 
       if (GTK_IS_WIDGET (selected) &&
-          gtk_widget_is_ancestor (GTK_WIDGET (selected), GTK_WIDGET (popover)))
-        glade_project_selection_clear (project, TRUE);
+          gtk_widget_is_ancestor (GTK_WIDGET (selected), GTK_WIDGET (popover)) &&
+          (GtkWidget*)selected != visible_child &&
+          !gtk_widget_is_ancestor (GTK_WIDGET (selected), GTK_WIDGET (visible_child)))
+        {
+          glade_project_selection_clear (project, TRUE);
+        }
     }
 }
 
@@ -439,7 +446,7 @@ glade_gtk_popover_menu_get_property (GladeWidgetAdaptor * adaptor,
   else if (!strcmp (id, "current"))
     {
       g_value_reset (value);
-      g_value_set_int (value, get_visible_child (GTK_POPOVER_MENU (object)));
+      g_value_set_int (value, get_visible_child (GTK_POPOVER_MENU (object), NULL));
     }
   else
     GWA_GET_CLASS (GTK_TYPE_CONTAINER)->get_property (adaptor, object, id, value);
@@ -533,7 +540,7 @@ glade_gtk_popover_menu_set_child_position (GObject * container,
   g_free (visible_child); 
 
   gbox = glade_widget_get_from_gobject (container);
-  glade_widget_pack_property_set (gbox, "visible-submenu", get_visible_child (GTK_POPOVER_MENU (container)));
+  glade_widget_pack_property_set (gbox, "visible-submenu", get_visible_child (GTK_POPOVER_MENU (container), 
NULL));
 }
 
 void


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