GMenu

You need to be running GTK+-3.4 or later for this to work

A GtkApplication with a simple GMenu and SimpleActions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* A window in the application. */
public class Window : Gtk.ApplicationWindow {

	/* Constructor */
	public Window (Application app) {
		Object (application: app, title: "Gmenu Example");

		var about_action = new SimpleAction ("about", null);

		/* Connect the 'activate' signal to the
		 * signal handler (aka. callback).
		 */
		about_action.activate.connect (this.about_cb);

		/* Add the action to this window. */
		this.add_action (about_action);

		this.show ();
	}

	/* Signal handler for 'activate' signal of the SimpleAction. */
	void about_cb (SimpleAction simple, Variant? parameter) {
		print ("This does nothing.  It is only a demonstration.\n");
	}
}

/* This is the Application. */
public class Application : Gtk.Application {

	/* Constructor */
	public Application () {
		Object (application_id: "org.example.application");
	}

	/* Override the 'activate' signal of GLib.Application. */
	protected override void activate () {

		/* Create a new window for this application. */
		new Window (this);
	}

	/* Override the 'startup' signal of GLib.Application. */
	protected override void startup () {
		base.startup ();

		var menu = new Menu ();
		menu.append ("About", "win.about");
		menu.append ("Quit", "app.quit");
		this.app_menu = menu;

		var quit_action = new SimpleAction ("quit", null);
		quit_action.activate.connect (this.quit);
		this.add_action (quit_action);
	}
}

/* main function creates Application and runs it. */
int main (string[] args) {
	return new Application ().run (args);
}

In this sample we used the following: