[gnome-devel-docs] Vala samples: Lots of updates



commit e2a6b753c6f503388fd38d310c430c233607b3f0
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date:   Sat Apr 28 00:05:58 2012 -0400

    Vala samples: Lots of updates
    
    - update some samples to use GtkApplication
    - added XIncludes to completed samples
    - updated Makefile.am as necessary

 platform-demos/C/GtkApplicationWindow.vala.page    |   27 +-----
 platform-demos/C/aboutdialog.vala.page             |   81 --------------------
 platform-demos/C/aboutdialog_GMenu.vala.page       |   41 ++++++++++
 platform-demos/C/beginner.vala.page                |    2 -
 platform-demos/C/dialog.vala.page                  |   29 +------
 platform-demos/C/image-viewer.vala.page            |    8 +-
 .../{aboutdialog.png => aboutdialog_GMenu.png}     |  Bin 15084 -> 15084 bytes
 platform-demos/C/media/dialog.png                  |  Bin 7318 -> 3533 bytes
 ...{GtkApplication.vala => aboutdialog_GMenu.vala} |    4 -
 platform-demos/C/samples/dialog.vala               |   56 ++++++++++----
 platform-demos/C/window.vala.page                  |   35 +--------
 platform-demos/Makefile.am                         |    8 ++-
 12 files changed, 103 insertions(+), 188 deletions(-)
---
diff --git a/platform-demos/C/GtkApplicationWindow.vala.page b/platform-demos/C/GtkApplicationWindow.vala.page
index f211788..597f7fc 100644
--- a/platform-demos/C/GtkApplicationWindow.vala.page
+++ b/platform-demos/C/GtkApplicationWindow.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="GtkApplicationWindow.vala">
   <info>
@@ -16,29 +17,11 @@
 
   <title>Application Window</title>
   <media type="image" mime="image/png" src="media/window.png"/>
-  <p>The simplest GtkApplication Window</p>
+  <p>The simplest GtkApplication Window which can support Menus.</p>
 
-      <code mime="text/x-vala" style="numbered"><![CDATA[
-public class MyWindow : Gtk.ApplicationWindow {
-	internal MyWindow (MyApplication app) {
-		Object (application: app, title: "Welcome to GNOME");
-	}
-}
-
-public class MyApplication : Gtk.Application {
-	protected override void activate () {
-		new MyWindow (this).show ();
-	}
-
-	internal MyApplication () {
-		Object (application_id: "org.example.MyApplication");
-	}
-}
-
-public int main (string[] args) {
-	return new MyApplication ().run (args);
-}
-]]></code>
+<code mime="text/x-vala" style="numbered">
+<xi:include href="samples/GtkApplicationWindow.vala" parse="text"><xi:fallback/></xi:include>
+</code>
 <p>
   In this sample we used the following:
 </p>
diff --git a/platform-demos/C/aboutdialog_GMenu.vala.page b/platform-demos/C/aboutdialog_GMenu.vala.page
new file mode 100644
index 0000000..9d36451
--- /dev/null
+++ b/platform-demos/C/aboutdialog_GMenu.vala.page
@@ -0,0 +1,41 @@
+<page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
+      type="guide" style="task"
+      id="aboutdialog_GMenu.vala">
+  <info>
+    <link type="guide" xref="beginner.vala#windows"/>
+    <revision version="0.1" date="2012-04-07" status="stub"/>
+
+    <credit type="author copyright">
+      <name>Ryan Lortie</name>
+      <email>desrt desrt ca</email>
+      <years>2012</years>
+    </credit>
+
+    <credit type="author">
+      <name>Tiffany Antopolski</name>
+      <email>tiffany antopolski gmail com</email>
+    </credit>
+
+
+    <desc>Display information about an application</desc>
+  </info>
+
+  <title>AboutDialog</title>
+  <media type="image" mime="image/png" src="media/aboutdialog_GMenu.png"/>
+  <p>An AboutDialog example using Gtk.ApplicationWindow and Menu</p>
+  <note><p><em style="bold">You need to be running Gtk3.4 or later for this to work</em></p></note>
+
+<code mime="text/x-vala" style="numbered">
+<xi:include href="samples/aboutdialog_GMenu.vala" parse="text"><xi:fallback/></xi:include>		
+</code>
+<p>
+  In this sample we used the following:
+</p>
+<list>
+  <item><p><link href="http://references.valadoc.org/#!api=gtk+-3.0/Gtk.Application";>Gtk.Application</link></p></item>
+  <item><p><link href="http://references.valadoc.org/#!api=gtk+-3.0/Gtk.ApplicationWindow";>Gtk.ApplicationWindow</link></p></item>
+  <item><p><link href="http://www.valadoc.org/#!api=gtk+-3.0/Gtk.Window.set_default_size";>set_default_size</link></p></item>
+  <item><p><link href="button.vala.page">Gtk.Button.with_label</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/beginner.vala.page b/platform-demos/C/beginner.vala.page
index 3f106fd..ec36a15 100644
--- a/platform-demos/C/beginner.vala.page
+++ b/platform-demos/C/beginner.vala.page
@@ -16,8 +16,6 @@
 
 <title>0 Beginner's Tutorials</title>
 <synopsis>
