[gnome-devel-docs] Vala samples: updated messagedialog to use Menu.



commit 3a69de4be6e905359e028e9f3c5b5c3301e86b4d
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date:   Sat Apr 28 18:56:01 2012 -0400

    Vala samples: updated messagedialog to use Menu.

 platform-demos/C/media/messagedialog.png        |  Bin 11072 -> 8108 bytes
 platform-demos/C/messagedialog.vala.page        |   40 +----------
 platform-demos/C/samples/messagedialog.vala     |   86 ++++++++++++++++------
 platform-demos/C/samples/messagedialog_old.vala |   28 +++++++
 platform-demos/Makefile.am                      |    1 +
 5 files changed, 95 insertions(+), 60 deletions(-)
---
diff --git a/platform-demos/C/media/messagedialog.png b/platform-demos/C/media/messagedialog.png
index 826a713..e077bce 100644
Binary files a/platform-demos/C/media/messagedialog.png and b/platform-demos/C/media/messagedialog.png differ
diff --git a/platform-demos/C/messagedialog.vala.page b/platform-demos/C/messagedialog.vala.page
index 4683f73..0c02395 100644
--- a/platform-demos/C/messagedialog.vala.page
+++ b/platform-demos/C/messagedialog.vala.page
@@ -1,4 +1,5 @@
 <page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
       type="guide" style="task"
       id="messagedialog.vala">
   <info>
@@ -18,42 +19,9 @@
   <media type="image" mime="image/png" src="media/messagedialog.png"/>
   <p>A modal message dialog which can cause the world to explode.</p>
 
-      <code mime="text/x-vala" style="numbered"><![CDATA[
-void dialog_response (int response_id) {
-	switch (response_id) {
-		case Gtk.ResponseType.OK:
-			print ("*boom*\n");
-			break;
-		case Gtk.ResponseType.CANCEL:
-			print ("good choice\n");
-			break;
-		case Gtk.ResponseType.DELETE_EVENT:
-			print ("dialog closed or cancelled\n");
-			break;
-	}
-
-	Gtk.main_quit ();
-}
-
-int main (string[] args) {
-
-	Gtk.init (ref args);
-
-	var messagedialog = new Gtk.MessageDialog (null,
-						   Gtk.DialogFlags.MODAL,
-                                                   Gtk.MessageType.INFO,
-                                                   Gtk.ButtonsType.OK_CANCEL,
-                                                   "This action will cause the universe to stop existing.");
-
-	messagedialog.response.connect (dialog_response);
-
- 	messagedialog.show ();
-
-	Gtk.main ();
-
-	return 0;
-}
-]]></code>
+<code mime="text/x-vala" style="numbered">
+<xi:include href="samples/messagedialog.vala" parse="text"><xi:fallback/></xi:include>
+</code>
 <p>
   In this sample we used the following:
 </p>
