1public class MyWindow : Gtk.ApplicationWindow { 2 3 /* Callback functions for the window actions. */ 4 void copy_cb (SimpleAction action, Variant? parameter) { 5 print ("\"Copy\" activated\n"); 6 } 7 8 void paste_cb (SimpleAction action, Variant? parameter) { 9 print ("\"Paste\" activated\n"); 10 } 11 12 void shape_cb (SimpleAction action, Variant? parameter) { 13 print ("shape is set to %s\n", parameter.get_string(null)); 14 action.set_state (parameter); 15 } 16 17 /* Create the window actions. */ 18 const ActionEntry[] actions = { 19 /*{ "action name", cb to connect to "activate" signal, parameter type, 20 initial state, cb to connect to "change-state" signal } */ 21 { "copy", copy_cb }, 22 { "paste", paste_cb }, 23 { "shape", shape_cb, "s", "'line'"} 24 }; 25 26 internal MyWindow (MyApplication app) { 27 Object (application: app, title: "MenuBar Example"); 28 this.set_default_size (200, 200); 29 30 /* Setup window actions. */ 31 this.add_action_entries (actions, this); 32 } 33} 34 35class MyApplication: Gtk.Application { 36 protected override void activate () { 37 new MyWindow (this).show (); 38 } 39 40 /* Callback functions for the application actions. */ 41 void new_cb (SimpleAction action, Variant? parameter) { 42 //new MyWindow (this).show (); 43 print ("You clicked \"New\"\n"); 44 } 45 46 void quit_cb (SimpleAction action, Variant? parameter) { 47 print ("You clicked \"Quit\"\n"); 48 this.quit (); 49 } 50 51 void awesome_cb (SimpleAction action, Variant? parameter) { 52 var active = action.get_state ().get_boolean (); 53 action.set_state (new Variant.boolean (!active)); 54 if (active) 55 print ("You unchecked \"Awesome\"\n"); 56 else 57 print ("You checked \"Awesome\"\n"); 58 } 59 60 void state_cb (SimpleAction action, Variant? parameter) { 61 print ("state is set to %s\n", parameter.get_string(null)); 62 action.set_state (parameter); 63 } 64 65 /* Create the application actions. */ 66 const ActionEntry[] actions = { 67 { "new", new_cb }, 68 { "quit", quit_cb }, 69 { "awesome", awesome_cb, null, "false" }, 70 { "state", state_cb, "s", "'off'" } 71 }; 72 73 protected override void startup () { 74 base.startup (); 75 76 /* Setup application actions. */ 77 this.add_action_entries (actions, this); 78 79 /* Setup menubar and app_menu. */ 80 /* Get the UI file. */ 81 var builder = new Gtk.Builder (); 82 try { 83 builder.add_from_file ("menubar.ui"); 84 } catch (Error e) { 85 error ("Unable to load file: %s", e.message); 86 } 87 88 /* Get the menubar from the builder. */ 89 this.menubar = builder.get_object ("menubar") as MenuModel; 90 91 /* Get the app_menu from the builder. */ 92 this.app_menu = builder.get_object ("appmenu") as MenuModel; 93 } 94} 95 96/* main creates and runs the application. */ 97public int main (string[] args) { 98 return new MyApplication ().run (args); 99} 100