- <p>If you have never programmed before, or are not familiar with the concepts of object oriented programming, you may need to learn a few basics first.  The book <link href="http://learnpythonthehardway.org/book/";>Learn Python the Hard Way</link> may be a better place for you to start. Once you master the basics, be sure to come back and check out these tutorials.</p>
-
  <p>Although these tutorials are designed for beginners, we can't cover all the basics.  Before attempting to follow these tutorials, you are expected to be familiar with the following concepts:</p>
 <list type="numbered">
   <item><p>Object oriented programming</p></item>
diff --git a/platform-demos/C/dialog.vala.page b/platform-demos/C/dialog.vala.page
index bc623a4..970f355 100644
--- a/platform-demos/C/dialog.vala.page
+++ b/platform-demos/C/dialog.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="dialog.vala">
   <info>
@@ -18,31 +19,9 @@
   <media type="image" mime="image/png" src="media/dialog.png"/>
   <p>A dialog with the response signal hooked up to a callback function.</p>
 
-      <code mime="text/x-vala" style="numbered"><![CDATA[
-void on_response (int response_id) {
-
-    /*To see the int value of the ResponseType*/
-    print ("response is %d\n", response_id);
-
-    Gtk.main_quit ();
-}
-
-int main (string[] args) {
-
-    Gtk.init (ref args);
-
-    var dialog = new Gtk.Dialog.with_buttons ("A Gtk+ Dialog", null, 0, Gtk.Stock.OK, Gtk.ResponseType.OK, null);
-    var content_area = dialog.get_content_area () as Gtk.Container; //TODO: explain this
-    var label = new Gtk.Label ("This demonstrates a dialog with a label");
-
-    content_area.add (label);
-    dialog.response.connect (on_response);
-    dialog.show_all ();
-
-    Gtk.main ();
-    return 0;
-}
-]]></code>
+      <code mime="text/x-vala" style="numbered">
+<xi:include href="samples/dialog.vala" parse="text"><xi:fallback/></xi:include>
+</code>
 
 <p>
   In this sample we used the following:
diff --git a/platform-demos/C/image-viewer.vala.page b/platform-demos/C/image-viewer.vala.page
index a03d75c..ac188b3 100644
--- a/platform-demos/C/image-viewer.vala.page
+++ b/platform-demos/C/image-viewer.vala.page
@@ -55,17 +55,17 @@
       <p>Start <app>Anjuta</app> and click <gui>Create a new project</gui> or <guiseq><gui>File</gui><gui>New</gui><gui>Project</gui></guiseq> to open the project wizard.</p>
     </item>
     <item>
-      <p>Choose <gui>Gtk+ (Simple)</gui> from the <gui>Vala</gui> tab, click <gui>Forward</gui>, and fill out your details on the next few pages.
+      <p>From the <gui>Vala</gui> tab choose <gui>Gtk+ (Simple)</gui>, click <gui>Continue</gui>, and fill out your details on the next page.
       Use <file>image-viewer</file> as project name and directory.</p>
    	</item>
     <item>
-      <p>Make sure that <gui>Use GtkBuilder for user interface</gui> is disabled as we will create the UI manually in this tutorial.</p>
+      <p>Make sure that <gui>Use GtkBuilder for user interface</gui> is unchecked as we will create the UI manually in this tutorial.</p>
      <note><p>
       You will learn how to use the interface builder in the <link xref="guitar-tuner.vala">Guitar-Tuner</link> tutorial.</p></note>
     </item>
     <item>
