|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="messagedialog.vala" xml:lang="ca">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">MessageDialog (Vala)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.vala#windows"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-04-07" status="stub"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Tiffany Antopolski</name>
|
|
Packit |
1470ea |
<email its:translate="no">tiffany.antopolski@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>A message window</desc>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>MessageDialog</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/messagedialog.png"/>
|
|
Packit |
1470ea |
A modal message dialog which can cause the world to explode.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
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 |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
In this sample we used the following:
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.ResponseType.html">Gtk.ResponseType</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.MessageDialog.html">Gtk.MessageDialog</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.DialogFlags.html">Gtk.DialogFlags</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.MessageType.html">Gtk.MessageType</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.ButtonsType.html">Gtk.ButtonsType</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</page>
|