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:
https://developer.gnome.org/gtk3/unstable/GtkBuilder.html#BUILDER-UI

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 = 
  "<interface>"
  "  <menu id='somemenu'>"
  "    <section>"
  "      <item>"
  "        <attribute name='label' translatable='yes'>Some
Thing</attribute>"
  "        <attribute name='id'>something</attribute>"
  "      </item>"
  "      <item>"
  "        <attribute name='label' translatable='yes'>Other
Thing</attribute>"
  "        <attribute name='id'>otherthing</attribute>"
  "      </item>"
  "    </section>"
  "  </menu>"
  "</interface>";

int
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,
"something"));
  g_assert (menu_item);

  gtk_main ();

  g_object_unref (G_OBJECT (builder));
   
  return 0;
}

-- 
murrayc murrayc com
www.murrayc.com
www.openismus.com




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