[glade] Handle submenu changes better



commit 99eb7211ec40b7f449389ecf861c35d77cdb8716
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Nov 19 12:13:29 2014 +0100

    Handle submenu changes better
    
    Deal with 'spontaneous' changes of the visible submenu. This will
    happen once we add model buttons.

 plugins/gtk+/glade-gtk-popover-menu.c |   91 +++++++++++++++++++++------------
 1 files changed, 59 insertions(+), 32 deletions(-)
---
diff --git a/plugins/gtk+/glade-gtk-popover-menu.c b/plugins/gtk+/glade-gtk-popover-menu.c
index d044b9a..465837a 100644
--- a/plugins/gtk+/glade-gtk-popover-menu.c
+++ b/plugins/gtk+/glade-gtk-popover-menu.c
@@ -115,6 +115,62 @@ glade_gtk_popover_menu_project_changed (GladeWidget * gwidget,
   g_object_set_data (G_OBJECT (gwidget), "popover-menu-project-ptr", project);
 }
 
+static gint
+get_visible_child (GtkPopoverMenu *popover)
+{
+  gchar *visible;
+  GList *children, *l;
+  gint ret, i;
+
+  ret = -1;
+
+  g_object_get (G_OBJECT (popover), "visible-submenu", &visible, NULL);
+  children = gtk_container_get_children (GTK_CONTAINER (popover));
+  for (l = children, i = 0; l; l = l->next, i++)
+    {
+      GtkWidget *child = l->data;
+      gchar *name;
+      gboolean found;
+
+      gtk_container_child_get (GTK_CONTAINER (popover), child, "submenu", &name, NULL);
+      found = !strcmp (visible, name);
+      g_free (name);
+      if (found)
+        {
+          ret = i;
+          break;
+        }
+    }
+  g_list_free (children);
+  g_free (visible);
+
+  return ret;
+}
+
+static void
+glade_gtk_popover_menu_visible_submenu_changed (GObject *popover,
+                                                GParamSpec *pspec,
+                                                gpointer data)
+{
+  GladeWidget *gwidget = glade_widget_get_from_gobject (popover);
+  GladeProject *project = glade_widget_get_project (gwidget);
+  gint current;
+  GList *list;
+
+  current = get_visible_child (GTK_POPOVER_MENU (popover));
+  glade_widget_property_set (gwidget, "current", current);
+
+  if ((list = glade_project_selection_get (project)) != NULL &&
+      g_list_length (list) == 1)
+    {
+      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);
+    }
+}
+
 void
 glade_gtk_popover_menu_post_create (GladeWidgetAdaptor *adaptor,
                                     GObject *container,
@@ -134,6 +190,9 @@ glade_gtk_popover_menu_post_create (GladeWidgetAdaptor *adaptor,
                     G_CALLBACK (glade_gtk_popover_menu_project_changed), NULL);
 
   glade_gtk_popover_menu_project_changed (parent, NULL, NULL);
+
+  g_signal_connect (container, "notify::visible-submenu",
+                    G_CALLBACK (glade_gtk_popover_menu_visible_submenu_changed), NULL);
 }
 
 void
@@ -366,38 +425,6 @@ glade_gtk_popover_menu_set_property (GladeWidgetAdaptor * adaptor,
     GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, id, value);
 }
 
-static gint
-get_visible_child (GtkPopoverMenu *popover)
-{
-  gchar *visible;
-  GList *children, *l;
-  gint ret, i;
-
-  ret = -1;
-
-  g_object_get (G_OBJECT (popover), "visible-submenu", &visible, NULL);
-  children = gtk_container_get_children (GTK_CONTAINER (popover));
-  for (l = children, i = 0; l; l = l->next, i++)
-    {
-      GtkWidget *child = l->data;
-      gchar *name;
-      gboolean found;
-
-      gtk_container_child_get (GTK_CONTAINER (popover), child, "submenu", &name, NULL);
-      found = !strcmp (visible, name);
-      g_free (name);
-      if (found)
-        {
-          ret = i;
-          break;
-        }
-    }
-  g_list_free (children);
-  g_free (visible);
-
-  return ret;
-}
-
 void
 glade_gtk_popover_menu_get_property (GladeWidgetAdaptor * adaptor,
                                      GObject * object,


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