|
Packit |
1470ea |
public class MyWindow : Gtk.ApplicationWindow {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Callback functions for the window actions. */
|
|
Packit |
1470ea |
void copy_cb (SimpleAction action, Variant? parameter) {
|
|
Packit |
1470ea |
print ("\"Copy\" activated\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void paste_cb (SimpleAction action, Variant? parameter) {
|
|
Packit |
1470ea |
print ("\"Paste\" activated\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void shape_cb (SimpleAction action, Variant? parameter) {
|
|
Packit |
1470ea |
print ("shape is set to %s\n", parameter.get_string(null));
|
|
Packit |
1470ea |
action.set_state (parameter);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create the window actions. */
|
|
Packit |
1470ea |
const ActionEntry[] actions = {
|
|
Packit |
1470ea |
/*{ "action name", cb to connect to "activate" signal, parameter type,
|
|
Packit |
1470ea |
initial state, cb to connect to "change-state" signal } */
|
|
Packit |
1470ea |
{ "copy", copy_cb },
|
|
Packit |
1470ea |
{ "paste", paste_cb },
|
|
Packit |
1470ea |
{ "shape", shape_cb, "s", "'line'"}
|
|
Packit |
1470ea |
};
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
internal MyWindow (MyApplication app) {
|
|
Packit |
1470ea |
Object (application: app, title: "MenuBar Example");
|
|
Packit |
1470ea |
this.set_default_size (200, 200);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Setup window actions. */
|
|
Packit |
1470ea |
this.add_action_entries (actions, this);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyApplication: Gtk.Application {
|
|
Packit |
1470ea |
protected override void activate () {
|
|
Packit |
1470ea |
new MyWindow (this).show ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Callback functions for the application actions. */
|
|
Packit |
1470ea |
void new_cb (SimpleAction action, Variant? parameter) {
|
|
Packit |
1470ea |
//new MyWindow (this).show ();
|
|
Packit |
1470ea |
print ("You clicked \"New\"\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void quit_cb (SimpleAction action, Variant? parameter) {
|
|
Packit |
1470ea |
print ("You clicked \"Quit\"\n");
|
|
Packit |
1470ea |
this.quit ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void awesome_cb (SimpleAction action, Variant? parameter) {
|
|
Packit |
1470ea |
var active = action.get_state ().get_boolean ();
|
|
Packit |
1470ea |
action.set_state (new Variant.boolean (!active));
|
|
Packit |
1470ea |
if (active)
|
|
Packit |
1470ea |
print ("You unchecked \"Awesome\"\n");
|
|
Packit |
1470ea |
else
|
|
Packit |
1470ea |
print ("You checked \"Awesome\"\n");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void state_cb (SimpleAction action, Variant? parameter) {
|
|
Packit |
1470ea |
print ("state is set to %s\n", parameter.get_string(null));
|
|
Packit |
1470ea |
action.set_state (parameter);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create the application actions. */
|
|
Packit |
1470ea |
const ActionEntry[] actions = {
|
|
Packit |
1470ea |
{ "new", new_cb },
|
|
Packit |
1470ea |
{ "quit", quit_cb },
|
|
Packit |
1470ea |
{ "awesome", awesome_cb, null, "false" },
|
|
Packit |
1470ea |
{ "state", state_cb, "s", "'off'" }
|
|
Packit |
1470ea |
};
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
protected override void startup () {
|
|
Packit |
1470ea |
base.startup ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Setup application actions. */
|
|
Packit |
1470ea |
this.add_action_entries (actions, this);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Setup menubar and app_menu. */
|
|
Packit |
1470ea |
/* Get the UI file. */
|
|
Packit |
1470ea |
var builder = new Gtk.Builder ();
|
|
Packit |
1470ea |
try {
|
|
Packit |
1470ea |
builder.add_from_file ("menubar.ui");
|
|
Packit |
1470ea |
} catch (Error e) {
|
|
Packit |
1470ea |
error ("Unable to load file: %s", e.message);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Get the menubar from the builder. */
|
|
Packit |
1470ea |
this.menubar = builder.get_object ("menubar") as MenuModel;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Get the app_menu from the builder. */
|
|
Packit |
1470ea |
this.app_menu = builder.get_object ("appmenu") as MenuModel;
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* main creates and runs the application. */
|
|
Packit |
1470ea |
public int main (string[] args) {
|
|
Packit |
1470ea |
return new MyApplication ().run (args);
|
|
Packit |
1470ea |
}
|