diff --git a/platform-demos/C/samples/messagedialog.vala b/platform-demos/C/samples/messagedialog.vala
index 3f8d15d..5a27cb4 100644
--- a/platform-demos/C/samples/messagedialog.vala
+++ b/platform-demos/C/samples/messagedialog.vala
@@ -1,34 +1,72 @@
-void dialog_response (int response_id) {
-	switch (response_id) {
-		case Gtk.ResponseType.OK:
-			print ("*boom*\n");
-			break;
-		case Gtk.ResponseType.CANCEL:
-			print ("good choice\n");
-			break;
-		case Gtk.ResponseType.DELETE_EVENT:
-			print ("dialog closed or cancelled\n");
-			break;
+//A window in the application
+public class Window : Gtk.ApplicationWindow {
+	public Window (Application app) {
+		Object (application: app, title: "Gtk.MessageDialog Example");
+
+		var label = new Gtk.Label ("This application goes boom!");
+		this.add (label);
+
+		var message_action = new SimpleAction ("message", null);
+		message_action.activate.connect (message);
+		this.add_action (message_action);
+
+		this.set_default_size (400, 200);
+		this.show_all ();
 	}
 
-	Gtk.main_quit ();
-}
+	void dialog_response (Gtk.Dialog dialog, int response_id) {
+		switch (response_id) {
+			case Gtk.ResponseType.OK:
+				print ("*boom*\n");
+				break;
+			case Gtk.ResponseType.CANCEL:
+				print ("good choice\n");
+				break;
+			case Gtk.ResponseType.DELETE_EVENT:
+				print ("dialog closed or cancelled\n");
+				break;
+		}
+			dialog.destroy();
+	}
 
-int main (string[] args) {
+	void message () {
+		var messagedialog = new Gtk.MessageDialog (this,
+						           Gtk.DialogFlags.MODAL,
+		                                           Gtk.MessageType.WARNING,
+                                                           Gtk.ButtonsType.OK_CANCEL,
+	                                                   "This action will cause the universe to stop existing.");
 
-	Gtk.init (ref args);
+		messagedialog.response.connect (dialog_response);
+ 		messagedialog.show ();
+	}
+}
 
-	var messagedialog = new Gtk.MessageDialog (null,
-						   Gtk.DialogFlags.MODAL,
-		                                   Gtk.MessageType.WARNING,
-                                                   Gtk.ButtonsType.OK_CANCEL,
-	                                           "This action will cause the universe to stop existing.");
+//This is the Application
+public class Application : Gtk.Application {
+	protected override void activate () {
+		new Window (this);
+	}
 
-	messagedialog.response.connect (dialog_response);
+	protected override void startup () {
+		base.startup ();
 
- 	messagedialog.show ();
+		var menu = new Menu ();
+		menu.append ("Message", "win.message");
+		menu.append ("Quit", "app.quit");
+		this.app_menu = menu;
 
-	Gtk.main ();
+		var quit_action = new SimpleAction ("quit", null);
+		//quit_action.activate.connect (this.quit);
+		this.add_action (quit_action);
+	}
 
-	return 0;
+	public Application () {
+		Object (application_id: "org.example.application");
+	}
 }
+
+//main function creates Application and runs it
+int main (string[] args) {
+	return new Application ().run (args);
+}
+
diff --git a/platform-demos/C/samples/messagedialog_old.vala b/platform-demos/C/samples/messagedialog_old.vala
new file mode 100644
index 0000000..d9f8a8e
--- /dev/null
+++ b/platform-demos/C/samples/messagedialog_old.vala
@@ -0,0 +1,28 @@
+void dialog_response (int response_id) {
+	switch (response_id) {
+		case Gtk.ResponseType.OK:
+			print ("*boom*\n");
+			break;
+		case Gtk.ResponseType.CANCEL:
+			print ("good choice\n");
+			break;
+		case Gtk.ResponseType.DELETE_EVENT:
+			print ("dialog closed or cancelled\n");
+			break;
+	}
+	Gtk.main_quit ();
+}
+
+int main (string[] args) {
+
+	Gtk.init (ref args);
+	var messagedialog = new Gtk.MessageDialog (null,
+						   Gtk.DialogFlags.MODAL,
+		                                   Gtk.MessageType.WARNING,
+                                                   Gtk.ButtonsType.OK_CANCEL,
+	                                           "This action will cause the universe to stop existing.");
+	messagedialog.response.connect (dialog_response);
+ 	messagedialog.show ();
+	Gtk.main ();
+	return 0;
+}
diff --git a/platform-demos/Makefile.am b/platform-demos/Makefile.am
index 2a804a3..0d3ba75 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -26,6 +26,7 @@ demo_sources = \
 	samples/dialog.vala			\
 	samples/grid.py				\
 	samples/GtkApplicationWindow.vala	\
+	samples/messagedialog.vala		\
 	samples/window.c			\
 	samples/window.py			\
 	samples/window.vala			\



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]