Commit a991bb99 authored by Matthias Clasen's avatar Matthias Clasen Committed by Allison Karlitskaya

GtkBuilder: pick up named submenus

When parsing GMenu xml, use the facility for pick up named submenus.
Note that <section id='foo'>...</section> is _not_ a named submenu.
It is a named item with an unnamed submenu :-(
parent c1f9ccce
......@@ -427,6 +427,14 @@ free_object_info (ObjectInfo *info)
g_slice_free (ObjectInfo, info);
}
static void
free_menu_info (MenuInfo *info)
{
g_free (info->id);
g_hash_table_unref (info->objects);
g_slice_free (MenuInfo, info);
}
static void
parse_child (ParserData *data,
const gchar *element_name,
......@@ -834,20 +842,20 @@ parse_menu (GMarkupParseContext *context,
{
gchar *id;
ParserData *data = user_data;
ObjectInfo *object_info;
MenuInfo *menu_info;
if (!g_markup_collect_attributes (element_name, names, values, error,
G_MARKUP_COLLECT_STRING, "id", &id,
G_MARKUP_COLLECT_INVALID))
return FALSE;
object_info = g_slice_new0 (ObjectInfo);
object_info->class_name = g_strdup ("GMenu");
object_info->id = g_strdup (id);
object_info->tag.name = element_name;
state_push (data, object_info);
menu_info = g_slice_new0 (MenuInfo);
menu_info->tag.name = element_name;
menu_info->id = g_strdup (id);
menu_info->objects = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
state_push (data, menu_info);
g_menu_markup_parser_start_menu (context, data->domain, NULL);
g_menu_markup_parser_start_menu (context, data->domain, menu_info->objects);
return TRUE;
}
......@@ -987,15 +995,23 @@ end_element (GMarkupParseContext *context,
}
else if (strcmp (element_name, "menu") == 0)
{
ObjectInfo *object_info;
MenuInfo *menu_info;
GObject *menu;
GHashTableIter iter;
const gchar *id;
object_info = state_pop_info (data, ObjectInfo);
menu_info = state_pop_info (data, MenuInfo);
menu = (GObject*)g_menu_markup_parser_end_menu (context);
_gtk_builder_add_object (data->builder, object_info->id, menu);
_gtk_builder_add_object (data->builder, menu_info->id, menu);
g_object_unref (menu);
free_object_info (object_info);
g_hash_table_iter_init (&iter, menu_info->objects);
while (g_hash_table_iter_next (&iter, (gpointer*)&id, (gpointer*)&menu))
{
_gtk_builder_add_object (data->builder, id, menu);
}
free_menu_info (menu_info);
}
else if (data->requested_objects && !data->inside_requested_object)
{
......@@ -1142,7 +1158,7 @@ free_info (CommonInfo *info)
else if (strcmp (info->tag.name, "requires") == 0)
_free_requires_info ((RequiresInfo *)info, NULL);
else if (strcmp (info->tag.name, "menu") == 0)
free_object_info ((ObjectInfo *)info);
free_menu_info ((MenuInfo *)info);
else
g_assert_not_reached ();
}
......
......@@ -2592,14 +2592,14 @@ test_gmenu (void)
" <item label='Copy' action='copy'/>"
" <item label='Paste' action='paste'/>"
" </section>"
" <section>"
" <item><link name='section' id='blargh'>"
" <item label='Bold' action='bold'/>"
" <submenu label='Language'>"
" <item label='Latin' action='lang' target='latin'/>"
" <item label='Greek' action='lang' target='greek'/>"
" <item label='Urdu' action='lang' target='urdu'/>"
" </submenu>"
" </section>"
" </link></item>"
" </menu>"
"</interface>";
......@@ -2608,6 +2608,8 @@ test_gmenu (void)
g_assert (GTK_IS_WINDOW (obj));
obj1 = gtk_builder_get_object (builder, "edit-menu");
g_assert (G_IS_MENU_MODEL (obj1));
obj1 = gtk_builder_get_object (builder, "blargh");
g_assert (G_IS_MENU_MODEL (obj1));
g_object_unref (builder);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment