const Gtk = imports.gi.Gtk;
const Lang = imports.lang;

const HelloGNOME = new Lang.Class ({
    Name: 'Hello GNOME',
    _init: function () {
        this.application = new Gtk.Application ();

        this.application.connect('activate', Lang.bind(this, this._onActivate));
        this.application.connect('startup', Lang.bind(this, this._onStartup));
    },

    _onActivate: function () {
        this._window.present ();
    },

    _onStartup: function () {
        this._window = new Gtk.ApplicationWindow  ({
            application: this.application
        });
        let popover = new Gtk.Popover();
        let frame = this.frame = new Gtk.Frame();
        let lb = new Gtk.ListBox();
        let row1 = new Gtk.ListBoxRow();
        let row2 = new Gtk.ListBoxRow();
        let label1 = new Gtk.ToggleButton({label: 'toggle frame'});
        label1.connect('toggled', (function(button) {
            this.frame.shadow_type = button.get_active() ? Gtk.ShadowType.NONE : Gtk.ShadowType.IN;
        }).bind(this));
        let label2 = new Gtk.Button({label: 'no room'});
        row1.add(label1);
        row2.add(label2);
        lb.add(row1);
        lb.add(row2);
        frame.add(lb);
        frame.show_all();
        popover.add(frame);

        let button = new Gtk.MenuButton({ popover: popover,
                                          label: 'click me',
                                          margin: 100 });
        this._window.add(button);
        button.show_all();
    },
});

let app = new HelloGNOME ();
app.application.run (ARGV);
