namespace Example {

	public class Application : Gtk.Application {

		public GLib.Menu edit_menu;

		public Application () {
			Object (application_id: "org.gnome.gaction.example");
		}

		public void hello () {
			stdout.printf ("Hello World!\n");
		}

		public override void startup () {
			base.startup ();

			var app_action_entries = new GLib.ActionEntry[] {
				GLib.ActionEntry () {
					name = "quit",
					activate = () => {
						this.hello ();
						foreach (var window in this.get_windows ()) {
							window.destroy ();
						}
					}
				}
			};
			this.add_action_entries (app_action_entries, this);

			var builder = new Gtk.Builder ();
			builder.add_from_string ("<interface>" +
			                         "  <menu id='app-menu'>" +
			                         "    <section>" +
			                         "      <item>" +
			                         "        <attribute name='label' translatable='yes'>_Quit</attribute>" +
			                         "        <attribute name='action'>app.quit</attribute>" +
			                         "        <attribute name='accel'>&lt;Primary&gt;q</attribute>" +
			                         "      </item>" +
			                         "    </section>" +
			                         "  </menu>" +
			                         "  <menu id='menubar'>" +
			                         "    <submenu>" +
			                         "      <attribute name='label' translatable='yes'>_Edit</attribute>" +
			                         "      <section id='menu-edit-section'>" +
			                         "      </section>" +
			                         "    </submenu>" +
			                         "  </menu>" +
			                         "</interface>", -1);
			this.app_menu = builder.get_object ("app-menu") as GLib.MenuModel;
			this.menubar = builder.get_object ("menubar") as GLib.MenuModel;
			this.edit_menu = builder.get_object ("menu-edit-section") as GLib.Menu;
		}

		public override void activate () {
			var window = new Window (this);
			window.present ();
		}
	}

	public class Window : Gtk.ApplicationWindow {

		public Window (Application app) {
			this.application = app;
			this.title = "Hello World!";
			this.default_width = 640;
			this.default_height = 360;

			var action_entries = new GLib.ActionEntry[] {
				GLib.ActionEntry () {
					name = "copy",
					activate = () => {
						(this.lookup_action ("copy") as GLib.SimpleAction).set_enabled (false);
					}
				}
			};
			this.add_action_entries (action_entries, this);

			app.edit_menu.append ("_Copy", "win.copy");
		}

	}

}

public static int main (string[] args) {
	var app = new Example.Application ();
	app.run ();

	return 0;
}
