[gnome-devel-docs] Vala Window example now uses Gtk.Application.



commit e96f5cb21fc8d6ed3a68e8e4436089a8f36ee43b
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date:   Fri Apr 27 00:09:42 2012 -0400

    Vala Window example now uses Gtk.Application.

 platform-demos/C/samples/window.vala |   50 +++++++++++++++---------------
 platform-demos/C/window.vala.page    |   55 +++++++++++++++++----------------
 2 files changed, 53 insertions(+), 52 deletions(-)
---
diff --git a/platform-demos/C/samples/window.vala b/platform-demos/C/samples/window.vala
index b59e67e..b1132d0 100644
--- a/platform-demos/C/samples/window.vala
+++ b/platform-demos/C/samples/window.vala
@@ -1,29 +1,29 @@
-int main (string[] args) {
-
-	Gtk.init (ref args);
-
-	var window = new Gtk.Window ();
-	window.title = "Welcome to GNOME";
+//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;
+		/*
+		 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;
 
-	/*The destroy signal is emitted when the x
-	  in the top right of the window is clicked.*/
-	window.destroy.connect (Gtk.main_quit);
-
-	/*The show () method only shows the widget it is called on.
-      If the widget has children (for example a label or a button,
-      the method show_all () should be used to show the widget and
-       the child widgets.*/
-	window.show ();
+		window.show ();
+		this.add_window (window);
+	}
+}
 
-	Gtk.main ();
-	return 0;
+//The main function creates the application and runs it.
+int main (string[] args) {
+	var app = new Application ();
+	return app.run (args);
 }
diff --git a/platform-demos/C/window.vala.page b/platform-demos/C/window.vala.page
index 09ab7f3..31401cb 100644
--- a/platform-demos/C/window.vala.page
+++ b/platform-demos/C/window.vala.page
@@ -19,48 +19,49 @@
   <tr>
     <td>
       <media type="image" mime="image/png" src="media/window.png"/>
-      <p>A toplevel window with destroy signal hooked up.</p>
+      <p>The simplest Gtk.Application</p>
     </td>
     <td>
-      <p>This example should no longer be used.  Use <link href="GtkApplicationWindow.vala.page">Application Window</link> instead.</p>
+      <p>Use <link href="GtkApplicationWindow.vala.page">Application Window</link> if you need GMenu support.</p>
     </td>
   </tr>
 </table>
       <code mime="text/x-vala" style="numbered"><![CDATA[
-int main (string[] args) {
-
-        Gtk.init (ref args);
-
-        var window = new Gtk.Window ();
-        window.title = "Welcome to GNOME";
+//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;
+		/*
+		 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;
 
-        /*The destroy signal is emitted when the x
-          in the top right of the window is clicked.*/
-        window.destroy.connect (Gtk.main_quit);
-
-        /*The show () method only shows the widget it is called on.
-      If the widget has children (for example a label or a button,
-      the method show_all () should be used to show the widget and
-       the child widgets.*/
-        window.show ();
+		window.show ();
+		this.add_window (window);
+	}
+}
 
-        Gtk.main ();
-        return 0;
+//The main function creates the application and runs it.
+int main (string[] args) {
+	var app = new Application ();
+	return app.run (args);
 }
 ]]></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>The widget <link href="http://www.valadoc.org/#!api=gtk+-3.0/Gtk.Window";>Gtk.Window</link></p></item>
 
   <item><p>The enum <link href="http://references.valadoc.org/#!api=gtk+-3.0/Gtk.WindowPosition";>Gtk.WindowPosition</link></p></item>



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