Blame platform-demos/C/samples/dialog.vala

Packit 1470ea
/* A window in the application. */
Packit 1470ea
public class MyWindow : Gtk.ApplicationWindow {
Packit 1470ea
Packit 1470ea
	/* Constructor */
Packit 1470ea
	internal MyWindow (MyApplication app) {
Packit 1470ea
		Object (application: app, title: "GNOME Button");
Packit 1470ea
Packit 1470ea
		this.window_position = Gtk.WindowPosition.CENTER;
Packit 1470ea
		this.set_default_size (250,50);
Packit 1470ea
Packit 1470ea
		var button = new Gtk.Button.with_label ("Click Me");
Packit 1470ea
Packit 1470ea
		/* Connect the button's "clicked" signal to
Packit 1470ea
		 * the signal handler (aka. this.callback function).
Packit 1470ea
		 */
Packit 1470ea
		button.clicked.connect (this.on_button_click);
Packit 1470ea
Packit 1470ea
		/* Add the button to this window and show it. */
Packit 1470ea
		this.add (button);
Packit 1470ea
		button.show ();
Packit 1470ea
	}
Packit 1470ea
Packit 1470ea
	/* The signal handler for the buttons 'clicked' signal. */
Packit 1470ea
	void on_button_click (Gtk.Button button) {
Packit 1470ea
		var dialog = new Gtk.Dialog.with_buttons ("A Gtk+ Dialog", this,
Packit 1470ea
                                                          Gtk.DialogFlags.MODAL,
Packit 1470ea
                                                          Gtk.Stock.OK,
Packit 1470ea
                                                          Gtk.ResponseType.OK, null);
Packit 1470ea
Packit 1470ea
		var content_area = dialog.get_content_area ();
Packit 1470ea
		var label = new Gtk.Label ("This demonstrates a dialog with a label");
Packit 1470ea
Packit 1470ea
		content_area.add (label);
Packit 1470ea
Packit 1470ea
		/* Connect the 'response' signal of the dialog
Packit 1470ea
		 * the signal handler.  It is emitted when the dialog's
Packit 1470ea
		 * OK button is clicked.
Packit 1470ea
		 */
Packit 1470ea
		dialog.response.connect (on_response);
Packit 1470ea
Packit 1470ea
		/* Show the dialog and all the widgets. */
Packit 1470ea
		dialog.show_all ();
Packit 1470ea
	}
Packit 1470ea
Packit 1470ea
	/* Signal handler for the 'response' signal of the dialog. */
Packit 1470ea
        void on_response (Gtk.Dialog dialog, int response_id) {
Packit 1470ea
Packit 1470ea
                /* To see the int value of the ResponseType. This is only
Packit 1470ea
		 * for demonstration purposes.*/
Packit 1470ea
                print ("response is %d\n", response_id);
Packit 1470ea
Packit 1470ea
		/* This causes the dialog to be destroyed. */
Packit 1470ea
                dialog.destroy ();
Packit 1470ea
        }
Packit 1470ea
Packit 1470ea
}
Packit 1470ea
Packit 1470ea
/* This is the application. */
Packit 1470ea
public class MyApplication : Gtk.Application {
Packit 1470ea
Packit 1470ea
	/* The constructor of the application. */
Packit 1470ea
	internal MyApplication () {
Packit 1470ea
		Object (application_id: "org.example.MyApplication");
Packit 1470ea
	}
Packit 1470ea
Packit 1470ea
	/* Override the 'activate' signal of GLib.Application. */
Packit 1470ea
	protected override void activate () {
Packit 1470ea
Packit 1470ea
		/* Create a window for the this application and show it. */
Packit 1470ea
		new MyWindow (this).show ();
Packit 1470ea
	}
Packit 1470ea
}
Packit 1470ea
Packit 1470ea
/* The main function creates and runs the application. */
Packit 1470ea
public int main (string[] args) {
Packit 1470ea
	return new MyApplication ().run (args);
Packit 1470ea
}