[gtk+] GtkApplication: Initial attempt at section headings



commit 5aee67793fdd172fb4e9bdfa2871d1d0ffa6720c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Nov 26 13:32:48 2011 -0500

    GtkApplication: Initial attempt at section headings
    
    This should be redone to show the label together with the
    separator line, somehow. For now, just put the label below
    the separator, as a separate item.

 gtk/gtkapplication.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index 9bbc4c2..ed95977 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -450,6 +450,7 @@ create_menuitem_from_model (GMenuModel   *model,
   const GVariantType *type;
   GVariant *v;
 
+  label = NULL;
   g_menu_model_get_item_attribute (model, item, G_MENU_ATTRIBUTE_LABEL, "s", &label);
 
   action = NULL;
@@ -536,7 +537,8 @@ static void
 append_items_from_model (GtkMenuShell *menu,
                          GMenuModel   *model,
                          GActionGroup *group,
-                         gboolean     *need_separator)
+                         gboolean     *need_separator,
+                         const gchar  *heading)
 {
   gint n;
   gint i;
@@ -544,6 +546,7 @@ append_items_from_model (GtkMenuShell *menu,
   GtkWidget *menuitem;
   GtkWidget *submenu;
   GMenuModel *m;
+  gchar *label;
 
   n = g_menu_model_get_n_items (model);
 
@@ -556,12 +559,23 @@ append_items_from_model (GtkMenuShell *menu,
       *need_separator = FALSE;
     }
 
+  if (heading != NULL)
+    {
+      w = gtk_menu_item_new_with_label (heading);
+      gtk_widget_show (w);
+      gtk_widget_set_sensitive (w, FALSE);
+      gtk_menu_shell_append (GTK_MENU_SHELL (menu), w);
+    }
+
   for (i = 0; i < n; i++)
     {
       if ((m = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION)))
         {
-          append_items_from_model (menu, m, group, need_separator);
+          label = NULL;
+          g_menu_model_get_item_attribute (model, i, G_MENU_ATTRIBUTE_LABEL, "s", &label);
+          append_items_from_model (menu, m, group, need_separator, label);
           g_object_unref (m);
+          g_free (label);
           continue;
         }
 
@@ -590,7 +604,7 @@ populate_menu_from_model (GtkMenuShell *menu,
   gboolean need_separator;
 
   need_separator = FALSE;
-  append_items_from_model (menu, model, group, &need_separator);
+  append_items_from_model (menu, model, group, &need_separator, NULL);
 }
 
 typedef struct {



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