Re: Merging UI strings into Gtk::Builder?



I made some tests with the menus_and_toolbars example in gtkmm-documentation. Something like this will probably work:
  Glib::ustring ui_info =
    "<interface>"
    "  <menu id='menu-linuxchess'>"
    "    <submenu>"
...
    "    </submenu>"
    "  </menu>"
    "</interface>";

  Glib::ustring ui_info2 =
    "<interface>"
    "  <menu id='menu-linuxchess-part2'>"
    "    <submenu id="xyz">"
...
    "    </submenu>"
    "  </menu>" 
    "</interface>";

  m_refBuilder = Gtk::Builder::create();
  m_refBuilder->add_from_string(ui_info);
  m_refBuilder->add_from_string(ui_info2);
  auto object = m_refBuilder->get_object("menu-linuxchess");
  auto gmenu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
  if (gmenu)
  {
    auto subobject = m_refBuilder->get_object("xyz");
    auto gsubmenu = Glib::RefPtr<Gio::Menu>::cast_dynamic(subobject);
    if (gsubmenu)
      gmenu->append_submenu("SomeLabel", gsubmenu);
  }

On 2020-07-27 15:50, Carlo Wood wrote:
Hi,

the documentation at

https://developer.gnome.org/gtkmm/stable/classGtk_1_1Builder.html#ae3520ee31a98ac30b728f93522de8df5

says: "Parses a string containing a GtkBuilder UI definition and merges
it with the current contents of the builder."

But when I try this:

  Glib::ustring ui_info =
    "<interface>"
    "  <menu id='menu-linuxchess'>"
    "    <submenu>"
...
    "    </submenu>"
    "  </menu>"
    "</interface>";

  Glib::ustring ui_info2 =
    "<interface>"
    "  <menu id='menu-linuxchess'>"
    "    <submenu>"
...
    "    </submenu>"
    "  </menu>" 
    "</interface>";

  m_refBuilder = Gtk::Builder::create();
  m_refBuilder->add_from_string(ui_info);
  m_refBuilder->add_from_string(ui_info2);

Then the last line *replaces* the content of m_refBuilder.
Nothing is merged, I just get a menu with the definition
from ui_info2.

How can I do this?


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