Getting a GMenuItem from GtkBuilder

Should the code below work, to get a menu item from a GtkBuilder using
the <menu> markup? It doesn't seem to. I'm guessing at the XML syntax
based on this:

I would use Glade to show me the correct syntax, but it doesn't use this
<menu>/<section>/<item> syntax yet.

#include <gtk/gtk.h>

const char* ui = 
  "  <menu id='somemenu'>"
  "    <section>"
  "      <item>"
  "        <attribute name='label' translatable='yes'>Some
  "        <attribute name='id'>something</attribute>"
  "      </item>"
  "      <item>"
  "        <attribute name='label' translatable='yes'>Other
  "        <attribute name='id'>otherthing</attribute>"
  "      </item>"
  "    </section>"
  "  </menu>"

main (int argc, char *argv[])
  GtkBuilder* builder = gtk_builder_new();

  GError* error = NULL;
  gtk_builder_add_from_string (builder, ui, -1, &error);
  g_assert_no_error (error);

  GMenu* menu = G_MENU (gtk_builder_get_object (builder, "somemenu"));
  g_assert (menu);

  GMenuItem* menu_item = G_MENU_ITEM (gtk_builder_get_object (builder,
  g_assert (menu_item);

  gtk_main ();

  g_object_unref (G_OBJECT (builder));
  return 0;

murrayc murrayc com

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