}
}
+static gboolean
+find_id_attribute (const gchar **names,
+ const gchar **values,
+ const gchar **id)
+{
+ gint i;
+
+ for (i = 0; names[i]; i++)
+ {
+ if (strcmp (names[i], "id") == 0)
+ {
+ *id = values[i];
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
static void
g_menu_markup_start_element (GMarkupParseContext *context,
const gchar *element_name,
attribute_names, attribute_values, error, \
first, __VA_ARGS__, G_MARKUP_COLLECT_INVALID)
#define OPTIONAL G_MARKUP_COLLECT_OPTIONAL
-#define STRDUP G_MARKUP_COLLECT_STRDUP
#define BOOLEAN G_MARKUP_COLLECT_BOOLEAN
#define STRING G_MARKUP_COLLECT_STRING
-#define NO_ATTRS() COLLECT (G_MARKUP_COLLECT_INVALID, NULL)
if (!(state->frame.menu || state->frame.item || state->string))
{
{
GMenuItem *item;
GMenu *menu;
+ gchar *id;
menu = g_menu_new ();
item = g_menu_item_new_submenu (NULL, G_MENU_MODEL (menu));
add_string_attributes (item, attribute_names, attribute_values);
g_menu_markup_push_frame (state, menu, item);
+
+ if (find_id_attribute (attribute_names, attribute_values, &id))
+ {
+ if (state->objects)
+ g_hash_table_insert (state->objects, g_strdup (id), g_object_ref (menu));
+ }
+
return;
}
{
GMenuItem *item;
GMenu *menu;
+ gchar *id;
menu = g_menu_new ();
item = g_menu_item_new_section (NULL, G_MENU_MODEL (menu));
add_string_attributes (item, attribute_names, attribute_values);
g_menu_markup_push_frame (state, menu, item);
+
+ if (find_id_attribute (attribute_names, attribute_values, &id))
+ {
+ if (state->objects)
+ g_hash_table_insert (state->objects, g_strdup (id), g_object_ref (menu));
+ }
+
return;
}
}
*
* If @objects is specified then it must be a #GHashTable that was
* created using g_hash_table_new_full() with g_str_hash(),
- * g_str_equal(), g_free() and g_object_unref(). Any named menus (ie:
- * those with an id='' attribute) that are encountered while parsing
- * will be added to this table. Each toplevel menu must be named.
+ * g_str_equal(), g_free() and g_object_unref().
+ * Any named menus (ie: <tag class="starttag">menu</tag>,
+ * <tag class="starttag">submenu</tag>,
+ * <tag class="starttag">section</tag> or <tag class="starttag">link</tag>
+ * elements with an id='' attribute) that are encountered while parsing
+ * will be added to this table. Each toplevel menu must be named.
*
* If @objects is %NULL then an empty hash table will be created.
*
*
* If @objects is specified then it must be a #GHashTable that was
* created using g_hash_table_new_full() with g_str_hash(),
- * g_str_equal(), g_free() and g_object_unref(). Any named menus (ie:
- * those with an * id='' attribute) that are encountered while parsing
+ * g_str_equal(), g_free() and g_object_unref().
+ * Any named menus (ie: <tag class="starttag">submenu</tag>,
+ * <tag class="starttag">section</tag> or <tag class="starttag">link</tag>
+ * elements with an id='' attribute) that are encountered while parsing
* will be added to this table.
+ * Note that toplevel <tag class="starttag">menu</tag> is not added to
+ * the hash table, even if it has an id attribute.
*
* If @objects is %NULL then named menus will not be supported.
*