#!/usr/bin/env gjs-console

const Gtk = imports.gi.Gtk
const Gio = imports.gi.Gio

let app = new Gtk.Application({
    application_id: null
})

app.connect("startup", function() {
    let window = new Gtk.ApplicationWindow({
        title: "test",
        application: app
    });

    app.connect("activate", function(){
        window.show_all()
        window.present()
    })

    window.add(new Gtk.Label({ label: "AppMenu with submenus in GNOME Shell" }))

    let menuXml = '<?xml version="1.0" encoding="UTF-8"?> \
<interface> \
    <menu id="appmenu"> \
        <item> \
            <attribute name="label">A simple item</attribute> \
        </item> \
        <submenu> \
            <attribute name="label">First sub</attribute> \
            <section> \
                <item> \
                    <attribute name="label">Abcdefghiklmnop</attribute> \
                </item> \
                <item> \
                    <attribute name ="label">Foo Bar Baz</attribute> \
                </item> \
            </section> \
            <submenu> \
                <attribute name="label">Nested submenu</attribute> \
                <section> \
                    <item> \
                        <attribute name="label">If you see this, the bug has been fixed</attribute> \
                    </item> \
                </section> \
            </submenu> \
        </submenu> \
        <submenu> \
            <attribute name="label">2nd sub</attribute> \
            <section> \
                <item> \
                    <attribute name="label">wow very menu</attribute> \
                </item> \
            </section> \
        </submenu> \
    </menu> \
</interface>'

    let builder = Gtk.Builder.new_from_string(menuXml, -1)

    app.set_app_menu(builder.get_object('appmenu'))


});

app.run(ARGV)
