diff options
author | Matthias Clasen <mclasen@redhat.com> | 2011-11-01 19:53:51 -0400 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2011-12-19 12:45:50 -0500 |
commit | 1ddaf01aed98462dfdd13370ec3d62d468cf343f (patch) | |
tree | 28c7ccc55371a7d255df3351b15cf4b00b2f4606 /gtk/gtkbuilderparser.c | |
parent | fd9df1864b2ad52363e62bd54ea6a3dbb8e9ebfd (diff) | |
download | gtk+-1ddaf01aed98462dfdd13370ec3d62d468cf343f.tar.gz |
Quick-and-dirty GtkBuilder integration
This makes GtkBuilder accept a GMenuMarkup tree at the toplevel
(ie with <menu id='foo'> being a child of <interface>) and the resulting
GMenu object can be obtained via gtk_builder_get_object (builder, "foo").
Diffstat (limited to 'gtk/gtkbuilderparser.c')
-rw-r--r-- | gtk/gtkbuilderparser.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c index 5ea15e3c60..d0071f90de 100644 --- a/gtk/gtkbuilderparser.c +++ b/gtk/gtkbuilderparser.c @@ -23,6 +23,7 @@ #include <string.h> #include <gmodule.h> +#include <gio/gio.h> #include "gtkbuilderprivate.h" #include "gtkbuilder.h" #include "gtkbuildable.h" @@ -823,6 +824,34 @@ parse_custom (GMarkupParseContext *context, return TRUE; } +static gboolean +parse_menu (GMarkupParseContext *context, + const gchar *element_name, + const gchar **names, + const gchar **values, + gpointer user_data, + GError **error) +{ + gchar *id; + ParserData *data = user_data; + ObjectInfo *object_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); + + g_menu_markup_parser_start_menu (context, NULL); + + return TRUE; +} + static void start_element (GMarkupParseContext *context, const gchar *element_name, @@ -883,6 +912,8 @@ start_element (GMarkupParseContext *context, parse_signal (data, element_name, names, values, error); else if (strcmp (element_name, "interface") == 0) parse_interface (data, element_name, names, values, error); + else if (strcmp (element_name, "menu") == 0) + parse_menu (context, element_name, names, values, data, error); else if (strcmp (element_name, "placeholder") == 0) { /* placeholder has no special treatmeant, but it needs an @@ -954,6 +985,18 @@ end_element (GMarkupParseContext *context, else if (strcmp (element_name, "interface") == 0) { } + else if (strcmp (element_name, "menu") == 0) + { + ObjectInfo *object_info; + GObject *menu; + + object_info = state_pop_info (data, ObjectInfo); + menu = (GObject*)g_menu_markup_parser_end_menu (context); + _gtk_builder_add_object (data->builder, object_info->id, menu); + g_object_unref (menu); + + free_object_info (object_info); + } else if (data->requested_objects && !data->inside_requested_object) { /* If outside a requested object, simply ignore this tag */ |