GtkBuilder menus and separators in menus

I am trying to create a menu using GtkBuilder, and try to make a GTK2 style top menu, and have succeeded somewhat, but what I cannot find is how to make a menu separator, like in the image below: (simply the line - I don’t mind if it is just a thin line or if it fills a text entry completly):

bild

As said, I am building my menu using GtkBuilder from a xml (inline in the code), and in part it looks like this:

  static const char *menu_string = ""
  "<interface>"
  "<menu id='menu'>"
      "<submenu>"
        "<attribute name='label' translatable='yes'>Something</attribute>"
        "<item>"
          "<attribute name='label' translatable='yes'>Something</attribute>"
          "<attribute name='action'>app.something</attribute>"
        "</item>"
        "<item>"
          "<attribute name='label' translatable='yes'>Something Else</attribute>"
          "<attribute name='action'>app.something_else</attribute>"
        "</item>"
      "</submenu>"

What is the XML syntax here to insert a separator? Is this some old XML variant? The examples I can find use GtkMenu and stuff like that in the actual XML.

If possible I don’t want to migrate to a new XML which requires me to remake all the menus.

Also, I have searched, but it seems quite hard to find documentation on the syntax of this XML.

Use sections:

<menu id="menu">
  <section>
    <item>
      <attribute name="label">Something</attribute>
      <attribute name="action">win.action1</attribute>
    </item>
    <item>
      <attribute name="label">Something Else</attribute>
      <attribute name="action">win.action2</attribute>
    </item>
  </section>
  <section>
    <item>
      <attribute name="label">Something Else Separated</attribute>
      <attribute name="action">win.action3</attribute>
    </item>
  </section>
</menu>

You’ll get a separator between the two sections.

1 Like

Excellent - Thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.