|
Packit |
1470ea |
//A window in the application
|
|
Packit |
1470ea |
public class Window : Gtk.ApplicationWindow {
|
|
Packit |
1470ea |
public Window (Application app) {
|
|
Packit |
1470ea |
Object (application: app, title: "Gtk.MessageDialog Example");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
var label = new Gtk.Label ("This application goes boom!");
|
|
Packit |
1470ea |
this.add (label);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
var message_action = new SimpleAction ("message", null);
|
|
Packit |
1470ea |
message_action.activate.connect (message);
|
|
Packit |
1470ea |
this.add_action (message_action);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this.set_default_size (400, 200);
|
|
Packit |
1470ea |
this.show_all ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void dialog_response (Gtk.Dialog dialog, int response_id) {
|
|
Packit |
1470ea |
switch (response_id) {
|
|
Packit |
1470ea |
case Gtk.ResponseType.OK:
|
|
Packit |
1470ea |
print ("*boom*\n");
|
|
Packit |
1470ea |
break;
|
|
Packit |
1470ea |
case Gtk.ResponseType.CANCEL:
|
|
Packit |
1470ea |
print ("good choice\n");
|
|
Packit |
1470ea |
break;
|
|
Packit |
1470ea |
case Gtk.ResponseType.DELETE_EVENT:
|
|
Packit |
1470ea |
print ("dialog closed or cancelled\n");
|
|
Packit |
1470ea |
break;
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
dialog.destroy();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void message (SimpleAction simple, Variant? parameter) {
|
|
Packit |
1470ea |
var messagedialog = new Gtk.MessageDialog (this,
|
|
Packit |
1470ea |
Gtk.DialogFlags.MODAL,
|
|
Packit |
1470ea |
Gtk.MessageType.WARNING,
|
|
Packit |
1470ea |
Gtk.ButtonsType.OK_CANCEL,
|
|
Packit |
1470ea |
"This action will cause the universe to stop existing.");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
messagedialog.response.connect (dialog_response);
|
|
Packit |
1470ea |
messagedialog.show ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//This is the Application
|
|
Packit |
1470ea |
public class Application : Gtk.Application {
|
|
Packit |
1470ea |
protected override void activate () {
|
|
Packit |
1470ea |
new Window (this);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
protected override void startup () {
|
|
Packit |
1470ea |
base.startup ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
var menu = new Menu ();
|
|
Packit |
1470ea |
menu.append ("Message", "win.message");
|
|
Packit |
1470ea |
menu.append ("Quit", "app.quit");
|
|
Packit |
1470ea |
this.app_menu = menu;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
var quit_action = new SimpleAction ("quit", null);
|
|
Packit |
1470ea |
//quit_action.activate.connect (this.quit);
|
|
Packit |
1470ea |
this.add_action (quit_action);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
public Application () {
|
|
Packit |
1470ea |
Object (application_id: "org.example.application");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
//main function creates Application and runs it
|
|
Packit |
1470ea |
int main (string[] args) {
|
|
Packit |
1470ea |
return new Application ().run (args);
|
|
Packit |
1470ea |
}
|