-      <p>Click <gui>Apply</gui> and the project will be created for you.
-      Open <file>src/main.vala</file> from the <gui>Project</gui> or <gui>File</gui> tabs.
+      <p>Click <gui>Continue</gui> then <gui>Apply</gui> and the project will be created for you.
+      Open <file>src/image_viewer.vala</file> from the <gui>Project</gui> or <gui>File</gui> tabs.
       You will see this code:</p>
       <code mime="text/x-valasrc"><![CDATA[
 using GLib;
diff --git a/platform-demos/C/media/aboutdialog.png b/platform-demos/C/media/aboutdialog_GMenu.png
similarity index 100%
rename from platform-demos/C/media/aboutdialog.png
rename to platform-demos/C/media/aboutdialog_GMenu.png
diff --git a/platform-demos/C/media/dialog.png b/platform-demos/C/media/dialog.png
index b14a28e..1b957cf 100644
Binary files a/platform-demos/C/media/dialog.png and b/platform-demos/C/media/dialog.png differ
diff --git a/platform-demos/C/samples/GtkApplication.vala b/platform-demos/C/samples/aboutdialog_GMenu.vala
similarity index 92%
rename from platform-demos/C/samples/GtkApplication.vala
rename to platform-demos/C/samples/aboutdialog_GMenu.vala
index 207e0c9..7907e9e 100644
--- a/platform-demos/C/samples/GtkApplication.vala
+++ b/platform-demos/C/samples/aboutdialog_GMenu.vala
@@ -1,7 +1,3 @@
-//Note to self: Python and JS need to import Glib for the menu
-
-/*** You need to be running Gtk+-3.4 or later for this to work ***/
-
 //A window in the application
 public class Window : Gtk.ApplicationWindow {
 	public Window (Application app) {
diff --git a/platform-demos/C/samples/dialog.vala b/platform-demos/C/samples/dialog.vala
index a9dc5fb..6daca2a 100644
--- a/platform-demos/C/samples/dialog.vala
+++ b/platform-demos/C/samples/dialog.vala
@@ -1,23 +1,45 @@
-void on_response (int response_id) {
+//This is the application
+public class MyApplication : Gtk.Application {
+	public MyApplication () {
+		Object (application_id: "org.example.dialog");
+	}
+	
+	void on_response (Gtk.Dialog dialog, int response_id) {
+		/*To see the int value of the ResponseType*/
+		print ("response is %d\n", response_id);
 
-    /*To see the int value of the ResponseType*/
-    print ("response is %d\n", response_id);
-    
-    Gtk.main_quit ();
-}
+		dialog.destroy ();
+	}
 
-int main (string[] args) {
+	void on_button_click (Gtk.Button button) {
+		var window = button.get_toplevel () as Gtk.Window;
+		var dialog = new Gtk.Dialog.with_buttons ("A Gtk+ Dialog", window,
+		                                          Gtk.DialogFlags.MODAL,
+		                                          Gtk.Stock.OK, 
+		                                          Gtk.ResponseType.OK, null);
+		var content_area = dialog.get_content_area (); 
+		var label = new Gtk.Label ("This demonstrates a dialog with a label");
+
+		content_area.add (label);
+		dialog.response.connect (on_response);
+		dialog.show_all ();
+	}
 
-    Gtk.init (ref args);
+	public override void activate () {
+		var window = new Gtk.Window ();
+		window.set_default_size (200, 50);
 
-    var dialog = new Gtk.Dialog.with_buttons ("A Gtk+ Dialog", null, 0, Gtk.Stock.OK, Gtk.ResponseType.OK, null);
-    var content_area = dialog.get_content_area () as Gtk.Container; //TODO: explain this
-    var label = new Gtk.Label ("This demonstrates a dialog with a label");
-    
-    content_area.add (label);
-    dialog.response.connect (on_response);
-    dialog.show_all ();
+		var button = new Gtk.Button.from_stock (Gtk.Stock.OK);
+		button.clicked.connect (on_button_click);
+		window.add (button);
 
-    Gtk.main ();
-    return 0;
+		this.add_window (window);
+		window.show_all ();
+	}
+}
+
+//The main function creates the application and runs it.
+int main (string[] args) {
+	var app = new MyApplication ();
+	return app.run (args);
 }
diff --git a/platform-demos/C/window.vala.page b/platform-demos/C/window.vala.page
index 31401cb..3f88b7e 100644
--- a/platform-demos/C/window.vala.page
+++ b/platform-demos/C/window.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="window.vala">
   <info>
@@ -26,37 +27,9 @@
     </td>
   </tr>
 </table>
-      <code mime="text/x-vala" style="numbered"><![CDATA[
-//This is the application
-public class Application : Gtk.Application {
-	public Application () {
-		Object (application_id: "org.example.window");
-	}
-	
-	public override void activate () {
-		var window = new Gtk.Window ();
-		window.title = "Welcome to GNOME";
-
-		/*
-		 The following 3 lines are included here to introduce
-		 you to ways you can adjust the toplevel window to suit
-		 your needs.  Uncomment them to see what they do.
-		*/
-		//window.border_width = 10;
-		//window.set_default_size (350, 70);
-		//window.window_position = Gtk.WindowPosition.CENTER;
-
-		window.show ();
-		this.add_window (window);
-	}
-}
-
-//The main function creates the application and runs it.
-int main (string[] args) {
-	var app = new Application ();
-	return app.run (args);
-}
-]]></code>
+      <code mime="text/x-vala" style="numbered">
+ <xi:include href="samples/window.vala" parse="text"><xi:fallback/></xi:include>
+</code>
 <p>
   In this sample we used the following:
 </p>
diff --git a/platform-demos/Makefile.am b/platform-demos/Makefile.am
index 3bea370..5a4bf21 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -21,10 +21,14 @@ demo_sources = \
 	message-board/message-board.c 		\
 	photo-wall/photo-wall.c 		\		
 	record-collection/record-collection.js 	\
+	samples/aboutdialog_GMenu.vala		\
+	samples/dialog.vala			\
+	samples/GtkApplicationWindow.vala	\
+	samples/window.vala			\
 	media/gnome-devtools.catalog
 
 DOC_FIGURES = \
-	media/aboutdialog.png			\
+	media/aboutdialog_GMenu.png		\
 	media/button.png			\
 	media/dialog.png			\
 	media/entry.png				\
@@ -51,7 +55,7 @@ DOC_FIGURES = \
 	$(demo_sources)
 
 DOC_PAGES =				\
-	aboutdialog.vala.page		\
+	aboutdialog_GMenu.vala.page	\
 	audio-player.vala.page		\
 	beginner.c.page			\
 	beginner.js.page		\



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